Should the first call in SearchForm be self.full_clean() instead of self.clean() ?

13 views
Skip to first unread message

@@

unread,
Nov 29, 2009, 9:07:48 AM11/29/09
to django-...@googlegroups.com
Not sure if call self.clean() is intended, but this does not make much sense to me :)
Since self.clean() only return cleaned_data but the returned value was not saved.
Thanks.

Daniel Lindsley

unread,
Dec 1, 2009, 1:00:20 AM12/1/09
to django-...@googlegroups.com
Askfor,


The only goal there was to cause the form to clean the data first.
I had thought that using ``.clean()`` would be enough but when I look
at Django's ``Form`` implementation, I'm not sure why that was. The
better choice here, I think, would be to alter the code to use ``if
self.is_valid()``, just like you would do in a view, which will
automatically do both the ``.full_clean()`` and ``.clean()`` as well
as staying closer to the typical way ``Forms`` are used. I don't think
this would be backward incompatible, though I'm open to hearing if
people feel otherwise.


Daniel
> --
>
> You received this message because you are subscribed to the Google Groups
> "django-haystack" group.
> To post to this group, send email to django-...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-haysta...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-haystack?hl=en.
>

@@

unread,
Dec 1, 2009, 1:28:06 AM12/1/09
to django-...@googlegroups.com
On Tue, Dec 1, 2009 at 2:00 PM, Daniel Lindsley <pola...@gmail.com> wrote:
  The only goal there was to cause the form to clean the data first.
I had thought that using ``.clean()`` would be enough but when I look
at Django's ``Form`` implementation, I'm not sure why that was. The
better choice here, I think, would be to alter the code to use ``if
self.is_valid()``, just like you would do in a view, which will
automatically do both the ``.full_clean()`` and ``.clean()`` as well
as staying closer to the typical way ``Forms`` are used. I don't think
this would be backward incompatible, though I'm open to hearing if
people feel otherwise.

Hi, 
I think there problem here is that if a bound form is not validated ( for example form.full_clean() or form.is_valid() ), then the form.cleaned_data is not exist, even form.clean() is called, so when try go get the search words like this self.cleaned_data['q'] will rise an exception.
If the form is validated, that means clean() is executed. execute it again would be not necessary.

is_valid is basically  equal to full_clean except is_valid will only call full_clean once, so i think this is better :)
Reply all
Reply to author
Forward
0 new messages