From 1d184d869a59889242cb9c8447762c4d462988c2 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 6 Jun 2016 17:11:33 +0200 Subject: Show treatments in find sheet --- archaeological_finds/models.py | 40 ++++++++- .../templates/ishtar/sheet_find.html | 98 +++++++++++++++------- 2 files changed, 107 insertions(+), 31 deletions(-) (limited to 'archaeological_finds') diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 0a1e59a68..b84b7614f 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -304,10 +304,10 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): find_number = models.IntegerField(_("Find number"), blank=True, null=True) upstream_treatment = models.ForeignKey( "Treatment", blank=True, null=True, - related_name='downstream_treatment', + related_name='downstream', verbose_name=_("Upstream treatment")) downstream_treatment = models.ForeignKey( - "Treatment", blank=True, null=True, related_name='upstream_treatment', + "Treatment", blank=True, null=True, related_name='upstream', verbose_name=_("Downstream treatment")) datings = models.ManyToManyField(Dating, verbose_name=_(u"Dating"), related_name='find') @@ -413,6 +413,42 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): bf.context_record.operation.get_reference(), self.index) + def upstream_treatments(self): + treatments = [] + base_finds = [bf.pk for bf in self.base_finds.all()] + if self.upstream_treatment and \ + self.upstream_treatment.pk not in treatments: + treatments.append((self.upstream_treatment.upstream.distinct( + ).order_by('label').all(), self.upstream_treatment)) + for upstream in self.upstream_treatment.upstream.all(): + if upstream.pk != self.pk and not [ + bf.pk for bf in upstream.base_finds.all() + if bf.pk in base_finds]: + continue + for items, treatment in upstream.upstream_treatments(): + if treatment.pk not in treatments: + treatments.append((treatment.upstream.order_by( + 'label').all(), treatment)) + return treatments + + def downstream_treatments(self): + treatments = [] + base_finds = [bf.pk for bf in self.base_finds.all()] + if self.downstream_treatment and \ + self.downstream_treatment.pk not in treatments: + treatments.append((self.downstream_treatment.downstream.distinct( + ).order_by('label').all(), self.downstream_treatment)) + for downstream in self.downstream_treatment.downstream.all(): + if downstream.pk != self.pk and not [ + bf.pk for bf in downstream.base_finds.all() + if bf.pk in base_finds]: + continue + for items, treatment in downstream.downstream_treatments(): + if treatment.pk not in treatments: + treatments.append((treatment.downstream.order_by( + 'label').all(), treatment)) + return treatments + def get_department(self): bf = self.get_first_base_find() if not bf: diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index 429a7da2b..ff3dc55dd 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -1,5 +1,5 @@ {% extends "ishtar/sheet.html" %} -{% load i18n window_field from_dict %} +{% load i18n window_field from_dict link_to_window %} {% block head_sheet %} {{block.super}} @@ -28,42 +28,82 @@ {% endif%} -{% field "Free-ID" item.label %} -{% field "Previous ID" item.previous_id %} -{% field "Description" item.description %} -{% field "Created by" item.history_creator.ishtaruser.full_label %} -{% field "Administrative index" item.administrative_index %} -{% field_multiple "Material types" item.material_types %} -{% field "Dating" item.dating %} -{% field "Length (cm)" item.length %} -{% field "Width (cm)" item.width %} -{% field "Height (cm)" item.height %} -{% field "Diameter (cm)" item.diameter %} -{% field "Volume (l)" item.volume %} + -{% if item.upstream_treatment %}

-{{item.upstream_treatment}} ({% for up in item.upstream_treatment.upstream_treatment.all %}{% if forloop.counter0 %}, {%endif %}{{up}}{% endfor %})

{% endif%} -{% if item.downstream_treatment %}

-{{item.downstream_treatment}} ({% for dt in item.downstream_treatment.downstream_treatment.all %}{% if forloop.counter0 %}, {%endif %}{{dt}}{% endfor %})

{% endif%} -{% if item.container %}

-{{item.container}}

{% endif%} +{% if item.upstream_treatment %} + + + + + + + + + + {% for items, treatment in item.upstream_treatments %} + + + + + + + + {% endfor %} +
{% trans "Upstream treatment" %}
{% trans "Type" %}{% trans "Related find" %}{% trans "Person" %}{% trans "Start date" %}{% trans "End date" %}
{{ treatment.treatment_type }}{% for item in items %}{% if not forloop.first %} ; {% endif %} {{item}} {{ item|link_to_window}}{% endfor %}{{ treatment.person|default_if_none:"" }}{{ treatment.start_date|default_if_none:"" }}{{ treatment.end_date|default_if_none:"" }}
+{% endif %} + +{% if item.downstream_treatment %} + + + + + + + + + + {% for items, treatment in item.downstream_treatments %} + + + + + + + + {% endfor %} +
{% trans "Downstream treatment" %}
{% trans "Type" %}{% trans "Related find" %}{% trans "Person" %}{% trans "Start date" %}{% trans "End date" %}
{{ treatment.treatment_type }}{% for item in items %}{% if not forloop.first %} ; {% endif %} {{item}} {{ item|link_to_window}}{% endfor %}{{ treatment.person|default_if_none:"" }}{{ treatment.start_date|default_if_none:"" }}{{ treatment.end_date|default_if_none:"" }}
+{% endif %}

{% trans "Associated base finds"%}

@@ -103,7 +143,7 @@ {% endfor %} {% if not item.source.count %} -

{% trans "No document associated to this find" %}

+ {% trans "No document associated to this find" %} {% else %} -- cgit v1.2.3
{%trans "Documents"%}