summaryrefslogtreecommitdiff
path: root/archaeological_files/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_files/models.py')
-rw-r--r--archaeological_files/models.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 36f28c2e8..5f4150695 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -445,10 +445,28 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return self.towns.all()[0].numero_insee[:2]
@classmethod
+ def _get_query_owns_dicts(cls, ishtaruser):
+ profile = ishtaruser.current_profile
+ town_ids = []
+ if profile:
+ town_ids = [town['pk']
+ for town in profile.query_towns.values('pk').all()]
+ return [
+ {
+ 'in_charge': ishtaruser.person,
+ 'history_creator': ishtaruser.user_ptr,
+ 'towns__pk__in': town_ids
+ },
+ {
+ 'end_date__isnull': True
+ }
+ ]
+
+ @classmethod
def get_query_owns(cls, ishtaruser):
- return (Q(history_creator=ishtaruser.user_ptr) |
- Q(in_charge__ishtaruser=ishtaruser)) \
- & Q(end_date__isnull=True)
+ return cls._construct_query_own(
+ '', cls._get_query_owns_dicts(ishtaruser)
+ )
def is_active(self):
return not bool(self.end_date)