From ab191a5873011db4b44adf6d4e532681c29b4cb3 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 18 Dec 2015 18:46:44 +0100 Subject: Operation wizard: improve relations layout (form and summary) --- archaeological_operations/forms.py | 44 ++++++++++++++++++++++ archaeological_operations/wizards.py | 3 ++ ishtar_common/templates/blocks/inline_formset.html | 2 +- .../templates/ishtar/wizard/relations_wizard.html | 32 ++++++++++++++++ ishtar_common/templatetags/inline_formset.py | 7 ++-- 5 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 ishtar_common/templates/ishtar/wizard/relations_wizard.html diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 8c3650c21..1dad60ea1 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -354,6 +354,50 @@ class RecordRelationsForm(forms.Form): self.fields['relation_type'].choices = \ models.RelationType.get_types() + @classmethod + def _format_lst(cls, current): + nc = [] + for rel, ope in sorted(current): + if not nc or nc[-1][0] != rel: + nc.append([rel, []]) + nc[-1][1].append(ope) + rendered = u";".join( + [u"{}{} {}".format(rel, _(u":"), u" ; ".join(opes)) + for rel, opes in nc]) + return rendered + + @classmethod + def get_formated_datas(cls, cleaned_datas): + result, current, deleted = [], [], [] + for data in cleaned_datas: + if not data: + continue + try: + relation_type = models.RelationType.objects.get( + pk=data.get('relation_type')) + except models.RelationType.DoesNotExist: + continue + try: + right_record = models.Operation.objects.get( + pk=data.get('right_record')) + except models.Operation.DoesNotExist: + continue + values = [unicode(relation_type), right_record.reference] + if data.get('DELETE'): + deleted.append(values) + else: + current.append(values) + if current: + nc = [] + for rel, ope in sorted(current): + if not nc or nc[-1][0] != rel: + nc.append([rel, []]) + nc[-1][1].append(ope) + result.append((_("Current relations"), cls._format_lst(current))) + if deleted: + result.append((_("Deleted relations"), u" ; ".join(deleted))) + return result + RecordRelationsFormSet = formset_factory(RecordRelationsForm, can_delete=True) RecordRelationsFormSet.form_label = _(u"Relations") diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 78a5c3350..2e7b3c4b4 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -40,6 +40,7 @@ class OperationWizard(Wizard): model = models.Operation object_parcel_type = 'operation' parcel_step_key = 'parcels' + relations_step_key = 'relations' # step contening the current(s) town(s) town_step_keys = ['towns-', 'townsgeneral-'] town_input_id = 'town' # input id of the current(s) town(s) @@ -52,6 +53,8 @@ class OperationWizard(Wizard): current_step = self.steps.current if current_step.startswith(self.parcel_step_key): templates = ['ishtar/wizard/parcels_wizard.html'] + templates + elif current_step.startswith(self.relations_step_key): + templates = ['ishtar/wizard/relations_wizard.html'] + templates return templates def get_current_file(self): diff --git a/ishtar_common/templates/blocks/inline_formset.html b/ishtar_common/templates/blocks/inline_formset.html index 3affb7bf3..4d4042985 100644 --- a/ishtar_common/templates/blocks/inline_formset.html +++ b/ishtar_common/templates/blocks/inline_formset.html @@ -12,7 +12,7 @@ {% if frm.errors %}{% endif %} {% endif %}{% for field in frm.visible_fields %} {% if field.errors %}
{{ field.errors.as_ul }}
{% endif %} - {{ field }} + {{ field|safe }} {# Include the hidden fields in the form #} {% if forloop.first %} {{ formset.management_form }} diff --git a/ishtar_common/templates/ishtar/wizard/relations_wizard.html b/ishtar_common/templates/ishtar/wizard/relations_wizard.html new file mode 100644 index 000000000..9ca592ca8 --- /dev/null +++ b/ishtar_common/templates/ishtar/wizard/relations_wizard.html @@ -0,0 +1,32 @@ +{% extends "ishtar/wizard/default_wizard.html" %} +{% load i18n range inline_formset %} +{% block extra_head %} +{{wizard.form.media}} +{% endblock %} +{% block wizard_form %} +
{% csrf_token %} +
+{{ wizard.form.media }} +{{ wizard.management_form }} +{{ wizard.form.management_form }} + +{% if wizard.form.non_form_errors%} + + +
{{wizard.form.non_form_errors}}
{%endif%} + + + {% for field in wizard.form.forms.0 %}{{ field.label_tag }}{% endfor %} + + {% inline_formset 'Parcels' wizard.form.forms False %} +
({% trans "all"%} )
+

+ +{{ previous_fields|safe }} +{% block "validation_bar" %} +{% include 'ishtar/wizard/validation_bar.html' %} +{% endblock %} +
+
+{% endblock %} + diff --git a/ishtar_common/templatetags/inline_formset.py b/ishtar_common/templatetags/inline_formset.py index c3220f207..5e833c06f 100644 --- a/ishtar_common/templatetags/inline_formset.py +++ b/ishtar_common/templatetags/inline_formset.py @@ -2,11 +2,10 @@ # -*- coding: utf-8 -*- from django import template -from django.utils.translation import ugettext as _ -import re register = template.Library() + @register.inclusion_tag('blocks/inline_formset.html') def inline_formset(caption, formset, header=True, skip=False): u""" @@ -14,5 +13,5 @@ def inline_formset(caption, formset, header=True, skip=False): For i18n of the caption be carreful to add manualy the caption label to the translated fields """ - return {'caption':caption, 'formset':formset, 'header':header, 'skip':skip} - + return {'caption': caption, 'formset': formset, 'header': header, + 'skip': skip} -- cgit v1.2.3