I have a problem with wizard.

225 views
Skip to first unread message

Olga Burdonova

unread,
Dec 9, 2013, 8:59:46 AM12/9/13
to django...@googlegroups.com
I have a problem with wizard, no data from previous forms is stored in session backend ...
What's exactly the problem I do not understand, but as a function called

"def set_step_data(data): ....  self.data[self.step_data_key][step] = cleaned_data"

nothing is stored...

then via pdb I see that _get_data(self):  called instead of _set_data(self, value):

What could be the problem of such behavior?

Backend session is configured ... and I see certain things of wizard database contains ...

for instance:

{'_auth_user_backend': 'allauth.account.auth_backends.AuthenticationBackend', 'wizard_order_wizard': {'step_files': {u'0': {}}, 'step': u'1', 'extra_data': {}, 'step_data': {u'0': {u'csrfmiddlewaretoken': [u'xC8H5GMNDe79iC3jkYAQZUy3E11RhnDK'], u'0-number_of_credits': [u'1'], u'order_wizard-current_step': [u'0']}}}, '_auth_user_id': 1}

but not all steps stored ..

I've tried

SESSION_SAVE_EVERY_REQUEST = True

no results... (very strange behavior..)

What am I doing wrong?

Obviously "done" is not called and wizard stops in render_done

(Pdb) print self.storage.get_step_data(form_key)
None

(Pdb) form_obj.is_valid()
False

return self.render_revalidation_failure(form_key, form_obj, **kwargs)

Does anyone have any idea about this problem?

Olga Burdonova

unread,
Dec 9, 2013, 11:23:17 AM12/9/13
to django...@googlegroups.com, olgabu...@googlemail.com
More information from pdb...

> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/views.py(60)current()
-> return self._wizard.storage.current_step or self.first
(Pdb) self._wizard.storage.current_step
u'0'
(Pdb) self.first
u'0'
(Pdb) n
--Return--
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/views.py(60)current()->u'0'
-> return self._wizard.storage.current_step or self.first
(Pdb) n
--Call--
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/views.py(403)process_step()
-> def process_step(self, form):
(Pdb) n
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/views.py(408)process_step()
-> return self.get_form_step_data(form)
(Pdb) n
--Return--
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/views.py(408)process_step()-><QueryDi... [u'0']}>
-> return self.get_form_step_data(form)
(Pdb) n
--Call--
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/base.py(55)set_step_data()
-> def set_step_data(self, step, cleaned_data):
(Pdb) n
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/base.py(62)set_step_data()
-> if isinstance(cleaned_data, MultiValueDict):
(Pdb) n
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/base.py(63)set_step_data()
-> cleaned_data = dict(cleaned_data.lists())
(Pdb) n
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/base.py(64)set_step_data()
-> self.data[self.step_data_key][step] = cleaned_data
(Pdb) s
--Call--
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/session.py(11)_get_data()
-> def _get_data(self):
(Pdb) n
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/session.py(12)_get_data()
-> self.request.session.modified = True
(Pdb) n
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/session.py(13)_get_data()
-> return self.request.session[self.prefix]
(Pdb) n
--Return--
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/session.py(13)_get_data()->{'extra_data': {}, 'step': u'0', 'step_data': {}, 'step_files': {}}
-> return self.request.session[self.prefix]
(Pdb) n
--Return--
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/storage/base.py(64)set_step_data()->None
-> self.data[self.step_data_key][step] = cleaned_data
(Pdb) n
> /usr/local/lib/python2.7/dist-packages/django/contrib/formtools/wizard/views.py(285)post()
-> self.storage.set_step_files(self.steps.current, self.process_step_files(form))

Olga Burdonova

unread,
Dec 10, 2013, 8:21:57 AM12/10/13
to django...@googlegroups.com, olgabu...@googlemail.com

Solved by overwriting some methods but I still thinking about better solution.

class OrderWizard(SessionWizardView):
    template_name = "order/wizard.html"

    def get_form_key(self, step):
        return "wizard_" + self.prefix + str(step)

    def process_step(self, form):
        self.request.session[self.get_form_key(self.get_step_index())] =  self.get_form_step_data(form)

    def render_done(self, form, **kwargs):
        """
        This method gets called when all forms passed. The method should also
        re-validate all steps to prevent manipulation. If any form don't
        validate, `render_revalidation_failure` should get called.
        If everything is fine call `done`.
        """
        final_form_list = []
        # walk through the form list and try to validate the data again.
        import pdb
        pdb.set_trace()
        for form_key in self.get_form_list():
            form_obj = self.get_form(step=form_key,
                data=self.request.session[self.get_form_key(form_key)],
                files=self.storage.get_step_files(form_key))
            if not form_obj.is_valid():
                return self.render_revalidation_failure(form_key, form_obj, **kwargs)
            final_form_list.append(form_obj)

        # render the done view and reset the wizard before returning the
        # response. This is needed to prevent from rendering done with the
        # same data twice.
        done_response = self.done(final_form_list, **kwargs)
        self.storage.reset()
        return done_response



    def done(self, form_list):
        #form_data = utils.process_form_data(form_list)
        import pdb
        pdb.set_trace()
        return HttpResponseRedirect('/page-to-redirect-to-when-done/')

Olga Burdonova

unread,
Dec 10, 2013, 8:23:49 AM12/10/13
to django...@googlegroups.com, olgabu...@googlemail.com
I tested it with django 1.6 and 1.5

Rafael E. Ferrero

unread,
Dec 10, 2013, 8:33:56 AM12/10/13
to django...@googlegroups.com
Good Work !!


2013/12/10 Olga Burdonova <olgabu...@googlemail.com>
I tested it with django 1.6 and 1.5

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6fd8f358-d348-4ae6-8e51-e3b0f588a033%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Rafael E. Ferrero
Reply all
Reply to author
Forward
0 new messages