diff options
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 9655ca387..b52477995 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -697,19 +697,30 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, return round(float(self.cost) / self.surface, 2) @classmethod - def get_query_owns(cls, ishtaruser): + 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 ( - Q(in_charge=ishtaruser.person) | - Q(scientist=ishtaruser.person) | - Q(collaborators__pk=ishtaruser.person.pk) | - Q(history_creator=ishtaruser.user_ptr) | - Q(towns__pk__in=town_ids) - ) & Q(end_date__isnull=True) + return [ + { + 'in_charge': ishtaruser.person, + 'scientist': ishtaruser.person, + 'collaborators__pk': ishtaruser.person.pk, + 'history_creator': ishtaruser.user_ptr, + 'towns__pk__in': town_ids + }, + { + 'end_date__isnull': True + } + ] + + @classmethod + def get_query_owns(cls, ishtaruser): + return cls._construct_query_own( + '', cls._get_query_owns_dicts(ishtaruser) + ) def is_active(self): return not bool(self.end_date) @@ -1074,10 +1085,9 @@ class OperationSource(Source): @classmethod def get_query_owns(cls, ishtaruser): - return (Q(operation__in_charge=ishtaruser.person) | - Q(operation__scientist=ishtaruser.person) | - Q(operation__collaborators__pk=ishtaruser.person.pk)) \ - & Q(operation__end_date__isnull=True) + return cls._construct_query_own( + 'operation__', Operation._get_query_owns_dicts(ishtaruser) + ) class ActType(GeneralType): |