diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-04-22 14:22:42 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 08:43:31 +0200 |
commit | 9a63b07c1270f47c0409bf463a4197570fef530c (patch) | |
tree | 6c8f02fce5a0f73da11c4f415261af424c2ebe9a /archaeological_files/models.py | |
parent | abd0cb791ab4e0ca35136c65ae3ec6def1539f15 (diff) | |
download | Ishtar-9a63b07c1270f47c0409bf463a4197570fef530c.tar.bz2 Ishtar-9a63b07c1270f47c0409bf463a4197570fef530c.zip |
Refactoring of query owns (refs #4060)
Diffstat (limited to 'archaeological_files/models.py')
-rw-r--r-- | archaeological_files/models.py | 24 |
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) |