I should mention this won't display validation errors in the form if you 
have any field validators -- you'd have to write additional logic to handle 
that.

Anthony

On Monday, April 1, 2013 1:26:09 PM UTC-4, Anthony wrote:
>
> You might try something like this:
>
> def upload():
>     if request.post_vars:
>         request.post_vars._formkey = SQLFORM(db.table1).process(formname=
> 'uploads').formkey
>         SQLFORM(db.table2).process(formname='uploads')
>         request.post_vars.clear()
>     form = SQLFORM.factory(db.table1, db.table2).process(formname=
> 'uploads')
>     return dict(form=form)
>
> That uses .factory() to create the HTML form, but standard SQLFORMs to 
> process the submitted data separately for each table. Note, when the 
> db.table1 form is processed, it will then overwrite the old _formkey value 
> in the session, so the new formkey has to be assigned to 
> request.post_vars._formkey before processing the db.table2 form (so it 
> matches the new formkey stored in the session). After processing, 
> request.post_vars is cleared so the files will not be re-saved when the 
> factory form is processed in the next line.
>
> Anthony
>
> On Monday, April 1, 2013 12:04:09 PM UTC-4, Lamps902 wrote:
>>
>> Just realized a possible issue. It's simple enough to rename the strings 
>> that will become the database contents form 'no_table.[whatever]' to 
>> 'table_name.[whatever]' (i.e. doing a replace() on the appropriate 
>> form.vars), but if your upload field definitions have uploadseparate = 
>> True, will this thwart the appropriate renaming of files through 
>> os.rename()* by making the file locations unpredictable when you have a 
>> large enough number of files? To remedy this, is it possible to specify 
>> what the name of the file should be before it is stored, or is there some 
>> other approach that could be taken?
>>
>> * as recommended by Anthony in this 
>> thread<https://groups.google.com/forum/#!searchin/web2py/change$20name$20of$20file/web2py/yaVPY02Z2ZU/AbOyfW0k-ZQJ>
>>
>>
>> On Monday, April 1, 2013 9:45:03 AM UTC-5, Niphlod wrote:
>>>
>>> there's no feature to leverage in the current code.....
>>> After all, a "factory" is something "ethereal" where your code needs to 
>>> manage db interactions (and whatever needs to be done).
>>>
>>> SQLFORM.factory is just a shortcut:
>>> - to "play" with your current models
>>> - to save you defining a table just to generate a form ('cause you can 
>>> pass Field() to it)
>>> - have default validators available
>>>
>>> you can't expect more "auto-magic" features out of it.... You can use 
>>> _filter_fields() to see which table belongs the input name, as long as your 
>>> input names are distinct.
>>>
>>> On Monday, April 1, 2013 4:31:47 PM UTC+2, Lamps902 wrote:
>>>>
>>>> If you have something like the following:
>>>>
>>>> form = SQLFORM.factory(db.table1, db.table2)
>>>>
>>>> and table1 has an 'upload' field named 'file1', with table2 containing 
>>>> an 'upload' field named 'file2', the filenames stored in the tables will 
>>>> end up as 'no_table.file[number].[unique_file_identifier].[extension]. The 
>>>> 'no_table' part can be changed by passing the 'tablename' argument to 
>>>> factory(), but this will not help when there are multiple uploads from 
>>>> different tables. Is there a straightforward way (i.e. by passing 
>>>> arguments 
>>>> to factory()) to make the upload file names correspond to their respective 
>>>> tables, or would that have to be handled manually? Thanks.
>>>
>>>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to