summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/forms.py2
-rw-r--r--archaeological_finds/forms_treatments.py4
-rw-r--r--archaeological_finds/locale/django.pot94
-rw-r--r--archaeological_finds/models_finds.py24
-rw-r--r--archaeological_finds/tests.py37
5 files changed, 111 insertions, 50 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 2e7cc75f5..884bbe9a1 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -144,6 +144,8 @@ class FindForm(ManageOldType, forms.Form):
previous_id = forms.CharField(label=_("Previous ID"), required=False)
description = forms.CharField(label=_("Description"),
widget=forms.Textarea, required=False)
+ get_first_base_find__discovery_date = forms.DateField(
+ label=_(u"Discovery date"), widget=widgets.JQueryDate, required=False)
get_first_base_find__batch = forms.ChoiceField(
label=_(u"Batch/object"), choices=[],
required=False)
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index 83fb11028..55e223b5d 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -95,7 +95,7 @@ class BaseTreatmentForm(ManageOldType, forms.Form):
label=_(u"Other ref."), max_length=200, required=False)
year = forms.IntegerField(label=_("Year"),
initial=lambda: datetime.datetime.now().year,
- validators=[validators.MinValueValidator(1600),
+ validators=[validators.MinValueValidator(1000),
validators.MaxValueValidator(2100)])
treatment_type = forms.MultipleChoiceField(
label=_(u"Treatment type"), choices=[],
@@ -450,7 +450,7 @@ class TreatmentFileForm(ManageOldType, forms.Form):
max_length=1000, required=False)
year = forms.IntegerField(label=_("Year"),
initial=lambda: datetime.datetime.now().year,
- validators=[validators.MinValueValidator(1600),
+ validators=[validators.MinValueValidator(1000),
validators.MaxValueValidator(2100)])
internal_reference = forms.CharField(
label=_(u"Internal ref."), max_length=60, required=False)
diff --git a/archaeological_finds/locale/django.pot b/archaeological_finds/locale/django.pot
index 121d3d48a..1a09f38df 100644
--- a/archaeological_finds/locale/django.pot
+++ b/archaeological_finds/locale/django.pot
@@ -13,8 +13,8 @@ msgstr ""
msgid "Context record"
msgstr ""
-#: forms.py:128 ishtar_menu.py:32 models_finds.py:705 models_finds.py:1160
-#: models_finds.py:1181 models_treatments.py:298
+#: forms.py:128 ishtar_menu.py:32 models_finds.py:705 models_finds.py:1166
+#: models_finds.py:1187 models_treatments.py:298
#: templates/ishtar/sheet_find.html:5
msgid "Find"
msgstr ""
@@ -195,13 +195,13 @@ msgid "Period"
msgstr ""
#: forms.py:316 forms_treatments.py:138 forms_treatments.py:283
-#: forms_treatments.py:481 models_finds.py:1186 models_treatments.py:130
+#: forms_treatments.py:481 models_finds.py:1192 models_treatments.py:130
#: models_treatments.py:309 templates/ishtar/sheet_find.html:94
#: templates/ishtar/sheet_find.html:136
msgid "Start date"
msgstr ""
-#: forms.py:318 models_finds.py:1187 models_treatments.py:310
+#: forms.py:318 models_finds.py:1193 models_treatments.py:310
#: templates/ishtar/sheet_find.html:95 templates/ishtar/sheet_find.html:137
msgid "End date"
msgstr ""
@@ -378,7 +378,7 @@ msgstr ""
msgid "Treatment type"
msgstr ""
-#: forms_treatments.py:68 forms_treatments.py:650 views.py:398
+#: forms_treatments.py:68 forms_treatments.py:650 views.py:401
msgid "Treatment search"
msgstr ""
@@ -472,7 +472,7 @@ msgstr ""
#: forms_treatments.py:267 forms_treatments.py:442 ishtar_menu.py:108
#: models_treatments.py:516 models_treatments.py:544 models_treatments.py:619
-#: wizards.py:187 templates/ishtar/sheet_treatmentfile.html:5
+#: wizards.py:188 templates/ishtar/sheet_treatmentfile.html:5
msgid "Treatment request"
msgstr ""
@@ -579,7 +579,7 @@ msgstr ""
msgid "Applicant organisation"
msgstr ""
-#: forms_treatments.py:430 forms_treatments.py:655 views.py:502
+#: forms_treatments.py:430 forms_treatments.py:655 views.py:505
msgid "Treatment request search"
msgstr ""
@@ -662,7 +662,7 @@ msgstr ""
msgid "Documentation"
msgstr ""
-#: ishtar_menu.py:133 ishtar_menu.py:214 models_finds.py:1183
+#: ishtar_menu.py:133 ishtar_menu.py:214 models_finds.py:1189
msgid "Administrative act"
msgstr ""
@@ -945,43 +945,43 @@ msgstr ""
msgid "FIND"
msgstr ""
-#: models_finds.py:1146
+#: models_finds.py:1152
msgid "Find documentation"
msgstr ""
-#: models_finds.py:1147
+#: models_finds.py:1153
msgid "Find documentations"
msgstr ""
-#: models_finds.py:1150
+#: models_finds.py:1156
msgid "Can view all Find sources"
msgstr ""
-#: models_finds.py:1152
+#: models_finds.py:1158
msgid "Can view own Find source"
msgstr ""
-#: models_finds.py:1154
+#: models_finds.py:1160
msgid "Can add own Find source"
msgstr ""
-#: models_finds.py:1156
+#: models_finds.py:1162
msgid "Can change own Find source"
msgstr ""
-#: models_finds.py:1158
+#: models_finds.py:1164
msgid "Can delete own Find source"
msgstr ""
-#: models_finds.py:1184
+#: models_finds.py:1190
msgid "Person"
msgstr ""
-#: models_finds.py:1190
+#: models_finds.py:1196
msgid "Property"
msgstr ""
-#: models_finds.py:1191
+#: models_finds.py:1197
msgid "Properties"
msgstr ""
@@ -1207,119 +1207,119 @@ msgstr ""
msgid "Find modification"
msgstr ""
-#: views.py:189
+#: views.py:192
msgid "Find deletion"
msgstr ""
-#: views.py:194
+#: views.py:197
msgid "Find: source search"
msgstr ""
-#: views.py:202
+#: views.py:205
msgid "Find: new source"
msgstr ""
-#: views.py:210
+#: views.py:213
msgid "Find: source modification"
msgstr ""
-#: views.py:225
+#: views.py:228
msgid "Find: source deletion"
msgstr ""
-#: views.py:239
+#: views.py:242
msgid "New basket"
msgstr ""
-#: views.py:258
+#: views.py:261
msgid "Manage items in basket"
msgstr ""
-#: views.py:278
+#: views.py:281
msgid "Manage basket"
msgstr ""
-#: views.py:369
+#: views.py:372
msgid "Delete basket"
msgstr ""
-#: views.py:419
+#: views.py:422
msgid "New treatment"
msgstr ""
-#: views.py:427 views.py:519
+#: views.py:430 views.py:522
msgid "Modify"
msgstr ""
-#: views.py:444
+#: views.py:447
msgid "Treatment deletion"
msgstr ""
-#: views.py:451
+#: views.py:454
msgid "Treatment: search administrative act"
msgstr ""
-#: views.py:460
+#: views.py:463
msgid "Treatment: new administrative act"
msgstr ""
-#: views.py:470
+#: views.py:473
msgid "Treatment: administrative act modification"
msgstr ""
-#: views.py:479
+#: views.py:482
msgid "Treatment: administrative act deletion"
msgstr ""
-#: views.py:512
+#: views.py:515
msgid "New treatment request"
msgstr ""
-#: views.py:535
+#: views.py:538
msgid "Treatment request deletion"
msgstr ""
-#: views.py:542
+#: views.py:545
msgid "Treatment request: search administrative act"
msgstr ""
-#: views.py:552
+#: views.py:555
msgid "Treatment request: new administrative act"
msgstr ""
-#: views.py:562
+#: views.py:565
msgid "Treatment request: administrative act modification"
msgstr ""
-#: views.py:571
+#: views.py:574
msgid "Treatment request: administrative act deletion"
msgstr ""
-#: views.py:597
+#: views.py:600
msgid "Treatment: source search"
msgstr ""
-#: views.py:612
+#: views.py:615
msgid "Treatment: source modification"
msgstr ""
-#: views.py:627
+#: views.py:630
msgid "Treatment: source deletion"
msgstr ""
-#: views.py:640
+#: views.py:643
msgid "Treatment request: source search"
msgstr ""
-#: views.py:656
+#: views.py:659
msgid "Treatment request: source modification"
msgstr ""
-#: views.py:674
+#: views.py:677
msgid "Treatment request: source deletion"
msgstr ""
-#: wizards.py:63 wizards.py:199
+#: wizards.py:63 wizards.py:200
msgid "Operation"
msgstr ""
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 78280bede..66059079b 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -24,7 +24,8 @@ from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
from django.db import connection, transaction
from django.db.models import Max, Q
-from django.db.models.signals import m2m_changed, post_save, post_delete
+from django.db.models.signals import m2m_changed, post_save, post_delete, \
+ pre_delete
from django.utils.translation import ugettext_lazy as _, ugettext
from ishtar_common.utils import cached_label_changed, post_save_point
@@ -1102,7 +1103,28 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms,
Dating.fix_dating_association(self)
+def pre_clean_find(sender, **kwargs):
+ if not kwargs.get('instance'):
+ return
+ instance = kwargs.get('instance')
+
+ for bf in instance.base_finds.all():
+ # no other find is associated
+ if not bf.find.exclude(pk=instance.pk).count():
+ bf.delete()
+
+ if instance.downstream_treatment:
+ # TODO: not managed for now. Raise an error?
+ return
+ if not instance.upstream_treatment:
+ return
+ instance.upstream_treatment.upstream.clear()
+ instance.upstream_treatment.downstream.clear()
+ instance.upstream_treatment.delete()
+
+
post_save.connect(cached_label_changed, sender=Find)
+pre_delete.connect(pre_clean_find, sender=Find)
def base_find_find_changed(sender, **kwargs):
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index f8f134c0a..b4a798807 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -412,6 +412,20 @@ class FindTest(FindInit, TestCase):
self.assertEqual(response.status_code, 200)
self.assertIn('class="sheet"', response.content)
+ def test_delete(self):
+ self.create_finds(force=True)
+ first_bf = self.base_finds[0]
+ self.finds[1].base_finds.add(first_bf)
+
+ self.finds[0].delete()
+ # on delete the selected base find is not deleted if another find
+ # is related to it
+ self.assertEqual(models.BaseFind.objects.filter(
+ pk=self.base_finds[0].pk).count(), 1)
+ self.finds[1].delete()
+ self.assertEqual(models.BaseFind.objects.filter(
+ pk=self.base_finds[0].pk).count(), 0)
+
class FindSearchTest(FindInit, TestCase):
fixtures = FIND_FIXTURES
@@ -599,3 +613,26 @@ class PackagingTest(FindInit, TestCase):
self.assertNotIn(
item, self.finds,
msg="Other basket have not been upgraded after packaging")
+
+ def test_delete(self):
+ # manage treatment deletion
+ treatment_type = models.TreatmentType.objects.get(txt_idx='packaging')
+ treatment = models.Treatment()
+
+ initial_find = self.finds[0]
+ treatment.save(user=self.get_default_user(), items=self.basket)
+ treatment.treatment_types.add(treatment_type)
+
+ resulting_find = models.Find.objects.get(
+ upstream_treatment__upstream=initial_find,
+ base_finds__pk=initial_find.base_finds.all()[0].pk
+ )
+ resulting_find.delete()
+
+ self.assertEqual(
+ models.Treatment.objects.filter(pk=treatment.pk).count(), 0)
+ q = models.Find.objects.filter(pk=initial_find.pk)
+ # initial find not deleted
+ self.assertEqual(q.count(), 1)
+ initial_find = q.all()[0]
+ self.assertEqual(initial_find.upstream_treatment, None)