summaryrefslogtreecommitdiff
path: root/archaeological_finds/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/models.py')
-rw-r--r--archaeological_finds/models.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index aaa145c65..6b1da9506 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -23,7 +23,8 @@ from django.conf import settings
from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
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.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _, ugettext
@@ -828,8 +829,6 @@ class Treatment(BaseHistorizedItem, ImageModel, OwnPerms):
help_text=_(
u"Location where the treatment is done. Target warehouse for "
u"a move."))
- other_location = models.CharField(_(u"Location (not referenced)"),
- max_length=200, blank=True, null=True)
person = models.ForeignKey(
Person, verbose_name=_(u"Responsible"), blank=True, null=True,
on_delete=models.SET_NULL, related_name='treatments')
@@ -925,6 +924,20 @@ class Treatment(BaseHistorizedItem, ImageModel, OwnPerms):
for attr in ('year', 'index', 'label')])
+def pre_delete_treatment(sender, **kwargs):
+ treatment = kwargs.get('instance')
+ for find in Find.objects.filter(upstream_treatment=treatment).all():
+ if find.downstream_treatment:
+ # a new treatment have be done since the deleted treatment
+ raise NotImplemented()
+ find.delete()
+ for find in Find.objects.filter(downstream_treatment=treatment).all():
+ find.downstream_treatment = None
+ find.save()
+
+post_delete.connect(pre_delete_treatment, sender=Treatment)
+
+
class AbsFindTreatments(models.Model):
find = models.ForeignKey(Find, verbose_name=_(u"Find"),
related_name='%(class)s_related')
@@ -983,6 +996,10 @@ class FindUpstreamTreatments(AbsFindTreatments):
FROM find_uptreatments_tree) y
WHERE path_info[nb] is not NULL
ORDER BY find_id, treatment_id;
+
+ -- deactivate deletion
+ CREATE RULE find_uptreatments_del AS ON DELETE TO find_uptreatments
+ DO INSTEAD DELETE FROM archaeological_finds_find where id=NULL;
"""
TABLE_COLS = ['treatment__treatment_type',
'treatment__upstream',
@@ -1027,6 +1044,10 @@ class FindDownstreamTreatments(AbsFindTreatments):
FROM find_downtreatments_tree) y
WHERE path_info[nb] is not NULL
ORDER BY find_id, treatment_id;
+
+ -- deactivate deletion
+ CREATE RULE find_downtreatments_del AS ON DELETE TO find_downtreatments
+ DO INSTEAD DELETE FROM archaeological_finds_find where id=NULL;
"""
TABLE_COLS = ['treatment__treatment_type',
'treatment__downstream',
@@ -1053,6 +1074,10 @@ class FindTreatments(AbsFindTreatments):
SELECT find_id, treatment_id, treatment_nb, FALSE as upstream
FROM find_downtreatments
ORDER BY find_id, treatment_id, upstream;
+
+ -- deactivate deletion
+ CREATE RULE find_treatments_del AS ON DELETE TO find_treatments
+ DO INSTEAD DELETE FROM archaeological_finds_find where id=NULL;
"""
upstream = models.BooleanField(_(u"Is upstream"))