summaryrefslogtreecommitdiff
path: root/ishtar/furnitures/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar/furnitures/forms.py')
-rw-r--r--ishtar/furnitures/forms.py41
1 files changed, 17 insertions, 24 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py
index 3732bd528..de221da70 100644
--- a/ishtar/furnitures/forms.py
+++ b/ishtar/furnitures/forms.py
@@ -26,11 +26,9 @@ from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.template import Context, RequestContext
from django.shortcuts import render_to_response
+from django.forms.formsets import formset_factory
from django import forms
-from merlin.wizards.utils import Step as BasicStep
-from merlin.wizards.session import SessionWizard
-
from formwizard.forms import NamedUrlSessionFormWizard
import models
@@ -43,10 +41,13 @@ reverse_lazy = lazy(reverse, unicode)
class Wizard(NamedUrlSessionFormWizard):
def get_template_context(self, request, storage, form=None):
+ """
+ Add previous and current steps to manage the wizard path
+ """
context = super(Wizard, self).get_template_context(request, storage,
form)
step = self.get_first_step(request, storage)
- current_step = storage.get_current_step()
+ current_step = storage.get_current_step() or '0'
context.update({'current_step':self.form_list[current_step]})
if step == current_step:
return context
@@ -71,20 +72,6 @@ class FileWizard(Wizard):
{'form_list': [form.cleaned_data for form in form_list]},
context_instance=RequestContext(request)
)
- """
- def process_step(self, request, step, form):
- if models.PREVENTIVE and 'file_type' in form.cleaned_data:
- file_type = int(form.cleaned_data['file_type'])
- if file_type == models.PREVENTIVE:
- preventive_step = Step('preventive',
- _(u"Preventive informations"), FileForm3)
- localisation_step = self.get_step(request, 'localisation')
- self.insert_after(request, localisation_step,
- preventive_step)
- else:
- preventive_step = self.get_step(request, 'preventive')
- self.remove_step(request, preventive_step)
-"""
class FileForm1(forms.Form):
form_label = _("General")
@@ -105,13 +92,19 @@ class FileForm1(forms.Form):
class FileForm2(forms.Form):
form_label = _("Address")
- town = forms.IntegerField(label=_(u"Town"),
- widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-town'),
- associated_model=models.Town),
- validators=[models.Town.valid_id])
total_surface = forms.IntegerField(label=_("Total surface"))
address = forms.CharField(label=_(u"Address"), widget=forms.Textarea)
+class TownForm(forms.Form):
+ form_label = _("Towns")
+ # !FIXME hard_link, reverse_lazy doen't seem to work with formsets
+ town = forms.IntegerField(label=_(u"Town"),
+ widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
+ 'autocomplete-town', associated_model=models.Town),
+ validators=[models.Town.valid_id])
+
+TownFormSet = formset_factory(TownForm)
+TownFormSet.form_label = _("Towns")
class FileForm3(forms.Form):
form_label = _("Preventive informations")
@@ -140,6 +133,6 @@ def is_preventive(self, request, storage):
except ValueError:
return False
-file_creation_wizard = FileWizard([FileForm1, FileForm2, FileForm3],
- url_name='file_creation', condition_list={'2':is_preventive})
+file_creation_wizard = FileWizard([FileForm1, FileForm2, TownFormSet, FileForm3],
+ url_name='file_creation', condition_list={'3':is_preventive})