Thanks for that. Here's where I'm confused:

   1. In your suggested 'else' you say to get the values from the form. 
   Where do I create the form? Do I do it there (as well as in the GET 
   branch)? I'd like to create the form only one time.
   2. You say I do a form.process in the GET branch? I thought I do 
   form.process() only on a POST. Sorry for my rookie questions.
   
After some reading (and before reading your most recent post) I thought I 
should do this (comments welcome):

form = FORM(...) # don't insert any values
if form.accepts(...):
   # process request.post_vars...
   redirect(...)
elif form.errors:
   # error processing
else:
   # Pre-populate form elements
return dict(form=form)

Or am I off base here?

Thanks.

On Wednesday, October 31, 2012 6:45:36 PM UTC-6, Niphlod wrote:
>
> If you cached the values no distinction between post or get matters. you 
> fetch them one-time only. 
> If you don't want to cache them, it's another story
>
> Basic workflow
>
> - requesting values
> - form = FORM()
> - users press submit (form.process)
> - re-requesting values (your unfortunate case)
> - process the values sent by the form
>
> But, you are afraid that requesting values from db 2 times is too much 
> (sound like premature optimization, but anyway, let's go with it). 
> You did
>
> if post_vars
>       process the values sent
> else
>    fetch values
>    form = FORM()
>
> This leaves you with open doors to XSRF and double submissions (not using 
> form.process or form.accepts). 
> You can still skip the fetch part if the page has been POSTed (don't need 
> for default values at that point), so the logic goes this way
>
> if page is GETted
>     fetch values
>     form = FORM()
>     user press submit (form.process)
> else (page is POSTed)
>      don't fetch the data
>      process the values from the form
>
>

-- 



Reply via email to