﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20569	Add cleaned_form to supersede cleaned_data	anonymous	nobody	"The cleaned_data dictionary is not very elegant:


{{{
if form.is_valid():
    subject = form.cleaned_data['subject']
}}}


First, is_valid needs to be called, and it is not obvious from the naming of the method and the fields that this is what populates cleaned_data.

Second, the ORM gives us regular fields rather than dictionary entries accessed as strings.

I suggest a cleaner interface (first iteration):


{{{
if form.is_valid():
    form.cleaning()
    subject = form.subject
    # to switch back to the original, use form.cleaning(False)
}}}


The fields could be defined as getter methods (@property), but since the form is a custom user class, it may be easier to just swap the values upon calling cleaning.

cleaning(False) is probably a rare operation.

The advantage of this is that client code is less likely to access the original data in lieu of the cleaned data.

Also, is_valid does not suggest that anything but a check occurs.  To avoid the extra call to cleaning, one could do this:


{{{
if form.validate():
    subject = form.subject
    # to switch back to the original, use form.cleaning(False)

}}}

The change would be backward compatible, as is_valid() and .cleaned_data work as before."	Cleanup/optimization	closed	Forms	dev	Normal	invalid		David Reitter	Unreviewed	0	1	1	1	1	0
