summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-01-03 03:18:43 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-01-03 03:18:43 +0100
commitc32287904f82f9db1090217f2cc4a36589d16d8a (patch)
tree897092dfa26b9bce6578b03a09881733e88f9da0
parent6c5de269a1b4ffa1d374c68525870978ea872543 (diff)
downloadIshtar-c32287904f82f9db1090217f2cc4a36589d16d8a.tar.bz2
Ishtar-c32287904f82f9db1090217f2cc4a36589d16d8a.zip
Change merlin-session-wizard to django-formwizard
-rw-r--r--ishtar/furnitures/forms.py68
-rw-r--r--ishtar/furnitures/urls.py12
-rw-r--r--ishtar/furnitures/views.py22
-rw-r--r--ishtar/templates/file_done.html16
-rw-r--r--ishtar/templates/file_wizard.html19
-rw-r--r--static/media/style.css11
6 files changed, 88 insertions, 60 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py
index b78a06644..08fb912a7 100644
--- a/ishtar/furnitures/forms.py
+++ b/ishtar/furnitures/forms.py
@@ -24,13 +24,15 @@ import datetime
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
-from django.template import Context
+from django.template import Context, RequestContext
from django.shortcuts import render_to_response
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
import widgets
from ishtar import settings
@@ -39,34 +41,37 @@ from django.utils.functional import lazy
reverse_lazy = lazy(reverse, unicode)
-class Step(BasicStep):
- """
- Add a label to steps
- """
- def __init__(self, idx, label, form):
- self.label = label
- super(Step, self).__init__(idx, form)
-
-class Wizard(SessionWizard):
- def process_show_form(self, request, step, form):
+class Wizard(NamedUrlSessionFormWizard):
+ def get_template_context(self, request, storage, form=None):
+ context = super(Wizard, self).get_template_context(request, storage,
+ form)
+ step = self.get_first_step(request, storage)
+ current_step = storage.get_current_step()
+ context.update({'current_step':self.form_list[current_step]})
+ if step == current_step:
+ return context
previous_steps = []
- for stp in self.base_steps:
- if stp == step:
- return Context({'previous_steps':previous_steps,
- 'current_step':stp})
- previous_steps.append(stp)
- return Context({'previous_steps':previous_steps})
+ while step:
+ if step == current_step:
+ context.update({'previous_steps':previous_steps})
+ return context
+ else:
+ previous_steps.append(self.form_list[step])
+ step = self.get_next_step(request, storage, step)
+ context.update({'previous_steps':previous_steps})
+ return context
class FileWizard(Wizard):
- def get_template(self, request, step, form):
- return ['file_wizard_%s.html' % step,
- 'file_wizard.html']
-
- def done(self, request, form_list):
- return render_to_response('done.html', {
- 'form_data': [form.cleaned_data for form in form_list],
- })
-
+ def get_template(self, request, form):
+ return ['file_wizard.html']
+
+ def done(self, request, storage, form_list):
+ return render_to_response(
+ 'file_done.html',
+ {'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'])
@@ -79,9 +84,10 @@ class FileWizard(Wizard):
else:
preventive_step = self.get_step(request, 'preventive')
self.remove_step(request, preventive_step)
-
+"""
class FileForm1(forms.Form):
+ form_label = _("General")
in_charge = forms.IntegerField(label=_("Person in charge"),
widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'),
associated_model=models.Person),
@@ -97,8 +103,8 @@ class FileForm1(forms.Form):
comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea,
required=False)
-
class FileForm2(forms.Form):
+ form_label = _("Address")
town = forms.IntegerField(label=_(u"Town"),
widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-town'),
associated_model=models.Town),
@@ -106,7 +112,9 @@ class FileForm2(forms.Form):
total_surface = forms.IntegerField(label=_("Total surface"))
address = forms.CharField(label=_(u"Address"), widget=forms.Textarea)
+
class FileForm3(forms.Form):
+ form_label = _("Preventive informations")
general_contractor = forms.IntegerField(label=_(u"General contractor"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-organization'),
@@ -118,3 +126,7 @@ class FileForm3(forms.Form):
saisine_type = forms.ChoiceField(label=_("Saisine type"),
choices=models.SaisineType.get_types())
reception_date = forms.DateField(label=_(u"Reception date"))
+
+file_creation_wizard = FileWizard([FileForm1, FileForm2, FileForm3],
+ url_name='file_creation')
+
diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py
index 5d1e0c710..aaa0d65c2 100644
--- a/ishtar/furnitures/urls.py
+++ b/ishtar/furnitures/urls.py
@@ -21,20 +21,22 @@ from django.conf.urls.defaults import *
from ishtar.urls import BASE_URL
from menus import menu
+from forms import file_creation_wizard
urlpatterns, actions = [], []
+urlpatterns = patterns('',
+ url(r'^file_creation/(?P<step>.+)$', file_creation_wizard,
+ name='file_creation'),
+ )
for section in menu.childs:
for menu_item in section.childs:
actions.append(menu_item.idx)
actions = r"|".join(actions)
urlpatterns += patterns('ishtar.furnitures.views',
- url(BASE_URL + r'(?P<action_slug>' + actions + r')/(?P<slug>[A-Za-z0-9_-]+)/' +\
- r'(?P<obj_id>\d)/$', 'action', name='action-bounded-form'),
- url(BASE_URL + r'(?P<action_slug>' + actions + r')/(?P<slug>[A-Za-z0-9_-]+)/$',
- 'action', name='action-form'),
- url(BASE_URL + r'(?P<action_slug>' + actions + r')/$', 'action', name='action'),
+ url(BASE_URL + r'(?P<action_slug>' + actions + r')/$', 'action',
+ name='action'),
url(BASE_URL + r'autocomplete-persone/$', 'autocomplete_person',
name='autocomplete-person'),
url(BASE_URL + r'autocomplete-town/$', 'autocomplete_town',
diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py
index bee8a305e..832089ea8 100644
--- a/ishtar/furnitures/views.py
+++ b/ishtar/furnitures/views.py
@@ -31,7 +31,7 @@ from django.core import serializers
from ishtar import settings
from menus import menu
-from forms import Step, FileForm1, FileForm2, FileForm3, FileWizard
+from forms import file_creation_wizard
import models
def index(request):
@@ -111,31 +111,11 @@ def action(request, action_slug, obj_id=None, *args, **kwargs):
associated_wizard = action_slug + '_wizard'
dct = {}
globals_dct = globals()
- if associated_wizard in globals_dct:
- wizard = globals_dct[associated_wizard]
- if ('slug' not in kwargs or not kwargs['slug']):
- current_step = None
- if wizard.id in request.session \
- and 'current_step' in request.session[wizard.id] \
- and request.session[wizard.id]['current_step']:
- current_step = request.session[wizard.id]['current_step'].slug
- else:
- current_step = wizard.base_steps[0].slug
- return redirect('action-form', action_slug, current_step)
- elif wizard.id in request.session:
- for step in wizard.base_steps:
- if step.slug == kwargs['slug']:
- request.session[wizard.id]['current_step'] = step
if action_slug in globals_dct:
return globals_dct[action_slug](request, dct, obj_id, *args, **kwargs)
return render_to_response('index.html', dct,
context_instance=RequestContext(request))
-file_creation_wizard = FileWizard([
- Step('general', _(u"General"), FileForm1),
- Step('localisation', _(u"Localisation"), FileForm2),
- Step('preventive', _(u"Preventive informations"), FileForm3)])
-
def file_creation(request, dct, obj_id, *args, **kwargs):
return file_creation_wizard(request, *args, **kwargs)
diff --git a/ishtar/templates/file_done.html b/ishtar/templates/file_done.html
new file mode 100644
index 000000000..6bbeb53d4
--- /dev/null
+++ b/ishtar/templates/file_done.html
@@ -0,0 +1,16 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% block content %}
+<ul id='form_path'>
+{% for step in previous_steps %}
+ <li>&raquo; <a href='?form_prev_step={{forloop.counter0}}'>{{step.form_label}}</a></li>
+{% endfor %}
+ <li class='current'>&raquo; <a href='#'>{{current_step.form_label}}</a></li>
+</ul>
+<div class='form'>
+<pre>
+{{ form_list|pprint }}
+</pre>
+</form>
+</div>
+{% endblock %}
diff --git a/ishtar/templates/file_wizard.html b/ishtar/templates/file_wizard.html
index 4bb6a59c8..9ebf4adb3 100644
--- a/ishtar/templates/file_wizard.html
+++ b/ishtar/templates/file_wizard.html
@@ -2,20 +2,27 @@
{% load i18n %}
{% load range %}
{% block content %}
+<form action="." method="post">{% csrf_token %}
<ul id='form_path'>
-{% for step in extra_context.previous_steps %}
- <li>&raquo; <a href='{%url action-form CURRENT_ACTION step.slug%}'>{{step.label}}</a></li>
+{% for step in previous_steps %}
+ <li>&raquo; <button name="form_prev_step" value="{{forloop.counter0}}">{{step.form_label}}</button></li>
{% endfor %}
- <li class='current'>&raquo; <a href='{%url action-form CURRENT_ACTION extra_context.current_step.slug%}'>{{extra_context.current_step.label}}</a></li>
+ <li class='current'>&raquo; <a href='#'>{{current_step.form_label}}</a></li>
</ul>
<div class='form'>
-<form action="." method="post">{% csrf_token %}
<table>
-{{ form }}
+{% if form.forms %}
+ {{ form.management_form }}
+ {% for formsetform in form.forms %}
+ {{ formsetform.as_table }}
+ {% endfor %}
+{% else %}
+ {{ form.as_table }}
+{% endif %}
</table>
<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
{{ previous_fields|safe }}
<input type="submit" value="{% trans "Validate" %}"/>
-</form>
</div>
+</form>
{% endblock %}
diff --git a/static/media/style.css b/static/media/style.css
index 5caaa1353..47f30b2ee 100644
--- a/static/media/style.css
+++ b/static/media/style.css
@@ -13,6 +13,17 @@ a {
color:#D14;
}
+button {
+ text-decoration:none;
+ color:#D14;
+ border:none;
+ background-color:white;
+ font-size: 11pt;
+ cursor:pointer;
+ padding:0;
+ margin:0;
+}
+
caption {
color:#922;
font-weight:bold;