Thursday, March 1, 2012

how to use formwizard with parametrized urls

How do I use formwizard within parametrized URLs ?

This is my urls.py

from accounts.jobs.views.wizard import JobWizardView

named_job_forms = (
('narrative', JobNarrativeForm),
('location', JobLocationForm),
('dedication', JobDedicationForm),
('preferences', JobPreferencesForm),
('notifications', JobNotificationsForm),
('promotion', JobPromotionForm),
('gallery', ListForm),
)

job_wizard = JobWizardView.as_view(named_job_forms,
url_name='job_step', done_step_name='job_wizard')

urlpatterns += patterns('accounts.jobs.views.wizard',
url(r'^wizard/(?P<job_id>\d+)/(?P<step>.+)/$', job_wizard,
name='job_step'),
url(r'^wizard/(?P<job_id>\d+)/$', job_wizard, name='job_wizard'),
)


However job_id is not passed-on by the formwizard code itself.

Shown below you can see kwargs is only given 'step' when constructing
the URL

formwizard/views.py
class NamedUrlWizardView(WizardView):
def get(self, *args, **kwargs):
"""
This renders the form or, if needed, does the http redirects.
"""
step_url = kwargs.get('step', None)
if step_url is None:
if 'reset' in self.request.GET:
self.storage.reset()
self.storage.current_step = self.steps.first
if self.request.GET:
query_string = "?%s" % self.request.GET.urlencode()
else:
query_string = ""
next_step_url = reverse(self.url_name, kwargs={
'step': self.steps.current,
}) + query_string
return redirect(next_step_url)
and continues...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment