diff options
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r-- | archaeological_context_records/models.py | 34 |
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 |