From 4a7df31f5ecd4e6575a66958790d2629dbf14ac4 Mon Sep 17 00:00:00 2001 From: Skia Date: Sun, 18 Dec 2016 11:55:45 +0100 Subject: [PATCH] Some other performance improvements --- core/models.py | 8 ++++---- core/views/files.py | 2 +- sas/templates/sas/album.jinja | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/models.py b/core/models.py index 810ed700..270c733c 100644 --- a/core/models.py +++ b/core/models.py @@ -385,7 +385,7 @@ class User(AbstractBaseUser): """ Determine if the object can be edited by the user """ - if self.is_owner(obj): + if hasattr(obj, "can_be_edited_by") and obj.can_be_edited_by(self): return True if hasattr(obj, "edit_groups"): for g in obj.edit_groups.all(): @@ -393,7 +393,7 @@ class User(AbstractBaseUser): return True if isinstance(obj, User) and obj == self: return True - if hasattr(obj, "can_be_edited_by") and obj.can_be_edited_by(self): + if self.is_owner(obj): return True return False @@ -401,13 +401,13 @@ class User(AbstractBaseUser): """ Determine if the object can be viewed by the user """ - if self.can_edit(obj): + if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self): return True if hasattr(obj, "view_groups"): for g in obj.view_groups.all(): if self.is_in_group(g.name): return True - if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self): + if self.can_edit(obj): return True return False diff --git a/core/views/files.py b/core/views/files.py index 399b567a..31596d74 100644 --- a/core/views/files.py +++ b/core/views/files.py @@ -18,6 +18,7 @@ import os from core.models import SithFile, RealGroup, Notification from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, can_view, not_found +from counter.models import Counter def send_file(request, file_id, file_class=SithFile, file_attr="file"): """ @@ -28,7 +29,6 @@ def send_file(request, file_id, file_class=SithFile, file_attr="file"): f = file_class.objects.filter(id=file_id).first() if f is None or not f.file: return not_found(request) - from counter.models import Counter if not (can_view(f, request.user) or ('counter_token' in request.session.keys() and request.session['counter_token'] and # check if not null for counters that have no token set diff --git a/sas/templates/sas/album.jinja b/sas/templates/sas/album.jinja index 68a0cd86..475ffcbb 100644 --- a/sas/templates/sas/album.jinja +++ b/sas/templates/sas/album.jinja @@ -17,7 +17,8 @@

{{ album.get_display_name() }}

{% trans %}Edit{% endtrans %}

-{% if user.can_edit(album) %} +{% set edit_mode = user.can_edit(album) %} +{% if edit_mode %}
{% csrf_token %}

@@ -39,7 +40,7 @@

{% for a in album.children.filter(is_folder=True).order_by('-id') %}
- {% if user.can_edit(album) %} + {% if edit_mode %} {% endif %} {% if user.can_view(a.as_album) %} @@ -64,7 +65,7 @@
{% for p in album.children.filter(is_folder=False).order_by('id') %}
- {% if user.can_edit(album) %} + {% if edit_mode %} {% endif %} {% if user.can_view(p.as_picture) %} @@ -77,7 +78,7 @@
{% endfor %}
-{% if user.can_edit(album) %} +{% if edit_mode %} {% endif %}