diff options
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index e741f5644..3826678c3 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -269,6 +269,10 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, verbose_name=_(u"In charge"), on_delete=models.SET_NULL, related_name='operation_responsability') + collaborators = models.ManyToManyField( + Person, blank=True, null=True, verbose_name=_(u"Collaborators"), + related_name='operation_collaborator' + ) year = models.IntegerField(_(u"Year"), null=True, blank=True) operation_code = models.IntegerField(_(u"Numeric reference"), null=True, blank=True) @@ -570,8 +574,10 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, @classmethod def get_query_owns(cls, user): - return (Q(in_charge=user.ishtaruser.person) |\ - Q(scientist=user.ishtaruser.person) |\ + return ( + Q(in_charge=user.ishtaruser.person) | + Q(scientist=user.ishtaruser.person) | + Q(collaborators__pk=user.ishtaruser.person.pk) | Q(history_creator=user)) & Q(end_date__isnull=True) def is_active(self): @@ -587,14 +593,6 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, nb = self.parcels.count() return nb - def _get_or_set_stats(self, funcname, update): - key, val = get_cache(self.__class__, [funcname, self.pk]) - if not update and val is not None: - return val - val = getattr(self, funcname)() - cache.set(key, val, settings.CACHE_TIMEOUT) - return val - @property def nb_acts(self, update=False): _(u"Number of administrative acts") @@ -911,6 +909,13 @@ class OperationSource(Source): return u"{}-{:04d}".format(self.operation.code_patriarche or '', self.index) + @classmethod + def get_query_owns(cls, user): + return (Q(operation__in_charge=user.ishtaruser.person) | + Q(operation__scientist=user.ishtaruser.person) | + Q(operation__collaborators__pk=user.ishtaruser.person.pk)) \ + & Q(operation__end_date__isnull=True) + class ActType(GeneralType): TYPE = (('F', _(u'Archaeological file')), |