A problem with a solution, but is it the right one?

35 views
Skip to first unread message

Jeff Heard

unread,
Jan 18, 2012, 2:42:12 PM1/18/12
to django...@googlegroups.com
My basic problem is this: I have multiple kinds of requests that come in, and some of them share parameters and valid values and default values. I cannot expect my users to pass all form values on the URL line, but unpassed parameters must be set to appropriate defaults, not merely None.  

These shared parameter sets are broken out into separate RequestForm classes, but I also wanted to put the parsing and default values into those classes. So I came up with the "from_request" method, which I put into each RequestForm subclass and created a class method called "create" in RequestForm that class every class in cls.mro()'s from_request method independently, then calls .clean() on the form to validate it.

Another caveat is that I must shadow the request.GET dictionary with a case-insensitive dictionary, which I take care of in the django.views.generic.View.dispatch() method.

The code for my proposed solution is here:  


Does this make sense to people?  Sorry to kind of flood the list with this problem all day in different forms, but i think I'm close to having something I like.

-- Jeff


francescortiz

unread,
Jan 20, 2012, 7:30:26 AM1/20/12
to Django users
I would pass bound data instead of calling from_request:
https://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api-bound-unbound

This way you don't have to worry about forms logic, but just about
filling the default data.

Francesc

Jeff Heard

unread,
Jan 20, 2012, 8:47:51 AM1/20/12
to django...@googlegroups.com
Yeah, I started doing that after I posted...  Thanks for the advice.  I'll be posting this code up on GitHub in a few days, as it's part of a reasonably complete implementation for Django of ISO 19142, Open Geospatial Consortium's Web Feature Service.  

-- Jeff

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


Derek

unread,
Jan 24, 2012, 2:46:02 AM1/24/12
to Django users
That sounds very interesting, Jeff - please post the link here.

On Jan 20, 3:47 pm, Jeff Heard <jefferson.r.he...@gmail.com> wrote:
> Yeah, I started doing that after I posted...  Thanks for the advice.  I'll
> be posting this code up on GitHub in a few days, as it's part of a
> reasonably complete implementation for Django of ISO 19142, Open Geospatial
> Consortium's Web Feature Service.
>
> -- Jeff
>
> On Fri, Jan 20, 2012 at 7:30 AM, francescortiz <francescor...@gmail.com>wrote:
>
>
>
>
>
>
>
> > I would pass bound data instead of calling from_request:
>
> >https://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api-bo...
Reply all
Reply to author
Forward
0 new messages