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_finds | |
| parent | abd0cb791ab4e0ca35136c65ae3ec6def1539f15 (diff) | |
| download | Ishtar-9a63b07c1270f47c0409bf463a4197570fef530c.tar.bz2 Ishtar-9a63b07c1270f47c0409bf463a4197570fef530c.zip | |
Refactoring of query owns (refs #4060)
Diffstat (limited to 'archaeological_finds')
| -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): |
