summaryrefslogtreecommitdiff
path: root/archaeological_context_records
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-04-07 12:16:37 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-04-07 12:16:37 +0200
commit6b87dae76d931ead9838db1f66a6ff1fe1cc1dd1 (patch)
tree0a2273d9db0499214e18a041987339eac9d20ac9 /archaeological_context_records
parent75730c0ac55c935c03e58977405b4b8a2233595d (diff)
parent3d8b8d86f01ecb9b37e24e25fd15500b8f4fb2a0 (diff)
downloadIshtar-6b87dae76d931ead9838db1f66a6ff1fe1cc1dd1.tar.bz2
Ishtar-6b87dae76d931ead9838db1f66a6ff1fe1cc1dd1.zip
Merge branch 'master' into v0.9
Diffstat (limited to 'archaeological_context_records')
-rw-r--r--archaeological_context_records/locale/django.pot69
-rw-r--r--archaeological_context_records/models.py43
-rw-r--r--archaeological_context_records/templates/ishtar/sheet_contextrecord.html10
-rw-r--r--archaeological_context_records/tests.py52
-rw-r--r--archaeological_context_records/urls.py4
5 files changed, 139 insertions, 39 deletions
diff --git a/archaeological_context_records/locale/django.pot b/archaeological_context_records/locale/django.pot
index eedcad733..82c64ac4c 100644
--- a/archaeological_context_records/locale/django.pot
+++ b/archaeological_context_records/locale/django.pot
@@ -4,14 +4,15 @@
# Étienne Loks <etienne.loks at peacefrogs net>, 2010-2015.
# Valérie-Emma Leroux <emma@iggdrasil.net>, 2016. #zanata
# Valérie-Emma Leroux <emma@iggdrasil.net>, 2017. #zanata
+# Étienne Loks <etienne.loks@iggdrasil.net>, 2017. #zanata
msgid ""
msgstr ""
-#: forms.py:47 forms.py:51 models.py:216 models.py:589 wizards.py:77
+#: forms.py:47 forms.py:51 models.py:216 models.py:599 wizards.py:77
msgid "Operation"
msgstr ""
-#: forms.py:59 forms.py:141 models.py:218 models.py:557
+#: forms.py:59 forms.py:141 models.py:218 models.py:567
msgid "ID"
msgstr ""
@@ -63,11 +64,11 @@ msgstr ""
msgid "General"
msgstr ""
-#: forms.py:140 models.py:181 models.py:214 models.py:559
+#: forms.py:140 models.py:181 models.py:214 models.py:569
msgid "Parcel"
msgstr ""
-#: forms.py:143 models.py:219 models.py:560
+#: forms.py:143 models.py:219 models.py:570
#: templates/ishtar/sheet_contextrecord.html:30
msgid "Description"
msgstr ""
@@ -104,7 +105,7 @@ msgstr ""
msgid "Depth of appearance (m)"
msgstr ""
-#: forms.py:156 forms.py:376 models.py:241 models.py:558
+#: forms.py:156 forms.py:376 models.py:241 models.py:568
msgid "Context record type"
msgstr ""
@@ -151,7 +152,7 @@ msgstr ""
msgid "Dating type"
msgstr ""
-#: forms.py:285 ishtar_menu.py:29 models.py:619
+#: forms.py:285 ishtar_menu.py:29 models.py:641
msgid "Context record"
msgstr ""
@@ -320,7 +321,7 @@ msgstr ""
msgid "Documentation types"
msgstr ""
-#: models.py:172 models.py:561
+#: models.py:172 models.py:571
msgid "Periods"
msgstr ""
@@ -425,74 +426,94 @@ msgctxt "short"
msgid "Context record"
msgstr ""
-#: models.py:491
+#: models.py:501
msgid "Inverse relation"
msgstr ""
-#: models.py:495 models.py:518 models.py:556
+#: models.py:505 models.py:528 models.py:566
msgid "Relation type"
msgstr ""
-#: models.py:496
+#: models.py:506
msgid "Relation types"
msgstr ""
-#: models.py:513
+#: models.py:523
msgid "ID (left)"
msgstr ""
-#: models.py:514
+#: models.py:524
msgid "Context record type (left)"
msgstr ""
-#: models.py:515
+#: models.py:525
msgid "Parcel (left)"
msgstr ""
-#: models.py:516
+#: models.py:526
msgid "Description (left)"
msgstr ""
-#: models.py:517
+#: models.py:527
msgid "Periods (left)"
msgstr ""
-#: models.py:519
+#: models.py:529
msgid "ID (right)"
msgstr ""
-#: models.py:520
+#: models.py:530
msgid "Context record type (right)"
msgstr ""
-#: models.py:521
+#: models.py:531
msgid "Parcel (right)"
msgstr ""
-#: models.py:522
+#: models.py:532
msgid "Description (right)"
msgstr ""
-#: models.py:523
+#: models.py:533
msgid "Periods (right)"
msgstr ""
-#: models.py:532
+#: models.py:542
msgid "Record relation"
msgstr ""
-#: models.py:533
+#: models.py:543
msgid "Record relations"
msgstr ""
-#: models.py:616
+#: models.py:626
msgid "Context record documentation"
msgstr ""
-#: models.py:617
+#: models.py:627
msgid "Context record documentations"
msgstr ""
+#: models.py:630
+msgid "Can view all Context record sources"
+msgstr ""
+
+#: models.py:632
+msgid "Can view own Context record source"
+msgstr ""
+
+#: models.py:634
+msgid "Can add own Context record source"
+msgstr ""
+
+#: models.py:636
+msgid "Can change own Context record source"
+msgstr ""
+
+#: models.py:638
+msgid "Can delete own Context record source"
+msgstr ""
+
#: views.py:102
msgid "New context record"
msgstr ""
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)
diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
index 272dcb28e..29e45d3a9 100644
--- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
+++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
@@ -15,7 +15,7 @@
{% include "ishtar/blocks/sheet_external_id.html" %}
<ul class='form-flex'>
-<li><label>{% if item.operation.code_patriarche %}{%trans "Complete ID:"%}{% else %}{%trans "Temporary ID:"%}{% endif %}</label><span class='value'>{{item.full_label}}</span></li>
+<li><label>{% if item.operation.code_patriarche %}{%trans "Complete ID"%}{% else %}{%trans "Temporary ID"%}{% endif %}</label><span class='value'>{{item.full_label}}</span></li>
{% include "ishtar/blocks/sheet_creation_section.html" %}
@@ -79,9 +79,9 @@
{% field_li num_ref_label item.operation.operation_code %}
{% field_li "Patriarche OA code" item.operation.code_patriarche %}
{% field_li_detail "Head scientist" item.operation.scientist %}
-<li><label>{%trans "State:"%}</label><span class='value'>{% if item.operation.is_active %}{% trans "Active file" %}{% else %}{%trans "Closed operation" %}{% endif %}</span></li>
+<li><label>{%trans "State"%}</label><span class='value'>{% if item.operation.is_active %}{% trans "Active file" %}{% else %}{%trans "Closed operation" %}{% endif %}</span></li>
{% if not item.operation.is_active %}
-<li><label>{%trans "Closing date:"%}</label> <span class='value'>{{ item.operation.closing.date }} <strong>{%trans "by" %}</strong> {{ item.operation.closing.user }}</span></li>
+<li><label>{%trans "Closing date"%}</label> <span class='value'>{{ item.operation.closing.date }} <strong>{%trans "by" %}</strong> {{ item.operation.closing.user }}</span></li>
{% endif %}
{% field_li "Type" item.operation.operation_type %}
{% field_li_multiple "Remains" item.operation.remains %}
@@ -90,8 +90,8 @@
{% field "Comment" item.operation.comment "<pre>" "</pre>" %}
<h3>{% trans "Localisation"%}</h3>
-<p><label>{%trans "Towns:"%}</label> <span class='value'>{{ item.operation.towns.all|join:", " }}</span></p>
-<p><label>{%trans "Related operation:"%}</label>
+<p><label>{%trans "Towns"%}</label> <span class='value'>{{ item.operation.towns.all|join:", " }}</span></p>
+<p><label>{%trans "Related operation"%}</label>
<span class='value'><a href="#" onclick='load_window("{% url show-operation item.operation.pk ''%}");'>{{ item.operation }}</a></span></p>
{% else %}<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <label>{%trans "No operation linked to this context unit!"%}</label></p>
{% endif %}
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 6bb293e4d..4226b42ea 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -235,7 +235,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):
models.RecordRelations.objects.create(
left_record=cr_1, right_record=cr_2, relation_type=sym_rel_type)
- def testExternalID(self):
+ def test_external_id(self):
cr = self.context_records[0]
self.assertEqual(
cr.external_id,
@@ -255,7 +255,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):
cr.operation
)
- def test_cache_update(self):
+ def test_upstream_cache_update(self):
cr = self.create_context_record()[0]
cr_pk = cr.pk
# OP2010 - 1 | A | 1 | CR 1
@@ -288,6 +288,54 @@ class ContextRecordTest(ContextRecordInit, TestCase):
ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')
self.assertEqual(ope_id, 'OP2017-1')
+ def test_downstream_cache_update(self):
+ if settings.USE_SPATIALITE_FOR_TESTS:
+ # using views - can only be tested with postgresql
+ return
+
+ cr = self.create_context_record()[0]
+
+ from archaeological_finds.models import Find, BaseFind, MaterialType
+
+ data = {
+ 'label': "Find me a reason",
+ 'context_record': cr,
+ 'history_modifier': self.get_default_user()
+ }
+ bf = BaseFind.objects.create(**data)
+ find = Find.objects.create(
+ history_modifier=self.get_default_user(),
+ label='Find me too'
+ )
+ find.base_finds.add(bf)
+
+ mat = MaterialType.objects.create(
+ label='Adamentium', txt_idx='admentium', code='ADA')
+ find.material_types.add(mat)
+
+ class TestObj(object):
+ def __init__(self):
+ self.find_reached = []
+
+ def reached(self, sender, **kwargs):
+ instance = kwargs.get('instance')
+ if sender in (Find, BaseFind):
+ self.find_reached.append(instance)
+
+ test_obj = TestObj()
+ cr = models.ContextRecord.objects.get(pk=cr.pk)
+ cr.test_obj = test_obj
+ cr.label = "New label!"
+ cr.save()
+
+ # verify the relevance of the update
+ bf = BaseFind.objects.get(pk=bf.pk)
+ self.assertIn("New label!", bf.cache_complete_id)
+
+ # bulk update of find cached label gen don't have to be
+ # reached
+ self.assertEqual(len(test_obj.find_reached), 0)
+
class ContextRecordSearchTest(ContextRecordInit, TestCase):
fixtures = ImportContextRecordTest.fixtures
diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py
index 341d321f9..e89a76aef 100644
--- a/archaeological_context_records/urls.py
+++ b/archaeological_context_records/urls.py
@@ -23,7 +23,7 @@ from archaeological_context_records import models
from ishtar_common.wizards import check_rights
import views
-# be carreful: each check_rights must be relevant with ishtar_menu
+# be careful: each check_rights must be relevant with ishtar_menu
# forms
urlpatterns = patterns(
@@ -33,7 +33,7 @@ urlpatterns = patterns(
check_rights(['view_contextrecord', 'view_own_contextrecord'])(
views.record_search_wizard), name='record_search'),
url(r'record_creation/(?P<step>.+)?$',
- check_rights(['add_contextrecord'])(
+ check_rights(['add_contextrecord', 'add_own_contextrecord'])(
views.record_creation_wizard), name='record_creation'),
url(r'record_modification/(?P<step>.+)?$',
check_rights(['change_contextrecord', 'change_own_contextrecord'])(