﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16442	step not passed to get_form when using NamedUrls	guillaume@…	nobody	"Hi,

I have noticed in the code of NamedUrlWizardView that you don't pass the step name to get_form.

I think it should pass it as else the only we have to know what step we are in is to use self.steps.current, which can bring some bugs. For example in my use case for the same step I need to customize get_form and get_form_initial. But in my get_form_initial I need to use get_form with data parameter to retrieve a previous form data to generate my new form. If I use self.steps.current it would bring a recursive loop.

Here is a piece of code that show the problem:

{{{#!python
class wizard(SessionWizardView, NamedUrlSessionWizardView):

    def _calc_attributes(self):
        sale_form = self.get_form(step=self.STEP_PRODUCT, data=self.storage.data['step_data'][self.STEP_PRODUCT])
        sale = sale_form.save(commit=False)
        self.common_attributes = CommonAttribute.objects.filter(for_type=sale.type)

    def get_form_initial(self, step):
        if step == self.steps.current
            self._calc_attributes()
            initials = []
            # add stuff in initials
            return initials
        return super(SaleWizard, self).get_form_initial(step)

    def get_form(self, step=None, data=None, files=None):
        if step == self.steps.current:
            self._calc_attributes()
            formset = inlineformset_factory(Sale, ProductStock, can_delete=True,
                                         extra=self.attributes_len,
                                         formset=BaseStockFormSet)
            kwargs = self.get_form_kwargs(step)
            kwargs.update({
                'data': data,
                'files': files,
                'prefix': self.get_form_prefix(step, self.form_list[step]),
                'initial': self.get_form_initial(step),
            })
            return formset(**kwargs)
        return super(SaleWizard, self).get_form(step, data, files)

}}}


Would be great if it could be fixed!

Thanks
"	Bug	closed	Forms	dev	Normal	invalid			Unreviewed	1	0	0	0	1	0
