Opened 19 years ago

Closed 17 years ago

Last modified 17 years ago

#518 closed enhancement (worksforme)

Need validators that aren't attached to a form field

Reported by: Simon Willison Owned by: Adrian Holovaty
Component: Validators Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In implementing CSRF protection (#510) I needed to add a validator to the validation chain that wasn't tied to a specific field within the manipulator. This isn't currently possible. If implemented, it would also make validation rules that depend on more than one field a lot more elegant. In fact, it would let us ditch the requirement to pass all_data to validation functions.

I think Ian Bicking's FunFormKit takes this approach.

(Personally I'd like to replace Manipulators with a more general purpose idea of Validators - collections of validation rules. At the moment Manipulators are coupled to models, but there are situations where you would want to validate a form that doesn't directly relate to a model. Validation in Rails has exactly the same problem.)

Change History (3)

comment:1 by Adrian Holovaty, 19 years ago

Correction: Manipulators are not coupled to models. It so happens that Django automatically generates manipulators *for every model*, but there's nothing about the concept of manipulators that is tied to models. Basically a manipulator is a class that encapsulates validation rules. See the manipulators in http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/views/comments.py for examples.

I agree, though, that there should be a way to add generic validators that aren't tied to a specific field.

comment:2 by Simon Willison, 19 years ago

I thoght they were coupled because of the presence of the save() method - maybe it should be renamed to something clearer, such as on_successful_submit().

comment:3 by Michael Radziej <mir@…>, 17 years ago

Resolution: worksforme
Status: newclosed

Looks like this isn't an issue anymore. If it is, please reopen.

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