Does pylons populate the request object when @validate kicks in

1 view
Skip to first unread message

afrotypa

unread,
Jun 24, 2009, 12:06:54 PM6/24/09
to pylons-devel
Hi,

I had a question about how @validate works

Say you have /controller/edit

which returns a form in a rendered template whose action is /
controller/save

As well the save action has an @validate decorator associated with
edits submitted form i.e. :-

@restrict('POST')
@validate(schema=TestSchema(), form='edit', post_only=False,
on_get=True)
def save(self, id=None):

If TestSchema fails to validate when @validate kicks in, this results
in edit being called (this looks like a method call not an HTTP get)
to re-generate the form for htmlfill to render with errors. This is
all fine an dandy if the select fields for the re-generated form have
the same options as when the form was initially generated and thus
there is no need to change the forms select field options.

However if regenerating the form requires a different set of select
options (which are dependent on the current select fields values
submitted in the original request), then the 2nd call to 'edit' will
need access to the request parameters in order to intelligently
regenerate the form. It appears request.params does not contain the
request parameters in this case. I was only able to obtain the current
form values in this case by doing something like this :-

params=dict(request.environ.get('webob._parsed_post_vars')[0])

This however does not look elegant and that variable is not guaranteed
to remain a part of the api in future webob versions.

Does anyone have an idea about how to handle this issue?

afrotypa

unread,
Jun 30, 2009, 3:37:23 AM6/30/09
to pylons-devel
Sorry, I created 2 threads of discussion on the same subject. Please
lets continue the discussion here :-

http://groups.google.ca/group/pylons-discuss/t/a70e07e1a0a4e8e7
Reply all
Reply to author
Forward
0 new messages