Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How wrap a FormWizard in a View?

How do I wrap a Django Form Wizard in a view? I need to do this so I can access request.

Does anyone have some example code for this?

like image 767
Asinox Avatar asked Dec 12 '25 07:12

Asinox


2 Answers

I probably should be just commenting on Manoj's answer, but sounds you need code

urls.py

from django.conf.urls.defaults import *
from MyApp import views

urlpatterns = patterns(
  '',
  (r'^wizard/$', views.MyWizardView ),
)

views.py

@login_required    
def MyWizardView (request):
  cw = MyWizard([WizardName, WizardQuestions, WizardProvider, WizardGoomber])
  return cw(request)
like image 127
BozoJoe Avatar answered Dec 16 '25 15:12

BozoJoe


The as_view function converts a class based view into a callable view:

from django import forms
from django.contrib.formtools.wizard.views import SessionWizardView

class Form1(forms.Form):
    a = forms.CharField()

class Form2(forms.Form):
    b = forms.CharField()

class MyWizard(SessionWizardView):
    pass

wizard_view = MyWizard.as_view([Form1, Form2])

def view(request):
    # do something fancy with the request object here
    return wizard_view(request)

This is basicly the same answer as in How to wrap a Django Form Wizard in a View?

like image 38
bikeshedder Avatar answered Dec 16 '25 14:12

bikeshedder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!