Opened 15 years ago

Closed 15 years ago

Last modified 12 years ago

#10287 closed (fixed)

Formset documentation has no information about practical formset validation

Reported by: aidan Owned by: Andrew Badr
Component: Documentation Version: 1.0
Severity: Keywords: docs, formsets
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Although the clean method is demonstrated, no actual validation is demonstrated.

It is unclear whether self.forms should be iterated and cleaned_data examined - a property which may or may not exist.

Attachments (1)

formset-docs.diff (3.3 KB ) - added by Andrew Badr 15 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 by Jacob, 15 years ago

Owner: changed from nobody to Jacob
Status: newassigned

comment:3 by Andrew Badr, 15 years ago

Owner: changed from Jacob to Andrew Badr
Status: assignednew

by Andrew Badr, 15 years ago

Attachment: formset-docs.diff added

comment:4 by Andrew Badr, 15 years ago

Has patch: set

This patch adds a more realistic example to the formset-level clean method. It also expands the first example in the "Formset validation" section so that it matches the later example, and to better explain the contents of formset.errors.

Like several methods in the internal formset code, the example clean in this patch iterates only through the first self.total_form_count() entries in self.forms. This seems to be safer than iterating self.forms directly, because we may not use all the initial forms, or we may try to use more than max_num. If I'm wrong about this, the example clean should be changed to simply iterate through self.forms directly. That's what some other methods do, and I'm not confident that I understand the difference.

Also, my clean method accesses the forms' cleaned_data manually instead of using the formset's self.cleaned_data. This is mainly because of a comment on self.cleaned_data saying "Maybe this should just go away?", but also because self.cleaned_data iterates through self.forms, which I'm confused about (see above). If this is changed, the guard checking any(self.errors) must be kept, or else users accessing self.cleaned_data with form-level validation errors will get an uncaught exception.

comment:5 by Andrew Badr, 15 years ago

Also, this is my first documentation patch. Did my changes overstep the bounds of the ticket by too much? I'm worried that the first validation example is now a little clunky. Critique is welcome.

comment:6 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(In 11234] Fixed #10287 -- Added better examples in the docs of formset validation. Thanks to Andrew Badr for the text.

comment:7 by Russell Keith-Magee, 15 years ago

(In [11241]) [1.0.X] Fixed #10287 -- Added better examples in the docs of formset validation. Thanks to Andrew Badr for the text.

Merge of r11234 from trunk.

comment:8 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top