summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-29 12:15:51 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-29 12:15:51 +0100
commit6081b054b1167c2288381a9a7f59ecf354339d85 (patch)
tree26118a3e75bd8047de57caae9927ce533709dd80 /archaeological_finds
parentc23fd5b7956a3e1c878fa5c87ec4fca5d9c79edb (diff)
downloadIshtar-6081b054b1167c2288381a9a7f59ecf354339d85.tar.bz2
Ishtar-6081b054b1167c2288381a9a7f59ecf354339d85.zip
Treatments: add a view to get all non modif treatments
- manage go back in the modi treatment hierarchy
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/migrations/0058_views_find_nonmodif_treatments.py20
-rw-r--r--archaeological_finds/models.py9
-rw-r--r--archaeological_finds/models_finds.py31
-rw-r--r--archaeological_finds/models_treatments.py70
-rw-r--r--archaeological_finds/templates/ishtar/sheet_find.html16
5 files changed, 127 insertions, 19 deletions
diff --git a/archaeological_finds/migrations/0058_views_find_nonmodif_treatments.py b/archaeological_finds/migrations/0058_views_find_nonmodif_treatments.py
new file mode 100644
index 000000000..288089f9d
--- /dev/null
+++ b/archaeological_finds/migrations/0058_views_find_nonmodif_treatments.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2019-01-29 12:06
+from __future__ import unicode_literals
+
+from django.db import migrations
+from archaeological_finds.models import FindNonModifTreatments
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_finds', '0057_migrate_main_image'),
+ ]
+
+ operations = [
+ migrations.RunSQL(
+ FindNonModifTreatments.CREATE_SQL,
+ reverse_sql=FindNonModifTreatments.DELETE_SQL
+ )
+ ]
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index 23177faee..ad349e315 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -7,7 +7,7 @@ from archaeological_finds.models_finds import MaterialType, ConservatoryState, \
from archaeological_finds.models_treatments import Treatment, \
AbsFindTreatments, FindUpstreamTreatments, FindDownstreamTreatments, \
FindTreatments, TreatmentFile, TreatmentFileType, \
- TreatmentState
+ TreatmentState, FindNonModifTreatments
__all__ = ['MaterialType', 'ConservatoryState', 'IntegrityType', 'CheckedType',
'RemarkabilityType', 'ObjectType', 'BaseFind', 'FindBasket', 'Find',
@@ -15,6 +15,7 @@ __all__ = ['MaterialType', 'ConservatoryState', 'IntegrityType', 'CheckedType',
'AlterationType', 'AlterationCauseType', 'TreatmentEmergencyType',
'BatchType', 'TreatmentType', 'TreatmentState',
'Treatment', 'AbsFindTreatments', 'FindUpstreamTreatments',
- 'FindDownstreamTreatments', 'FindTreatments', 'TreatmentFile',
- 'TreatmentFileType', 'CommunicabilityType',
- 'MaterialTypeQualityType', 'ObjectTypeQualityType']
+ 'FindNonModifTreatments', 'FindDownstreamTreatments',
+ 'FindTreatments', 'TreatmentFile', 'TreatmentFileType',
+ 'CommunicabilityType', 'MaterialTypeQualityType',
+ 'ObjectTypeQualityType']
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 6fe56afe5..ccf42952f 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -1354,12 +1354,14 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
operations_lbl.admin_order_field = \
"base_finds__context_record__operation__cached_label"
- def _get_treatments(self, model, rel='upstream', limit=None):
+ def _get_treatments(self, model, rel='upstream', limit=None, count=False):
treatments, findtreats = [], []
q = model.objects.filter(
find_id=self.pk).order_by(
'-treatment__year', '-treatment__index', '-treatment__start_date',
'-treatment__end_date')
+ if count:
+ return q.count()
for findtreat in q.distinct().all():
if findtreat.pk in findtreats:
continue
@@ -1371,12 +1373,6 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
treatments.append((q.all(), findtreat.treatment))
return treatments
- @property
- def weight_string(self):
- if not self.weight:
- return ""
- return "{} {}".format(self.weight, self.weight_unit or "")
-
def upstream_treatments(self, limit=None):
from archaeological_finds.models_treatments import \
FindUpstreamTreatments
@@ -1398,6 +1394,27 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
def all_treatments(self):
return self.upstream_treatments() + self.downstream_treatments()
+ def non_modif_treatments(self, limit=None):
+ from archaeological_finds.models_treatments import \
+ FindNonModifTreatments
+ return self._get_treatments(FindNonModifTreatments, 'finds',
+ limit=limit)
+
+ def non_modif_treatments_count(self):
+ from archaeological_finds.models_treatments import \
+ FindNonModifTreatments
+ return self._get_treatments(FindNonModifTreatments, 'finds',
+ count=True)
+
+ def limited_non_modif_treatments(self):
+ return self.non_modif_treatments(15)
+
+ @property
+ def weight_string(self):
+ if not self.weight:
+ return ""
+ return "{} {}".format(self.weight, self.weight_unit or "")
+
def get_department(self):
bf = self.get_first_base_find()
if not bf:
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index 5a654cb70..0a04cefb9 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -601,7 +601,7 @@ class AbsFindTreatments(models.Model):
treatment = models.OneToOneField(Treatment, verbose_name=_(u"Treatment"),
primary_key=True)
# primary_key is set to prevent django to ask for an id column
- # treatment is not a primary key
+ # treatment is not a real primary key
treatment_nb = models.IntegerField(_(u"Order"))
TABLE_COLS = ["treatment__" + col for col in Treatment.TABLE_COLS] + \
['treatment_nb']
@@ -624,6 +624,74 @@ class AbsFindTreatments(models.Model):
self.find, self.treatment, self.treatment_nb)
+class FindNonModifTreatments(AbsFindTreatments):
+ CREATE_SQL = """
+ CREATE VIEW find_nonmodif_treatments_tree AS
+ WITH RECURSIVE rel_tree AS (
+ SELECT f.id AS find_id, of.id AS old_find_id,
+ f.downstream_treatment_id, f.upstream_treatment_id,
+ 1 AS level, ARRAY[]::integer[] AS path_info
+ FROM archaeological_finds_find f
+ INNER JOIN archaeological_finds_find of
+ ON of.downstream_treatment_id = f.upstream_treatment_id
+ WHERE f.downstream_treatment_id is NULL AND
+ f.upstream_treatment_id is NOT NULL
+ UNION ALL
+ SELECT c.id AS find_id, p.old_find_id, c.downstream_treatment_id,
+ c.upstream_treatment_id,
+ p.level + 1, p.path_info||c.downstream_treatment_id
+ FROM archaeological_finds_find c
+ JOIN rel_tree p
+ ON c.downstream_treatment_id = p.upstream_treatment_id
+ AND (p.path_info = ARRAY[]::integer[] OR
+ NOT (c.downstream_treatment_id =
+ ANY(p.path_info[0:array_upper(p.path_info, 1)-1]))
+ )
+ )
+ SELECT DISTINCT find_id, old_find_id, path_info, level
+ FROM rel_tree
+ UNION ALL
+ SELECT id AS find_id, id AS old_find_id,
+ ARRAY[]::integer[] AS path_info, 0 AS level
+ FROM archaeological_finds_find f
+ WHERE f.downstream_treatment_id is NULL
+ ORDER BY find_id;
+
+ CREATE VIEW find_nonmodif_treatments AS
+ SELECT DISTINCT y.find_id,
+ y.old_find_id,
+ ft.treatment_id as treatment_id,
+ 1 AS treatment_nb
+ FROM (SELECT * FROM find_nonmodif_treatments_tree) y
+ INNER JOIN archaeological_finds_find_treatments ft
+ ON ft.find_id = y.old_find_id
+ ORDER BY y.find_id, ft.treatment_id;
+
+ -- deactivate deletion
+ CREATE RULE find_nonmodif_treatments_del AS
+ ON DELETE TO find_nonmodif_treatments
+ DO INSTEAD DELETE FROM archaeological_finds_find where id=NULL;
+ """
+ DELETE_SQL = """
+ DROP VIEW find_nonmodif_treatments;
+ DROP VIEW find_nonmodif_treatments_tree;
+ """
+ TABLE_COLS = ['treatment__treatment_type',
+ 'treatment__upstream',
+ 'treatment__start_date', 'treatment__end_date',
+ 'treatment__location', 'treatment__container',
+ 'treatment__person', 'treatment_nb']
+
+ # search parameters
+ EXTRA_REQUEST_KEYS = {'find_id': 'find_id'}
+
+ class Meta:
+ managed = False
+ db_table = 'find_nonmodif_treatments'
+ unique_together = ('find', 'treatment')
+ ordering = ('find', '-treatment_nb')
+
+
class FindUpstreamTreatments(AbsFindTreatments):
CREATE_SQL = """
CREATE VIEW find_uptreatments_tree AS
diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html
index ff0ccb2b0..1af09b030 100644
--- a/archaeological_finds/templates/ishtar/sheet_find.html
+++ b/archaeological_finds/templates/ishtar/sheet_find.html
@@ -20,9 +20,10 @@
{% with permission_view_own_document=permission_view_own_document %}
{% with m2m_listing_datings=item|m2m_listing:'datings' %}
+{% with non_modif_treatments_count=item.non_modif_treatments_count %}
{% with display_datings=item.integrities.count|or_:item.remarkabilities.count|or_:item.conservatory_state|or_:item.conservatory_comment|or_:item.alterations.count|or_:item.alteration_causes.count|or_:item.preservation_to_considers.count|or_:item.appraisal_date|or_:item.treatment_emergency|or_:item.insurance_value|or_:item.estimated_value|or_:m2m_listing_datings|or_:item.dating_comment %}
-{% with display_warehouse_treatments=item.container|or_:item.container_ref|or_:item.upstream_treatment|or_:item.downstream_treatment|or_:item.treatments.count %}
+{% with display_warehouse_treatments=item.container|or_:item.container_ref|or_:item.upstream_treatment|or_:item.downstream_treatment|or_:non_modif_treatments_count %}
{% with can_view_documents=permission_view_own_document|or_:permission_view_document %}
{% with display_documents=can_view_documents|and_:item.documents.count %}
@@ -263,9 +264,9 @@
{% field_flex "Precise localisation" item.container.cached_division %}
</div>
{% endif %}
- {% if item.upstream_treatment or item.downstream_treatment or item.treatments.count %}
- {% if item.treatments.all %}
- <h3>{% trans "Treatments"%}</h3>
+ {% if item.upstream_treatment or item.downstream_treatment or non_modif_treatments_count %}
+ {% if non_modif_treatments_count %}
+ <h3>{% trans "Simple treatments"%}</h3>
<table id='{{window_id}}-treatments' class="table table-striped">
<tr>
<th>&nbsp;</th>
@@ -279,7 +280,8 @@
<th>{% trans "Start date" %}</th>
<th>{% trans "End date" %}</th>
</tr>
- {% for treatment in item.treatments.all %}
+ {# {% for treatment in item.treatments.all %} #}
+ {% for items, treatment in item.non_modif_treatments %}
<tr>
<td>
<a class="display_details" href="#"
@@ -291,7 +293,7 @@
<td class='string'>{{ treatment.label|default_if_none:"-" }}</td>
<td class='string'>{{ treatment.treatment_types_lbl }}</td>
<td class='string'>{{ treatment.treatment_state|default_if_none:"-" }}</td>
- <td class='item-list'>{% for it in treatment.limited_finds %}<span>{{it}} {{it|link_to_window:request}}</span>{% endfor %}</td>
+ <td class='item-list'>{% for it in items %}<span>{{it}} {{it|link_to_window:request}}</span>{% endfor %}</td>
<td class='string'>{{ treatment.person|default_if_none:"-" }}</td>
<td class='string'>{{ treatment.container|default_if_none:"-" }}</td>
<td class='string'>{{ treatment.start_date|default_if_none:"-" }}</td>
@@ -395,7 +397,7 @@
{% endif %}
</div>
-{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}
+{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}
{% endblock %}