#21592: formset.ordered_forms should try to return ordered forms if is_valid()
is
false
-------------------------------+--------------------
Reporter: nickname123 | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------
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)
{{{
[18:57] <gp> Why does the ordered_forms property of a formset required
is_valid() to be True?
https://github.com/django/django/blob/stable/1.6.x/django/forms/formsets.py#L216
[18:58] <FunkyBob> isn't that a fundamental of the FormWizard ? you can't
progress until each 'form' is valid?
[18:59] <gp> FunkyBob: I am trying to allow users to order the forms in
the formset but I cannot output them using ordered_forms until the formset
is valid
[18:59] <gp> I don't understand why is_valid is important for outputting
the forms in an ordered fashion
[19:00] <FunkyBob> I see
[19:01] <gp> My use case is the following: I have added "add another"
function like the admin. Then I have added an "update" button that
rerenders the template. I was hoping to easily allow ordering without
javascript
[19:02] <gp> Which I can still do... that is just how I ran into this
[19:04] <gp> Well by still can do I mean I can do it if I reimplement the
ordered_forms property. Didn't know if there was a specific reason this
was only allowed for valid forms
[19:04] <gp> Or if maybe I should submit a bug/feature request
[19:05] <+bmispelon> gp: fwiw, the full test suite still passes if
self.is_valid() is removed
[19:08] <gp> Ty. I will submit a ticket and override it for my formset
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21592>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.d36780f271bf520a6ab93c38822a9b72%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.