summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
authorValérie-Emma Leroux <emma@iggdrasil.net>2017-04-07 11:40:31 +0200
committerValérie-Emma Leroux <emma@iggdrasil.net>2017-04-07 11:40:31 +0200
commit7f22d3c20cc24debfe123425efa63ec5293e4b4c (patch)
treef773b80964981c231c892ee5255b94285bc5620a /archaeological_context_records/models.py
parent9127307734c85b816ac7dbb539b565ffb106d60f (diff)
parentda4af2ab5d105f6d2ce442b517e532b7570616e3 (diff)
downloadIshtar-7f22d3c20cc24debfe123425efa63ec5293e4b4c.tar.bz2
Ishtar-7f22d3c20cc24debfe123425efa63ec5293e4b4c.zip
Merge branch 'master' of git.iggdrasil.net:/srv/git/ishtar
Conflicts: archaeological_operations/templates/ishtar/sheet_operation.html
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py61
1 files changed, 52 insertions, 9 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 14e98e76b..bb3afc899 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2012-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2012-2017 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -129,6 +129,15 @@ post_save.connect(post_save_cache, sender=ExcavationTechnicType)
post_delete.connect(post_save_cache, sender=ExcavationTechnicType)
+class DocumentationType(GeneralType):
+ class Meta:
+ verbose_name = _(u"Documentation type")
+ verbose_name_plural = _(u"Documentation types")
+ ordering = ('label',)
+post_save.connect(post_save_cache, sender=DocumentationType)
+post_delete.connect(post_save_cache, sender=DocumentationType)
+
+
class CRBulkView(object):
CREATE_SQL = """
CREATE VIEW context_records_cached_label_bulk_update
@@ -150,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',
@@ -216,18 +225,21 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
width = models.FloatField(_(u"Width (m)"), blank=True, null=True)
thickness = models.FloatField(_(u"Thickness (m)"), blank=True,
null=True)
+ diameter = models.FloatField(_(u"Diameter (m)"), blank=True, null=True)
depth = models.FloatField(_(u"Depth (m)"), blank=True, null=True)
+ depth_of_appearance = models.FloatField(
+ _(u"Depth of appearance (m)"), blank=True, null=True)
location = models.TextField(
_(u"Location"), blank=True, null=True,
help_text=_(u"A short description of the location of the context "
u"record"))
datings = models.ManyToManyField(Dating)
+ documentations = models.ManyToManyField(DocumentationType, blank=True,
+ null=True)
datings_comment = models.TextField(_(u"Comment on datings"), blank=True,
null=True)
unit = models.ForeignKey(Unit, verbose_name=_(u"Context record type"),
related_name='+', blank=True, null=True)
- has_furniture = models.NullBooleanField(_(u"Has furniture?"), blank=True,
- null=True)
filling = models.TextField(_(u"Filling"), blank=True, null=True)
interpretation = models.TextField(_(u"Interpretation"), blank=True,
null=True)
@@ -353,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,
@@ -389,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):
@@ -603,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")
@@ -610,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)