﻿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
21590	Don't require forms clean_* methods to return a value	Aymeric Augustin	nobody	"Adding custom validation to forms isn't as DRY as it colud be:

{{{
    class MyForm(forms.ModelForm):

        class Meta:
            model = MyModel

        def clean_title(self):
            title = self.cleaned_data[""title""]
            validate_title(title)  # custom validation
            return title

        def clean_slug(self):
            slug = self.cleaned_data[""slug""]
            validate_slug(slug)   # custom validation
            return slug
}}}

The requirement that `clean()` return a `cleaned_data` dict was recently lifted; what about doing the same for `clean_*()`? Then the example above could be simplified to:

{{{
    class MyForm(forms.ModelForm):

        class Meta:
            model = MyModel

        def clean_title(self):
            validate_title(self.cleaned_data[""title""])  # custom validation

        def clean_slug(self):
            validate_slug(self.cleaned_data[""slug""])   # custom validation
}}}

Otherwise developers go for private APIs, eg.:

{{{
    class MyForm(forms.ModelForm):

        class Meta:
            model = MyModel

        def __init__(self, *args, **kwargs):
            super(MyForm, self).__init__(*args, **kwargs)
            self.fields[""title""].validators.append(validate_title)
            self.fields[""slug""].validators.append(validate_slug)
}}}
"	Cleanup/optimization	closed	Forms	dev	Normal	invalid			Unreviewed	0	0	0	0	0	0
