mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Some other performance improvements
This commit is contained in:
parent
bf6483039d
commit
4a7df31f5e
@ -385,7 +385,7 @@ class User(AbstractBaseUser):
|
|||||||
"""
|
"""
|
||||||
Determine if the object can be edited by the user
|
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
|
return True
|
||||||
if hasattr(obj, "edit_groups"):
|
if hasattr(obj, "edit_groups"):
|
||||||
for g in obj.edit_groups.all():
|
for g in obj.edit_groups.all():
|
||||||
@ -393,7 +393,7 @@ class User(AbstractBaseUser):
|
|||||||
return True
|
return True
|
||||||
if isinstance(obj, User) and obj == self:
|
if isinstance(obj, User) and obj == self:
|
||||||
return True
|
return True
|
||||||
if hasattr(obj, "can_be_edited_by") and obj.can_be_edited_by(self):
|
if self.is_owner(obj):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -401,13 +401,13 @@ class User(AbstractBaseUser):
|
|||||||
"""
|
"""
|
||||||
Determine if the object can be viewed by the user
|
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
|
return True
|
||||||
if hasattr(obj, "view_groups"):
|
if hasattr(obj, "view_groups"):
|
||||||
for g in obj.view_groups.all():
|
for g in obj.view_groups.all():
|
||||||
if self.is_in_group(g.name):
|
if self.is_in_group(g.name):
|
||||||
return True
|
return True
|
||||||
if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self):
|
if self.can_edit(obj):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import os
|
|||||||
|
|
||||||
from core.models import SithFile, RealGroup, Notification
|
from core.models import SithFile, RealGroup, Notification
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, can_view, not_found
|
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"):
|
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()
|
f = file_class.objects.filter(id=file_id).first()
|
||||||
if f is None or not f.file:
|
if f is None or not f.file:
|
||||||
return not_found(request)
|
return not_found(request)
|
||||||
from counter.models import Counter
|
|
||||||
if not (can_view(f, request.user) or
|
if not (can_view(f, request.user) or
|
||||||
('counter_token' in request.session.keys() and
|
('counter_token' in request.session.keys() and
|
||||||
request.session['counter_token'] and # check if not null for counters that have no token set
|
request.session['counter_token'] and # check if not null for counters that have no token set
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
<h3>{{ album.get_display_name() }}</h3>
|
<h3>{{ album.get_display_name() }}</h3>
|
||||||
<a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br>
|
<a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br>
|
||||||
<hr>
|
<hr>
|
||||||
{% if user.can_edit(album) %}
|
{% set edit_mode = user.can_edit(album) %}
|
||||||
|
{% if edit_mode %}
|
||||||
<form action="" method="post" enctype="multipart/form-data" style="width: 100%;">
|
<form action="" method="post" enctype="multipart/form-data" style="width: 100%;">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<p>
|
<p>
|
||||||
@ -39,7 +40,7 @@
|
|||||||
<div>
|
<div>
|
||||||
{% for a in album.children.filter(is_folder=True).order_by('-id') %}
|
{% for a in album.children.filter(is_folder=True).order_by('-id') %}
|
||||||
<div style="display: inline-block;">
|
<div style="display: inline-block;">
|
||||||
{% if user.can_edit(album) %}
|
{% if edit_mode %}
|
||||||
<input type="checkbox" name="file_list" value="{{ a.id }}">
|
<input type="checkbox" name="file_list" value="{{ a.id }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.can_view(a.as_album) %}
|
{% if user.can_view(a.as_album) %}
|
||||||
@ -64,7 +65,7 @@
|
|||||||
<div>
|
<div>
|
||||||
{% for p in album.children.filter(is_folder=False).order_by('id') %}
|
{% for p in album.children.filter(is_folder=False).order_by('id') %}
|
||||||
<div style="display: inline-block;">
|
<div style="display: inline-block;">
|
||||||
{% if user.can_edit(album) %}
|
{% if edit_mode %}
|
||||||
<input type="checkbox" name="file_list" value="{{ p.id }}">
|
<input type="checkbox" name="file_list" value="{{ p.id }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.can_view(p.as_picture) %}
|
{% if user.can_view(p.as_picture) %}
|
||||||
@ -77,7 +78,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% if user.can_edit(album) %}
|
{% if edit_mode %}
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form action="" method="post" enctype="multipart/form-data">
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
|
Loading…
Reference in New Issue
Block a user