FormWizard class in django.contrib.formtools.wizard so I decided to use that. However, I immediately hit a couple of issues with it.FormWizard requires you to output the
previous_fields context variable in each of the form's step templates. Django's FormWizard previous_fields is just a string of raw HTML. If you are using some other kind of markup to do your forms e.g. XForms, or even javascript widgets from dojo or extjs, then this is no good.I quickly came up with a fix for this and opened #10557 which has now been slated to be included in Django 1.2.....
Wait a minute! Django 1.1 isn't even out yet!
The second issue was that
FormWizard didn't handle FormSets.Who knows when 1.2 will be out so I've bundled up my code and released it as
wadofstuff.django.forms 1.0.0.From the README:
Functions
security_hash(request, form, exclude=None, *args)Calculates a security hash for the given Form/FormSet instance.
This creates a list of the form field names/values in a deterministic
order, pickles the result with the SECRET_KEY setting, then takes an md5
hash of that.
Allows a list of form fields to be excluded from the hash calculation. This
is useful form fields that may have their values set programmatically.
Classes
BoundFormWizardA subclass of Django's
FormWizard that adds the following functionality:- Renders
previous_fieldsas a list of bound form fields in the template context rather than as raw html. - Can handle FormSets.
previous_fields you should change your wizard step templates from:
{{ previous_fields|safe }}
to:
{% for f in previous_fields %}{{ f.as_hidden }}{% endfor %}
The latest stable release for the forms module can be obtained by:
- Running
easy_install wadofstuff-django-forms - Downloading the 1.0.0 release and running python setup.py install.
Note: The BoundFormWizard class can only handle regular FormSets and not ModelFormSets. I have ModelFormWizard class that I'll be adding to a future release that can handle simple Models.