formset.ordered_forms should try to return ordered forms if is_valid() is false
|Reported by:||nickname123||Owned by:||pjrharley|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I am not sure if this should be a bug report or a feature request.
I think that formset.ordered_forms should be usable even if the formset is invalid. This is particularly useful in conjunction with Form Wizard for me, but I think there are plenty of other cases where this would be nice.
See https://github.com/django/django/blob/stable/1.6.x/django/forms/formsets.py#L216 where is_valid() == False causes an AttributeError
It would be useful for rendering templates. The particular data I am working is much easier to understand if it is displayed in order.
I was attempting to allow ordering the forms without moving to the next step in a form wizard. So I overrode the formset is_valid method like below with the intentions that the user could post ordering without moving to the next step:
class BaseOrderFormSet(BaseFormSet): """ THIS FORMSET RETURNS INVALID IF THE USER SUBMITTED A REQUEST TO ADD ADDITIONAL FORMS OR UPDATE THE FORMSET INSTEAD OF ACTUALLY SUBMITTING THE DATA FOR SAVING """ can_add_form = True can_update_formset = True def is_valid(self): # do not validate if we need to add another row return not ADD_FORM_KEY in self.data and not UPDATE_FORMSET_KEY in self.data and super(BaseOrderFormSet, self).is_valid()
(note FunkyBob's first comment seems out of context because we were having a conversation in django-users first but it wasn't relevant enough to the ticket to copy over and it spanned a lot of other comments)
Change History (6)
Changed 3 months ago by nickname123
comment:1 Changed 3 months ago by nickname123
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 3 months ago by pjrharley
- Has patch set
- Owner changed from nobody to pjrharley
- Status changed from new to assigned
- Triage Stage changed from Unreviewed to Accepted