From f41b22f173bb9c9c331fa9eab2a7a8d47d0a57db Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 4 Apr 2013 20:49:29 +0200 Subject: Inline formset to manage parcels --- ishtar_common/static/media/style.css | 13 ++++++++++ ishtar_common/templates/blocks/form_snippet.html | 13 ++++++++++ ishtar_common/templates/blocks/inline_formset.html | 25 +++++++++++++++++++ ishtar_common/templates/form_snippet.html | 13 ---------- .../templates/ishtar/wizard/default_wizard.html | 4 ++++ .../templates/ishtar/wizard/parcels_wizard.html | 28 ++++++++++++++++++++++ .../templates/ishtar/wizard/towns_wizard.html | 10 +------- ishtar_common/templatetags/inline_formset.py | 18 ++++++++++++++ ishtar_common/templatetags/table_form.py | 2 +- 9 files changed, 103 insertions(+), 23 deletions(-) create mode 100644 ishtar_common/templates/blocks/form_snippet.html create mode 100644 ishtar_common/templates/blocks/inline_formset.html delete mode 100644 ishtar_common/templates/form_snippet.html create mode 100644 ishtar_common/templates/ishtar/wizard/parcels_wizard.html create mode 100644 ishtar_common/templatetags/inline_formset.py (limited to 'ishtar_common') diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css index cad9a224a..fe078fa3c 100644 --- a/ishtar_common/static/media/style.css +++ b/ishtar_common/static/media/style.css @@ -528,6 +528,19 @@ a.remove{ border:1px solid; } +.form table.inline-table th{ + text-align:center; + font-weight:bold; +} + +.form table.inline-table td{ + text-align:center; +} + +.inline-table input[type=text]{ + width:60px; +} + .widget-parcel{ width:60px; } diff --git a/ishtar_common/templates/blocks/form_snippet.html b/ishtar_common/templates/blocks/form_snippet.html new file mode 100644 index 000000000..2f841e078 --- /dev/null +++ b/ishtar_common/templates/blocks/form_snippet.html @@ -0,0 +1,13 @@ +{% load i18n %} + {% if form.non_field_errors %} + {{form.non_field_errors}} + {%endif%} + {% for field in form %}{% if not field.is_hidden %} + + {{ field.label_tag }} + {{ field.errors }}{{field|safe}}{% if field.help_text %} + ? + + +
{{field.help_text}}
+ {%endif%}{% else %}{{field}}{% endif %}{% endfor %} diff --git a/ishtar_common/templates/blocks/inline_formset.html b/ishtar_common/templates/blocks/inline_formset.html new file mode 100644 index 000000000..e36405118 --- /dev/null +++ b/ishtar_common/templates/blocks/inline_formset.html @@ -0,0 +1,25 @@ +{% load i18n %} + {% if extra_formset.non_form_errors %}
{{extra_formset.non_form_errors.as_ul}}
{% endif %} + {% if header %} + + {% endif %}{% for frm in formset%}{% if header %} + {% for field in frm.visible_fields%} + {%endfor%} + + {% endif %} + {% if forloop.first and not skip %}{%endif%} + {% if not skip or not forloop.first %}{% endif %}{% for field in frm.visible_fields %} + {% endfor %} + {% if not skip or not forloop.last %}{% endif %}{%endfor%} + {% if not skip %}{% endif %}{% if header %} +
{% trans caption %}
{{field.label}}
+ {% if field.errors %}
{{ field.errors.as_ul }}
{% endif %} + {{ field }} + {# Include the hidden fields in the form #} + {% if forloop.first %} + {{ formset.management_form }} + {% for hidden in frm.hidden_fields %} + {{ hidden }} + {% endfor %} + {% endif %} +
{% endif %} diff --git a/ishtar_common/templates/form_snippet.html b/ishtar_common/templates/form_snippet.html deleted file mode 100644 index 2f841e078..000000000 --- a/ishtar_common/templates/form_snippet.html +++ /dev/null @@ -1,13 +0,0 @@ -{% load i18n %} - {% if form.non_field_errors %} - {{form.non_field_errors}} - {%endif%} - {% for field in form %}{% if not field.is_hidden %} - - {{ field.label_tag }} - {{ field.errors }}{{field|safe}}{% if field.help_text %} - ? - - -
{{field.help_text}}
- {%endif%}{% else %}{{field}}{% endif %}{% endfor %} diff --git a/ishtar_common/templates/ishtar/wizard/default_wizard.html b/ishtar_common/templates/ishtar/wizard/default_wizard.html index e2abc80b6..b56324a78 100644 --- a/ishtar_common/templates/ishtar/wizard/default_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/default_wizard.html @@ -6,6 +6,7 @@ {{form.media}} {% endblock %} {% block content %} +{% block wizard_head %}

{{wizard_label}}

{% csrf_token %}
    @@ -17,6 +18,8 @@
  • » 
  • {% endfor %}
+{% endblock %} +{% block wizard_form %}
{% if reminder %}
{{ reminder }}
{%endif%} {{ wizard.form.media }} @@ -43,3 +46,4 @@
{% endblock %} +{% endblock %} diff --git a/ishtar_common/templates/ishtar/wizard/parcels_wizard.html b/ishtar_common/templates/ishtar/wizard/parcels_wizard.html new file mode 100644 index 000000000..94e9820ab --- /dev/null +++ b/ishtar_common/templates/ishtar/wizard/parcels_wizard.html @@ -0,0 +1,28 @@ +{% extends "ishtar/wizard/default_wizard.html" %} +{% load i18n range inline_formset %} +{% block extra_head %} +{{wizard.form.media}} +{% endblock %} +{% block wizard_form %} +
+{% if reminder %}
{{ reminder }}
{%endif%} +{{ 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 %}{% endfor %} + {% inline_formset 'Parcels' wizard.form.forms False %} +
{{ field.label_tag }}
+

+ +{{ previous_fields|safe }} + +{% if next_steps %}{% endif %} +
+ +{% endblock %} diff --git a/ishtar_common/templates/ishtar/wizard/towns_wizard.html b/ishtar_common/templates/ishtar/wizard/towns_wizard.html index cd40e6049..cc3487df3 100644 --- a/ishtar_common/templates/ishtar/wizard/towns_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/towns_wizard.html @@ -4,15 +4,7 @@ {% block extra_head %} {{wizard.form.media}} {% endblock %} -{% block content %} -

{{wizard_label}}

-
{% csrf_token %} - +{% block wizard_form %}
{% if TOWNS %} {% if wizard.form.forms %} diff --git a/ishtar_common/templatetags/inline_formset.py b/ishtar_common/templatetags/inline_formset.py new file mode 100644 index 000000000..c3220f207 --- /dev/null +++ b/ishtar_common/templatetags/inline_formset.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +# -*- 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""" + Render a formset as an inline table. + 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} + diff --git a/ishtar_common/templatetags/table_form.py b/ishtar_common/templatetags/table_form.py index 7adb54d65..0ab49d93f 100644 --- a/ishtar_common/templatetags/table_form.py +++ b/ishtar_common/templatetags/table_form.py @@ -5,6 +5,6 @@ from django.template import Library register = Library() -@register.inclusion_tag('form_snippet.html') +@register.inclusion_tag('blocks/form_snippet.html') def table_form(form): return {'form': form} -- cgit v1.2.3