#16442: step not passed to get_form when using NamedUrls -------------------------+---------------------------- Reporter: guillaume@… | Owner: nobody Type: Bug | Status: new Milestone: 1.4 | Component: Forms Version: SVN | Severity: Normal Keywords: | Triage Stage: Unreviewed Has patch: 0 | Easy pickings: 1 UI/UX: 0 | -------------------------+---------------------------- 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 -- Ticket URL: <https://code.djangoproject.com/ticket/16442> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.