diff options
-rw-r--r-- | archaeological_operations/forms.py | 44 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 3 | ||||
-rw-r--r-- | ishtar_common/templates/blocks/inline_formset.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/relations_wizard.html | 32 | ||||
-rw-r--r-- | ishtar_common/templatetags/inline_formset.py | 7 |
5 files changed, 83 insertions, 5 deletions
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 %}<tr><td colspan='3'><ul>{% for error in frm.errors.values %}<li>{{error}}</li>{% endfor%}</ul></td></tr>{% endif %} <tr>{% endif %}{% for field in frm.visible_fields %}<td> {% if field.errors %}<div class='errors'>{{ field.errors.as_ul }}</div>{% 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 %} +<form action="." method="post">{% csrf_token %} +<div class='form'> +{{ wizard.form.media }} +{{ wizard.management_form }} +{{ wizard.form.management_form }} + +{% if wizard.form.non_form_errors%} +<table class='formset'> +<tr class='error'><th colspan='2'>{{wizard.form.non_form_errors}}</th></tr> +</table>{%endif%} + +<table class='inline-table'> + <tr>{% for field in wizard.form.forms.0 %}<th{% if not forloop.last %} rowspan='2'{% endif %}>{{ field.label_tag }}</th>{% endfor %}</tr> + <tr><td>({% trans "all"%} <input type='checkbox' name='check-all' class='check-all'/>)</td></tr> + {% inline_formset 'Parcels' wizard.form.forms False %} +</table> +<p><button name="formset_modify" value="{{wizard.steps.current}}">{% trans "Add/Modify" %}</button></p> +<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> +{{ previous_fields|safe }} +{% block "validation_bar" %} +{% include 'ishtar/wizard/validation_bar.html' %} +{% endblock %} +</div> +</form> +{% 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} |