[Django] #26259: Form.cleaned_data should be a property

3 views
Skip to first unread message

Django

unread,
Feb 22, 2016, 9:26:35 AM2/22/16
to django-...@googlegroups.com
#26259: Form.cleaned_data should be a property
-------------------------------+--------------------
Reporter: guettli | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
We stumbled over this code:

{{{
form.is_valid()
if form.cleaned_data.get('cancel'):
...
}}}
We did not understand why `form.is_valid()` is necessary.

It seems that `form.cleaned_data` is not a property, you need to call
`is_valid()` first.

It would be nice if `Form.cleaned_data` is be a property, this way the
following code would just work:

{{{
if form.cleaned_data.get('cancel'):
...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26259>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 22, 2016, 10:17:34 AM2/22/16
to django-...@googlegroups.com
#26259: Form.cleaned_data should call is_valid() if necessary
-----------------------------+--------------------------------------
Reporter: guettli | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 1.9
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => wontfix
* component: Uncategorized => Forms
* needs_tests: => 0
* needs_better_patch: => 0
* needs_docs: => 0
* type: Uncategorized => New feature


Comment:

I don't think an implicit call to `is_valid()` is a good idea. Most of the
time, you do want different handling for valid and invalid forms. Of
course, you could write your own subclass of `Form` which has the behavior
you desire.

Feel free to raise the idea on the DevelopersMailingList for other
opinions.

--
Ticket URL: <https://code.djangoproject.com/ticket/26259#comment:1>

Reply all
Reply to author
Forward
0 new messages