Question

today I've started using Form Wizard in django 1.4. The functionality seems to be nice, but according to the documentation, one need to pass the form_list (and condition_dict, when necessary) to the as_view method (which means urls.py) instead of providing it in the subclass of WizardView

This means writing some logics within urls.py and not views.py which I believe is against django pattern, as the views module is supposed to be responsible for views logics.

I've ended up with following:

# views.py
class MyWizard(SessionWizardView):
    _form_list = (
        ('init', forms.MyWizardFormInit), 
        ('newuser', forms.MyWizardFormNewUser),
    )
    _condition_dict = {
        'newuser': lambda wizard: (wizard.get_cleaned_data_for_step('init') or {}).get('existing_user') == 'False'
    }

and the urls.py:

url(.., MyWizard.as_view(MyWizard._form_list, condition_dict = MyWizard._condition_dict)),

which really looks silly and ridiculous. Is there any correct way to prevent declaring logics in urls.py while keeping DRY ?

Was it helpful?

Solution

A slightly cleaner version might look like this:

views.py

my_wizard_view = MyWizard.as_view(MyWizard._form_list, condition_dict=MyWizard._condition_dict))

urls.py

url(r'^my_wizard/$', my_wizard_view, name='my_wizard')

OTHER TIPS

I haven't used WizardWiev yet, but have you tried setting those attributes on the WizardView subclass itself instead of passing them through the url definition? Or, filing that, have you tried overloading the WizardView.get_form method?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top