>
>  My experience in web-type applications is of the 'single purpose code' 
>
type: one method assembles the data for the web page, from a database or 
> some default values etc., and then 'returns' it to the web client; then an 
> entirely separate method is the target for the subsequent HTML form 
> submission, it receives the data and creates the necessary data structure 
> (object or whatever) and populates it from the data on the POST, stores it 
> in the DB etc. This has a complete separation of functions. 
> And to some extent it is this lack of a clean separation that I find a 
> problem in the self-submission case, perhaps more philosophically than 
> practically, I'll agree.
>

First, note that having the same action handle both form creation and form 
processing does not imply a lack of separation. You can still have 
different code paths and even entirely separate functions that handle 
different parts of the process, even if the same URL handles both cases.

Second, as already mentioned, there is some common code used for creation 
and processing, so self-submission helps to reduce code duplication as well 
as the use of redirects if you need to display validation errors or re-load 
a new blank form after a successful submission.

Third, nothing is forcing you to use the self-submission pattern if you 
really don't like it. For example, see 
http://web2py.com/books/default/chapter/29/07/forms-and-validators#Sharing-forms.

but are you suggesting that it is better to populate the db.tablename 
> object's defaults before the 'form=SQLFORM(...' statement ? 
>

Specifically when using SQLFORM (which pre-populates fields based on the 
db.tablename field default values).
 

> if request.post_vars == None: 
>         # 
>         # put pre-population data acquisition here 
>         # including calls to other methods - if lengthy code 
>         # 
> form = SQLFORM(... 
>

Yes, something along those lines.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to