views:

250

answers:

1

I'm having some issues with the form wizard, that maybe someone can shed some light on. According docstring in the method process_step: I can "dynamically alter self.form_list". So, based on my project needs, I'm appending forms to the form_list. The forms I'm appending contain questions and answers: http://dpaste.com/hold/152201/

The issue is that when 2 people hit the formwizard at the same time, they start to see each others questions and answers. I guess I don't understand how process_step suggests I can dynamically alter the form_list, when by doing so I'm modifying the form list of another user. Is the form_list a shared object among visitors hitting the formwizard url defined in urls.py? I've seen this issue under apache2/prefork/worker/mod_wsgi, and while running the app with runserver.

+1  A: 

How do you use FormWizard? If you're putting it in urls.py like docs says then it could be cached, i had that issue couple of times. Just put it in a view like:

def my_view(request):
    return FormWizard(request)

UPDATE: Example from real

def registration_wizard(request, template_name=None):
    rw = RegistrationWizard([RegistrationForm, 0])
    #hack formwizard to replace default template
    if template_name:
        rw.get_template = lambda x: template_name

    return rw(request)

here RegistrationWizard is a FormWizard subclass with dynamic form_list, [RegistrationForm, 0] is needed because if there's only one form at creation time, wizard won't get to form_list function. Template thing is pretty self-explanatory

Dmitry Shevchenko
Thanks for the response Dmitry. I am placing my FormWizard in urls.py. Do you have a working example of placing the FormWizard in a view? I did get your suggestion working by following the example provided at http://www.djangosnippets.org/snippets/1833/, but my problem seems to persist.
Jason Leveille
updated my answer
Dmitry Shevchenko
I'm doing my best to work through my issue. I like your suggestion (I like defining the Wizard in a view instead of urls.py), however I'm still having issues. I need to do some debugging to make sure it's not something I'm screwing up. I'll keep you updated, and hopefully put a big green checkmark next to your answer.
Jason Leveille
Just to followup with this post, I ditched trying to dynamically insert forms into the form_list. There were some architectural decisions made in the last few days that made the FormWizard approach for this part of the app not necessary anyway.
Jason Leveille
Also, Dimitry, based on what I was trying to accomplish, your suggestion didn't solve the issue I was having. I needed the "statefulness" of the cached form_list, but the form_list independence of the view approach. No matter what angle I attempted to approach my problem from, nothing seemed to work. Thanks for your help though.
Jason Leveille
well i think you just need your own implementation :) formwizard in django's core looks like abandoned project really
Dmitry Shevchenko