diff options
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r-- | archaeological_finds/models_finds.py | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 7155f3906..40059faa6 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -37,7 +37,7 @@ from ishtar_common.models import GeneralType, HierarchicalType, ImageModel, \ HistoricalRecords, OwnPerms, Source, Person, Basket, post_save_cache, \ ValueGetter, get_current_profile, IshtarImage -from archaeological_operations.models import AdministrativeAct +from archaeological_operations.models import AdministrativeAct, Operation from archaeological_context_records.models import ContextRecord, Dating from ishtar_common.models import PRIVATE_FIELDS, SpatialReferenceSystem, \ @@ -1094,21 +1094,14 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel, @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(base_finds__context_record__operation__scientist= - ishtaruser.person) | - Q(base_finds__context_record__operation__in_charge= - ishtaruser.person) | - Q(base_finds__context_record__operation__collaborators__pk= - ishtaruser.person.pk) | - Q(history_creator=ishtaruser.user_ptr) | - Q(base_finds__context_record__operation__towns__pk__in=town_ids) - ) & Q(base_finds__context_record__operation__end_date__isnull=True) + q = cls._construct_query_own( + 'base_finds__context_record__operation__', + Operation._get_query_owns_dicts(ishtaruser) + ) | cls._construct_query_own('', [ + {'history_creator': ishtaruser.user_ptr}, + {'base_finds__context_record__operation__end_date__isnull': True} + ]) + return q @classmethod def get_owns(cls, user, menu_filtr=None, limit=None, @@ -1497,15 +1490,15 @@ class FindSource(Source): @classmethod def get_query_owns(cls, ishtaruser): - return (Q(find__base_finds__context_record__operation__scientist= - ishtaruser.person) | - Q(find__base_finds__context_record__operation__in_charge= - ishtaruser.person) | - Q( - find__base_finds__context_record__operation__collaborators__pk= - ishtaruser.person.pk)) \ - & Q( - find__base_finds__context_record__operation__end_date__isnull=True) + q = cls._construct_query_own( + 'find__base_finds__context_record__operation__', + Operation._get_query_owns_dicts(ishtaruser) + ) | cls._construct_query_own('', [ + {'find__history_creator': ishtaruser.user_ptr}, + {'find__base_finds__context_record__operation__end_date__isnull': + True} + ]) + return q class Property(LightHistorizedItem): |