diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-13 17:15:06 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-13 17:15:06 +0100 |
commit | 92073870e0090a12272bdd832b522c2516d760ad (patch) | |
tree | aafda29084b953738dba9a962b773e90da29d152 | |
parent | 99eca09d2edad9db6cf95a278ab9cfa8b420bf47 (diff) | |
download | Ishtar-92073870e0090a12272bdd832b522c2516d760ad.tar.bz2 Ishtar-92073870e0090a12272bdd832b522c2516d760ad.zip |
Sheet find: limit to 15 related finds in treatment tables
-rw-r--r-- | archaeological_finds/forms.py | 10 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 25 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/sheet_find.html | 8 |
3 files changed, 27 insertions, 16 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 11ecf8152..3558b0346 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -166,17 +166,17 @@ class FindForm(ManageOldType, forms.Form): required=False, max_length=120 ) get_first_base_find__x = forms.FloatField(label=_(u"X"), required=False) + get_first_base_find__y = forms.FloatField(label=_(u"Y"), required=False) + get_first_base_find__z = forms.FloatField(label=_(u"Z"), required=False) + get_first_base_find__spatial_reference_system = \ + forms.ChoiceField(label=_(u"Spatial Reference System"), required=False, + choices=[]) get_first_base_find__estimated_error_x = \ forms.FloatField(label=_(u"Estimated error for X"), required=False) - get_first_base_find__y = forms.FloatField(label=_(u"Y"), required=False) get_first_base_find__estimated_error_y = \ forms.FloatField(label=_(u"Estimated error for Y"), required=False) - get_first_base_find__z = forms.FloatField(label=_(u"Z"), required=False) get_first_base_find__estimated_error_z = \ forms.FloatField(label=_(u"Estimated error for Z"), required=False) - get_first_base_find__spatial_reference_system = \ - forms.ChoiceField(label=_(u"Spatial Reference System"), required=False, - choices=[]) length = FloatField(label=_(u"Length (cm)"), required=False) width = FloatField(label=_(u"Width (cm)"), required=False) height = FloatField(label=_(u"Height (cm)"), required=False) diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 93bed4ab3..45c750f66 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -548,17 +548,20 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): bf.context_record.operation.get_reference(), self.index) - def _get_treatments(self, model, rel='upstream'): + def _get_treatments(self, model, rel='upstream', limit=None): treatments, findtreats = [], [] - for findtreat in model.objects.filter( + q = model.objects.filter( find_id=self.pk).order_by( 'treatment_nb', 'treatment__start_date', - 'treatment__end_date').distinct().all(): + 'treatment__end_date') + for findtreat in q.distinct().all(): if findtreat.pk in findtreats: continue findtreats.append(findtreat.pk) q = getattr(findtreat.treatment, rel).distinct().order_by( 'label') + if limit: + q = q[:limit] treatments.append((q.all(), findtreat.treatment)) return treatments @@ -568,15 +571,23 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): return "" return "{} {}".format(self.weight, self.weight_unit or "") - def upstream_treatments(self): + def upstream_treatments(self, limit=None): from archaeological_finds.models_treatments import \ FindUpstreamTreatments - return self._get_treatments(FindUpstreamTreatments, 'upstream') + return self._get_treatments(FindUpstreamTreatments, 'upstream', + limit=limit) - def downstream_treatments(self): + def limited_upstream_treatments(self): + return self.upstream_treatments(15) + + def downstream_treatments(self, limit=None): from archaeological_finds.models_treatments import \ FindDownstreamTreatments - return self._get_treatments(FindDownstreamTreatments, 'downstream') + return self._get_treatments(FindDownstreamTreatments, 'downstream', + limit=limit) + + def limited_downstream_treatments(self): + return self.downstream_treatments(15) def all_treatments(self): return self.upstream_treatments() + self.downstream_treatments() diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index 40ccdd713..d7425eda2 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -95,13 +95,13 @@ <th>{% trans "Year - index" %}</th> <th>{% trans "Label" %}</th> <th>{% trans "Type" %}</th> - <th>{% trans "Related finds" %}</th> + <th>{% trans "Related finds (max. 15 displayed)" %}</th> <th>{% trans "Doer" %}</th> <th>{% trans "Container" %}</th> <th>{% trans "Start date" %}</th> <th>{% trans "End date" %}</th> </tr> - {% for items, treatment in item.upstream_treatments %} + {% for items, treatment in item.limited_upstream_treatments %} <tr> <td> <a class="display_details" href="#" @@ -135,13 +135,13 @@ <th>{% trans "Year - index" %}</th> <th>{% trans "Label" %}</th> <th>{% trans "Type" %}</th> - <th>{% trans "Related finds" %}</th> + <th>{% trans "Related finds (max. 15 displayed)" %}</th> <th>{% trans "Doer" %}</th> <th>{% trans "Container" %}</th> <th>{% trans "Start date" %}</th> <th>{% trans "End date" %}</th> </tr> - {% for items, treatment in item.downstream_treatments %} + {% for items, treatment in item.limited_downstream_treatments %} <tr> <td> <a class="display_details" href="#" |