On 12/01/11 17:54, Daniel Swarbrick wrote:
> Most of the time, I use POST for forms, but using GET is useful when
> developing a search form, for example. This is especially true if you
> want to paginate your results, because you still have all your
> original form variables in the query string.
>
> CBV FormView get_form_kwargs() only populates form_kwargs data if the
> request is POST or PUT, which means that a GET form will never have
> form.is_valid() == True, even thought the supplied query string may
> indeed validate all form fields.
>
> Is this by design, or an oversight?

This is, at least in my view, by design - it's good web behaviour to not
use GET to modify data, or otherwise do things that forms usually end up
doing.

> I'm working around this for now by overriding get_form_kwargs() in my
> view like so:
>
>     def get_form_kwargs(self):
>         kwargs = {'initial': self.get_initial()}
>         if self.request.GET:
>             kwargs['data'] = self.request.GET
>         return kwargs

This is the point about class-based views - you can just add that as a
Mixin or a new base class, and get the functionality on the views you want.

I'm -1 on the generic views accepting GET for form submissions, for the
GET-modifying-data-is-bad reasons above. That doesn't, however, stop you
from using it as a mixin, and if you find any design issues with mixing
in new behaviours, I'll be more than happy to take a look...

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to