summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
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
commit9a63b07c1270f47c0409bf463a4197570fef530c (patch)
tree6c8f02fce5a0f73da11c4f415261af424c2ebe9a /archaeological_context_records/models.py
parentabd0cb791ab4e0ca35136c65ae3ec6def1539f15 (diff)
downloadIshtar-9a63b07c1270f47c0409bf463a4197570fef530c.tar.bz2
Ishtar-9a63b07c1270f47c0409bf463a4197570fef530c.zip
Refactoring of query owns (refs #4060)
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 996304231..07429e606 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -429,17 +429,13 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,
@classmethod
def get_query_owns(cls, ishtaruser):
- profile = ishtaruser.current_profile
- town_ids = []
- if profile:
- town_ids = [town['pk']
- for town in profile.query_towns.values('pk').all()]
- return (Q(operation__scientist=ishtaruser.person) |
- Q(operation__in_charge=ishtaruser.person) |
- Q(operation__collaborators__pk=ishtaruser.person.pk) |
- Q(history_creator=ishtaruser.user_ptr) |
- Q(operation__towns__pk__in=town_ids)) \
- & Q(operation__end_date__isnull=True)
+ q = cls._construct_query_own(
+ 'operation__', Operation._get_query_owns_dicts(ishtaruser)
+ ) | cls._construct_query_own('', [
+ {'history_creator': ishtaruser.user_ptr},
+ {'operation__end_date__isnull': True}
+ ])
+ return q
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None,
@@ -720,11 +716,13 @@ class ContextRecordSource(Source):
return self.context_record
@classmethod
- def get_query_owns(cls, user):
- return (
- Q(context_record__operation__scientist=user.ishtaruser.person) |
- Q(context_record__operation__in_charge=user.ishtaruser.person) |
- Q(context_record__operation__collaborators__pk=
- user.ishtaruser.person.pk)) \
- & Q(context_record__operation__end_date__isnull=True)
+ def get_query_owns(cls, ishtaruser):
+ q = cls._construct_query_own(
+ 'context_record__operation__',
+ Operation._get_query_owns_dicts(ishtaruser)
+ ) | cls._construct_query_own('', [
+ {'context_record__history_creator': ishtaruser.user_ptr},
+ {'context_record__operation__end_date__isnull': True}
+ ])
+ return q