summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-04-04 20:49:29 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-04-04 20:49:29 +0200
commitc5e94062adefdd8cb0aeb730830921d5d546a86b (patch)
tree673bfb7389360f360ddaafcfe1a4d133d67f4c36
parente121fde541630e72888a3314f50c3ac0fb88186d (diff)
downloadIshtar-c5e94062adefdd8cb0aeb730830921d5d546a86b.tar.bz2
Ishtar-c5e94062adefdd8cb0aeb730830921d5d546a86b.zip
Inline formset to manage parcels
-rw-r--r--archaeological_operations/forms.py8
-rw-r--r--archaeological_operations/wizards.py5
-rw-r--r--ishtar_common/static/media/style.css13
-rw-r--r--ishtar_common/templates/blocks/form_snippet.html (renamed from ishtar_common/templates/form_snippet.html)0
-rw-r--r--ishtar_common/templates/blocks/inline_formset.html25
-rw-r--r--ishtar_common/templates/ishtar/wizard/default_wizard.html4
-rw-r--r--ishtar_common/templates/ishtar/wizard/parcels_wizard.html28
-rw-r--r--ishtar_common/templates/ishtar/wizard/towns_wizard.html10
-rw-r--r--ishtar_common/templatetags/inline_formset.py18
-rw-r--r--ishtar_common/templatetags/table_form.py2
10 files changed, 100 insertions, 13 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 0318d4207..741dfb2b7 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -37,8 +37,9 @@ from archaeological_files.models import File
import models
from widgets import ParcelWidget
from ishtar_common import widgets
-from ishtar_common.forms import FinalForm, FormSet, ClosingDateFormSelection, \
- formset_factory, get_now, reverse_lazy, get_form_selection, TableSelect
+from ishtar_common.forms import BaseFormSet, FinalForm, FormSet, \
+ ClosingDateFormSelection, formset_factory, get_now, reverse_lazy, \
+ get_form_selection, TableSelect
from ishtar_common.forms_common import TownForm, TownFormSet, TownFormset, \
AuthorFormset, SourceForm, SourceSelect, \
SourceDeletionForm, get_town_field
@@ -94,6 +95,9 @@ class ParcelForm(forms.Form):
return self.cleaned_data
class ParcelFormSet(FormSet):
+ def add_fields(self, form, index):
+ super(FormSet, self).add_fields(form, index)
+
def clean(self):
"""Checks that no parcels are duplicated."""
return self.check_duplicate(('town', 'section',
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py
index 3281a5723..2b13e3353 100644
--- a/archaeological_operations/wizards.py
+++ b/archaeological_operations/wizards.py
@@ -34,9 +34,12 @@ class OperationWizard(Wizard):
def get_template_names(self):
templates = super(OperationWizard, self).get_template_names()
- current_step = self.steps. current
+ current_step = self.steps.current
if current_step.startswith('towns-'):
templates = ['ishtar/wizard/towns_wizard.html'] + templates
+ if current_step.startswith('parcels-') or \
+ current_step.startswith('parcelsgeneral-') :
+ templates = ['ishtar/wizard/parcels_wizard.html'] + templates
return templates
def get_context_data(self, form, **kwargs):
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/form_snippet.html b/ishtar_common/templates/blocks/form_snippet.html
index 2f841e078..2f841e078 100644
--- a/ishtar_common/templates/form_snippet.html
+++ b/ishtar_common/templates/blocks/form_snippet.html
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 %}<div class='errors'>{{extra_formset.non_form_errors.as_ul}}</div>{% endif %}
+ {% if header %}<table class='inline-table'>
+ <caption>{% trans caption %}</caption>
+ {% endif %}{% for frm in formset%}{% if header %}<thead>
+ <tr>{% for field in frm.visible_fields%}
+ <th>{{field.label}}</th>{%endfor%}
+ </tr>
+ </thead>{% endif %}
+ {% if forloop.first and not skip %}<tbody>{%endif%}
+ {% if not skip or not forloop.first %}<tr>{% endif %}{% for field in frm.visible_fields %}
+ <td>
+ {% if field.errors %}<div class='errors'>{{ field.errors.as_ul }}</div>{% endif %}
+ {{ field }}
+ {# Include the hidden fields in the form #}
+ {% if forloop.first %}
+ {{ formset.management_form }}
+ {% for hidden in frm.hidden_fields %}
+ {{ hidden }}
+ {% endfor %}
+ {% endif %}
+ </td>{% endfor %}
+ {% if not skip or not forloop.last %}</tr>{% endif %}{%endfor%}
+ {% if not skip %}</tbody>{% endif %}{% if header %}
+ </table>{% endif %}
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 %}
<h2>{{wizard_label}}</h2>
<form action="." method="post" name='wizard'>{% csrf_token %}
<ul id='form_path'>
@@ -17,6 +18,8 @@
<li>&raquo;&nbsp;<button name="form_prev_step" value="{{forloop.counter|add:previous_step_counter}}">{{step.form_label}}</button></li>
{% endfor %}
</ul>
+{% endblock %}
+{% block wizard_form %}
<div class='form'>
{% if reminder %}<div class='reminder'>{{ reminder }}</div>{%endif%}
{{ wizard.form.media }}
@@ -43,3 +46,4 @@
</div>
</form>
{% 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 %}
+<div class='form'>
+{% if reminder %}<div class='reminder'>{{ reminder }}</div>{%endif%}
+{{ wizard.form.media }}
+{{ wizard.management_form }}
+ {{ wizard.form.management_form }}
+<div class='top_button'><input type="submit" id="submit_form" value="{% trans "Validate" %}"/></div>
+ {%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>{{ field.label_tag }}</th>{% endfor %}</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 }}
+<input type="submit" id="submit_form" name='validate' value="{% trans "Validate" %}"/>
+{% if next_steps %}<input type="submit" id="submit_end_form" name='validate_and_end' value="{% trans "Validate and end" %}"/>{% endif %}
+</div>
+</form>
+{% 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 %}
-<h2>{{wizard_label}}</h2>
-<form action="." method="post" name='wizard'>{% csrf_token %}
-<ul id='form_path'>
-{% for step in previous_steps %}
- <li>&raquo;&nbsp;<button name="form_prev_step" value="{{forloop.counter0}}">{{step.form_label}}</button></li>
-{% endfor %}
- <li class='current'>&raquo;&nbsp;<a href='#'>{{current_step.form_label}}</a></li>
-</ul>
+{% block wizard_form %}
<div class='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}