diff options
| -rw-r--r-- | ishtar/furnitures/forms_operations.py | 18 | ||||
| -rw-r--r-- | ishtar/furnitures/templatetags/table_form.py | 10 | ||||
| -rw-r--r-- | ishtar/furnitures/widgets.py | 2 | ||||
| -rw-r--r-- | ishtar/templates/default_wizard.html | 21 | ||||
| -rw-r--r-- | ishtar/templates/form_snippet.html | 13 | ||||
| -rw-r--r-- | ishtar/templates/grid_form.html | 10 | 
6 files changed, 35 insertions, 39 deletions
| diff --git a/ishtar/furnitures/forms_operations.py b/ishtar/furnitures/forms_operations.py index 17fd8f69d..3c2dbd734 100644 --- a/ishtar/furnitures/forms_operations.py +++ b/ishtar/furnitures/forms_operations.py @@ -118,7 +118,6 @@ class OperationWizard(Wizard):              year = int(request.session[storage.prefix]['step_data']\                                    [general_form_key][general_form_key+"-year"])              data[prefix+'-hidden_year'] = year -            data[prefix+'-hidden_ope'] = True          # manage the dynamic choice of towns          if step.startswith('towns-') and hasattr(form, 'management_form'):              data['TOWNS'] = self.get_towns(request, storage) @@ -158,13 +157,11 @@ class OperationWizard(Wizard):      def get_form_initial(self, request, storage, step):          initial = super(OperationWizard, self).get_form_initial(request,                                                             storage, step) -        if initial: -            return initial          # put hidden year and default operation_code field for refs          general_form_key = 'general-' + self.url_name -        initial = {}          if step.startswith('refs-') \ -           and self.session_has_key(request, storage, general_form_key): +           and self.session_has_key(request, storage, general_form_key)\ +           and 'operation_code' not in initial:              year = int(request.session[storage.prefix]['step_data']\                                    [general_form_key][general_form_key+"-year"])              initial['hidden_year'] = year @@ -258,23 +255,24 @@ class OperationFormReference(forms.Form):                           'associated_file':models.File,                           'operation_type':models.OperationType}      currents = {'associated_file':models.File} +    pk = forms.IntegerField(required=False, widget=forms.HiddenInput)      hidden_year = forms.IntegerField(widget=forms.HiddenInput) -    hidden_ope = forms.BooleanField(widget=forms.HiddenInput, required=False)      operation_code = forms.IntegerField(label=_(u"Operation code"))      if settings.COUNTRY == 'fr':          code_patriarche = forms.IntegerField(label=u"Code PATRIARCHE",                                  required=False)          code_dracar = forms.CharField(label=u"Code DRACAR", required=False,                             validators=[validators.MaxLengthValidator(10)]) +      def clean(self):          cleaned_data = self.cleaned_data -        if 'hidden_ope' in cleaned_data and cleaned_data['hidden_ope']: -            return cleaned_data          year = cleaned_data.get("hidden_year")          operation_code = cleaned_data.get("operation_code")          ops = models.Operation.objects.filter(year=year, -                                        operation_code=operation_code).count() -        if ops: +                                              operation_code=operation_code) +        if 'pk' in cleaned_data and cleaned_data['pk']: +            ops = ops.exclude(pk=cleaned_data['pk']) +        if ops.count():              max_val = models.Operation.objects.filter(year=year).aggregate(                                  Max('operation_code'))["operation_code__max"]              raise forms.ValidationError(_(u"Operation code already exist for " diff --git a/ishtar/furnitures/templatetags/table_form.py b/ishtar/furnitures/templatetags/table_form.py new file mode 100644 index 000000000..7adb54d65 --- /dev/null +++ b/ishtar/furnitures/templatetags/table_form.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from django.template import Library + +register = Library() + +@register.inclusion_tag('form_snippet.html') +def table_form(form): +    return {'form': form} diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py index d813e2e63..e058f7074 100644 --- a/ishtar/furnitures/widgets.py +++ b/ishtar/furnitures/widgets.py @@ -214,7 +214,7 @@ class JQueryJqGrid(forms.RadioSelect):          self.multiple = multiple
      def render(self, name, value=None, attrs=None):
 -        t = loader.get_template('grid_form.html')
 +        t = loader.get_template('form_snippet.html')
          rendered = t.render(Context({'form':self.form}))
          rendered += """
  </table>
 diff --git a/ishtar/templates/default_wizard.html b/ishtar/templates/default_wizard.html index 752728ab3..2b8ade350 100644 --- a/ishtar/templates/default_wizard.html +++ b/ishtar/templates/default_wizard.html @@ -1,6 +1,7 @@  {% extends "base.html" %}  {% load i18n %}  {% load range %} +{% load table_form %}  {% block extra_head %}  {{form.media}}  {% endblock %} @@ -19,29 +20,13 @@    {%if form.non_form_errors%}<tr class='error'><th colspan='2'>{{form.non_form_errors}}</th></tr>{%endif%}    {{ form.management_form }}    {% for formsetform in form.forms %} -  {% for field in formsetform %} -  <tr{% if field.field.required %} class='required'{% endif %}> -    <th>{{ field.label_tag }}</th> -    <td> {{ field.errors }}{{field|safe}}</td>{% if field.help_text %} -    <td><a href="#{{field.name}}" class="help_display" title="{% trans "Help"%}">?</a></td> -  </tr> -  <tr class="help_text" id="{{field.name}}_help"> -    <td colspan="3"><div>{{field.help_text}}</div></td> -  {%endif%}</tr>{% endfor %} +  {% table_form formsetform %}    {% endfor %}    <tr class='modify'><td colspan="2"><button name="formset_modify" value="{{form_step}}">{% trans "Add/Modify" %}</button></td></tr></li>  </table>  {% else %}  <table> -  {% for field in form %} -  <tr{% if field.field.required %} class='required'{% endif %}> -    <th>{{ field.label_tag }}</th> -    <td> {{ field.errors }}{{field|safe}}</td>{% if field.help_text %} -    <td><a href="#{{field.name}}" class="help_display" title="{% trans "Help"%}">?</a></td> -  </tr> -  <tr class="help_text" id="{{field.name}}_help"> -    <td colspan="3"><div>{{field.help_text}}</div></td> -  {%endif%}</tr>{% endfor %} +{% table_form form %}  </table>  {% endif %}  <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> diff --git a/ishtar/templates/form_snippet.html b/ishtar/templates/form_snippet.html new file mode 100644 index 000000000..2f841e078 --- /dev/null +++ b/ishtar/templates/form_snippet.html @@ -0,0 +1,13 @@ +{% load i18n %} +  {% if form.non_field_errors %}<tr class='errors'> +    <td colspan='3'>{{form.non_field_errors}}</td> +  </tr>{%endif%} +  {% for field in form %}{% if not field.is_hidden %} +  <tr{% if field.field.required %} class='required'{% endif %}> +    <th>{{ field.label_tag }}</th> +    <td> {{ field.errors }}{{field|safe}}</td>{% if field.help_text %} +    <td><a href="#{{field.auto_id}}" class="help_display" title="{% trans "Help"%}">?</a></td> +  </tr> +  <tr class="help_text" id="{{field.auto_id}}_help"> +    <td colspan="3"><div>{{field.help_text}}</div></td> +  {%endif%}</tr>{% else %}{{field}}{% endif %}{% endfor %} diff --git a/ishtar/templates/grid_form.html b/ishtar/templates/grid_form.html deleted file mode 100644 index 8c02197b4..000000000 --- a/ishtar/templates/grid_form.html +++ /dev/null @@ -1,10 +0,0 @@ -{% load i18n %} -  {% for field in form %} -  <tr{% if field.field.required %} class='required'{% endif %}> -    <th>{{ field.label_tag }}</th> -    <td> {{ field.errors }}{{field|safe}}</td>{% if field.help_text %} -    <td><a href="#{{field.name}}" class="help_display" title="{% trans "Help"%}">?</a></td> -  </tr> -  <tr class="help_text" id="{{field.name}}_help"> -    <td colspan="3"><div>{{field.help_text}}</div></td> -  {%endif%}</tr>{% endfor %} | 
