summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py43
1 files changed, 37 insertions, 6 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 4df56c49f..bb3afc899 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -159,7 +159,7 @@ class CRBulkView(object):
class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
- ValueGetter, ShortMenuItem):
+ ValueGetter, ShortMenuItem):
SHOW_URL = 'show-contextrecord'
SLUG = 'contextrecord'
TABLE_COLS = ['label', 'operation__common_name', 'parcel__town__name',
@@ -365,9 +365,11 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
@classmethod
def get_query_owns(cls, user):
- return Q(operation__scientist=user.ishtaruser.person) |\
- Q(operation__in_charge=user.ishtaruser.person) |\
- Q(history_creator=user)
+ return (Q(operation__scientist=user.ishtaruser.person) |
+ Q(operation__in_charge=user.ishtaruser.person) |
+ Q(operation__collaborators__pk=user.ishtaruser.person.pk) |
+ Q(history_creator=user)) \
+ & Q(operation__end_date__isnull=True)
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None,
@@ -401,8 +403,16 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
return self.full_label()
def _get_associated_cached_labels(self):
- from archaeological_finds.models import Find
- return list(Find.objects.filter(base_finds__context_record=self).all())
+ from archaeological_finds.models import Find, BaseFind
+ return list(Find.objects.filter(base_finds__context_record=self).all())\
+ + list(BaseFind.objects.filter(context_record=self).all())
+
+ def _cached_labels_bulk_update(self):
+ if settings.TESTING and settings.USE_SPATIALITE_FOR_TESTS:
+ return
+ self.base_finds.model.cached_label_bulk_update(
+ context_record_id=self.pk)
+ return True
@property
def reference(self):
@@ -615,6 +625,18 @@ class ContextRecordSource(Source):
class Meta:
verbose_name = _(u"Context record documentation")
verbose_name_plural = _(u"Context record documentations")
+ permissions = (
+ ("view_contextrecordsource",
+ ugettext(u"Can view all Context record sources")),
+ ("view_own_contextrecordsource",
+ ugettext(u"Can view own Context record source")),
+ ("add_own_contextrecordsource",
+ ugettext(u"Can add own Context record source")),
+ ("change_own_contextrecordsource",
+ ugettext(u"Can change own Context record source")),
+ ("delete_own_contextrecordsource",
+ ugettext(u"Can delete own Context record source")),
+ )
context_record = models.ForeignKey(
ContextRecord, verbose_name=_(u"Context record"),
related_name="source")
@@ -622,3 +644,12 @@ class ContextRecordSource(Source):
@property
def owner(self):
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)