Skip to content

Commit

Permalink
Updated test apps to work with the new WizardViews.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephrdev committed Jun 5, 2011
1 parent d04f8d7 commit 54ce1f9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 47 deletions.
2 changes: 1 addition & 1 deletion test_project/templates/testapp/done.html
Expand Up @@ -3,7 +3,7 @@
<title>Feedback Done</title>
</head>
<body>
<h1>We want got your feedback!</h1>
<h1>We got your feedback!</h1>
<pre>{{ form_list|pprint }}</pre>
</body>
</html>
4 changes: 2 additions & 2 deletions test_project/templates/testapp/form.html
Expand Up @@ -5,7 +5,7 @@
<body>
<h1>We want your feedback!</h1>
<form action="." method="post">
{% include "formwizard/wizard.html" %}
{% include "formwizard/wizard_form.html" %}
</form>
</body>
</html>
</html>
17 changes: 0 additions & 17 deletions test_project/testapp/forms.py
@@ -1,8 +1,5 @@
from django import forms
from django.template import RequestContext
from django.shortcuts import render_to_response

from formwizard.forms import SessionFormWizard

class FeedbackStep1(forms.Form):
name = forms.CharField()
Expand All @@ -16,17 +13,3 @@ class FeedbackStep2(forms.Form):

class FeedbackStep3(forms.Form):
message = forms.CharField(widget=forms.Textarea())

class FeedbackWizard(SessionFormWizard):
def done(self, request, storage, form_list):
return render_to_response(
'testapp/done.html',
{'form_list': [form.cleaned_data for form in form_list]},
context_instance=RequestContext(request)
)

def get_template(self, request, storage):
return ['testapp/form.html',]

feedback_form_instance = FeedbackWizard([FeedbackStep1, FeedbackStep2, \
FeedbackStep3])
8 changes: 5 additions & 3 deletions test_project/testapp/urls.py
@@ -1,6 +1,8 @@
from django.conf.urls.defaults import *
from test_project.testapp.forms import feedback_form_instance

from testapp.views import feedback_wizard


urlpatterns = patterns('',
url(r'^$', feedback_form_instance, name='feedback_wizard'),
)
url(r'^$', feedback_wizard, name='feedback_wizard'),
)
20 changes: 20 additions & 0 deletions test_project/testapp/views.py
@@ -0,0 +1,20 @@
from django.shortcuts import render_to_response
from django.template import RequestContext

from formwizard.views import SessionWizardView

from testapp.forms import FeedbackStep1, FeedbackStep2, FeedbackStep3


class FeedbackWizard(SessionWizardView):
template_name = 'testapp/form.html'

def done(self, form_list, *args, **kwargs):
return render_to_response(
'testapp/done.html',
{'form_list': [form.cleaned_data for form in form_list]},
context_instance=RequestContext(self.request)
)

feedback_wizard = FeedbackWizard.as_view(
[FeedbackStep1, FeedbackStep2, FeedbackStep3])
21 changes: 0 additions & 21 deletions test_project/testapp2/forms.py
@@ -1,8 +1,5 @@
from django import forms
from django.template import RequestContext
from django.shortcuts import render_to_response

from formwizard.forms import SessionFormWizard

class FeedbackStep1(forms.Form):
name = forms.CharField()
Expand All @@ -17,21 +14,3 @@ class FeedbackStep2(forms.Form):

class FeedbackStep3(forms.Form):
message = forms.CharField(widget=forms.Textarea())

class FeedbackWizard(SessionFormWizard):
def done(self, request, storage, form_list):
return render_to_response(
'testapp/done.html',
{'form_list': [form.cleaned_data for form in form_list]},
context_instance=RequestContext(request)
)

def get_template(self, request, storage):
return ['testapp/form.html',]

feedback_form_instance = FeedbackWizard(
[FeedbackStep1, FeedbackStep2, FeedbackStep3],
condition_list={
'2': lambda w, r, s: (w.get_cleaned_data_for_step(r, s, '1') or {}).get('leave_message', True)
}
)
6 changes: 3 additions & 3 deletions test_project/testapp2/urls.py
@@ -1,6 +1,6 @@
from django.conf.urls.defaults import *
from test_project.testapp2.forms import feedback_form_instance
from testapp2.views import feedback_wizard

urlpatterns = patterns('',
url(r'^$', feedback_form_instance, name='feedback_wizard2'),
)
url(r'^$', feedback_wizard, name='feedback_wizard2'),
)
25 changes: 25 additions & 0 deletions test_project/testapp2/views.py
@@ -0,0 +1,25 @@
from django.shortcuts import render_to_response
from django.template import RequestContext

from formwizard.views import SessionWizardView

from testapp2.forms import FeedbackStep1, FeedbackStep2, FeedbackStep3


class FeedbackWizard(SessionWizardView):
template_name = 'testapp/form.html'

def done(self, form_list, *args, **kwargs):
return render_to_response(
'testapp/done.html',
{'form_list': [form.cleaned_data for form in form_list]},
context_instance=RequestContext(self.request)
)

def message_condition(wizard):
data = wizard.get_cleaned_data_for_step('1') or {}
return data.get('leave_message', True)

feedback_wizard = FeedbackWizard.as_view(
[FeedbackStep1, FeedbackStep2, FeedbackStep3],
condition_dict={'2': message_condition})

0 comments on commit 54ce1f9

Please sign in to comment.