From 7569568dd7810cec673758a27ad1f725110e0c1d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 9 Sep 2015 22:36:23 +0200 Subject: Archaeological finds: update sheet and search --- archaeological_finds/forms.py | 3 ++ archaeological_finds/models.py | 5 ++- .../templates/ishtar/sheet_find.html | 51 ++++++++++++---------- .../templates/ishtar/blocks/window_field.html | 3 ++ ishtar_common/templatetags/window_field.py | 8 ++++ ishtar_common/templatetags/window_tables.py | 8 +--- ishtar_common/views.py | 4 +- 7 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 ishtar_common/templates/ishtar/blocks/window_field.html create mode 100644 ishtar_common/templatetags/window_field.py diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 82c32b2dc..ae91b8383 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -126,6 +126,7 @@ class FindSelect(TableSelect): dating__period = forms.ChoiceField(label=_(u"Period"), choices=[]) # TODO search by warehouse material_type = forms.ChoiceField(label=_(u"Material type"), choices=[]) + object_types = forms.ChoiceField(label=_(u"Object type"), choices=[]) conservatory_state = forms.ChoiceField(label=_(u"Conservatory state"), choices=[]) base_finds__find__description = forms.CharField(label=_(u"Description")) @@ -144,6 +145,8 @@ class FindSelect(TableSelect): models.ConservatoryState.get_types() self.fields['conservatory_state'].help_text = \ models.ConservatoryState.get_help() + self.fields['object_types'].choices = \ + models.ObjectType.get_types() class FindFormSelection(forms.Form): diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 947cd9067..ce56fac27 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -76,7 +76,7 @@ class ObjectType(GeneralType): verbose_name_plural = _(u"Object types") ordering = ('parent__label', 'label',) - def __unicode__(self): + def full_label(self): lbls = [self.label] item = self while item.parent: @@ -84,6 +84,9 @@ class ObjectType(GeneralType): lbls.append(item.label) return u" > ".join(reversed(lbls)) + def __unicode__(self): + return self.label + class BaseFind(BaseHistorizedItem, OwnPerms): label = models.CharField(_(u"ID"), max_length=60) diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index c5bd637a5..3047b7e87 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 %} +{% load i18n window_field %} {% block head_sheet %} {{block.super}} @@ -28,29 +28,32 @@ {% endif%} -{% if item.label %}

-{{item.label}}

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

-{{item.description}}

{% endif%} -

{{ item.history_creator.ishtaruser.full_label }}

-

-{{item.material_type}}

-{% if item.dating %}

-{{item.dating}}

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

-{{item.volume}}

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

-{{item.weight}} {% if item.weight_unit %}{{item.weight_unit}}{% else %}g{% endif %}

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

-{{item.find_number}}

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

-{{item.conservatory_state}}

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

-{{item.preservation_to_consider}}

+{% field "Name" item.label %} +{% field "Description" item.description %} +{% field "Created by" item.history_creator.ishtaruser.full_label %} +{% field "Material type" item.material_type %} +{% 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.weight %}{% with item.weight|add:' '|add:item.weight_unit as weight %} +{% field "Weight" weight %} +{% endwith %}{% endif %} + +{% field "Find number" item.find_number %} +{% field "Conservatory state" item.conservatory_state %} +{% field "Type of preservation to consider" item.preservation_to_consider %} + +{% if item.object_types.count %} +

+ + {% for object_type in item.object_types.all %} + {% if forloop.counter0 %}, {% endif %}{{ object_type }} + {% endfor %} +

{% endif %} {% if item.upstream_treatment %}

diff --git a/ishtar_common/templates/ishtar/blocks/window_field.html b/ishtar_common/templates/ishtar/blocks/window_field.html new file mode 100644 index 000000000..9b2bc6540 --- /dev/null +++ b/ishtar_common/templates/ishtar/blocks/window_field.html @@ -0,0 +1,3 @@ +{% load i18n %} +{% if data %}

+{{data}}

{% endif%} diff --git a/ishtar_common/templatetags/window_field.py b/ishtar_common/templatetags/window_field.py new file mode 100644 index 000000000..90cb5391c --- /dev/null +++ b/ishtar_common/templatetags/window_field.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.inclusion_tag('ishtar/blocks/window_field.html') +def field(caption, data): + return {'caption': caption, 'data': data} diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py index 5c19eb6df..5eebf6359 100644 --- a/ishtar_common/templatetags/window_tables.py +++ b/ishtar_common/templatetags/window_tables.py @@ -1,12 +1,8 @@ - from django import template -from django.utils.translation import ugettext as _ -import re register = template.Library() + @register.inclusion_tag('ishtar/blocks/window_tables/documents.html') def table_document(caption, data): - return {'caption':caption, 'data':data} - - + return {'caption': caption, 'data': data} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index c9211c219..4f089d258 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -146,7 +146,9 @@ def get_autocomplete_generic(model, extra={'available': True}): query = query & Q(label__icontains=q) limit = 20 objects = model.objects.filter(query)[:limit] - data = json.dumps([{'id': obj.pk, 'value': unicode(obj)} + get_label = lambda x: x.full_label() if hasattr(x, 'full_label') \ + else unicode(x) + data = json.dumps([{'id': obj.pk, 'value': get_label(obj)} for obj in objects]) return HttpResponse(data, mimetype='text/plain') return func -- cgit v1.2.3