Back to business after almost 2 months i try again to use sqlform.factory
to create and edit documents
My problem was to generate the link
i rearranged my code as follows
#if edit a document
if request.args(0):
row=db((db.trabalhador.id==request.args(0))).select().first()
empresa=row.empresa
foto=row['foto'] or None
#print foto
if row:
for field in row:
if field in db.trabalhador.fields:
#POPULATE FIELDS with record to edit
db.trabalhador[field].default=row[field]
form=SQLFORM.factory(db.trabalhador,db.t_docs,
submit_button="Gravar",
fields=['nome','bi','ncart','ncartval','rfid','apt_medica','apt_medicaval','val_formacao','f_doc'],
table_name='trabalhador',
upload=URL('download')
)
I see my record and upload fields with [file] link. The [file] link
downloads my uploaded file.
My upload fields have required= true in db.py!!!
I do nothing and just press save
I get the error saying that i have to select a file to my upload field.
I´m stuck
Help please.....
2013/1/24 Anthony <[email protected]>
> I think it should work with factory -- haven't tried it.
>
> Anthony
>
>
> On Thursday, January 24, 2013 12:26:03 PM UTC-5, Ramos wrote:
>
>> All of this can be used with SQLFORM.FACTORY?
>> or do i have to use just SQLFORM?
>>
>>
>>
>>
>> 2013/1/24 Anthony <[email protected]>
>>
>> *1 - You can either pass a record (or a dict or Storage object whose
>>>> keys are the same as the field names in your tables) to SQLFORM and let it
>>>> fill in all the field values for you (including creating the link for the
>>>> upload field)*
>>>> *How does a SQLFORM create the link for the upload field when editing
>>>> a record?*
>>>>
>>>
>>> It passes the filename (from the record) and the download URL (from the
>>> "upload" argument) to the UploadWidget, which automatically adds the link.
>>> See
>>> here<http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#1057>,
>>> here<http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#1089>,
>>> and
>>> here<http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#556>.
>>> I think the record object you pass in must have items for all the fields in
>>> the form (i.e., for both tables).
>>>
>>>
>>>>
>>>> 2 *or you can create a custom widget for the db field and embed the
>>>> link to the file in the widget*
>>>> *How to?*
>>>>
>>>
>>> See
>>> http://web2py.com/books/**default/chapter/29/07#Widgets<http://web2py.com/books/default/chapter/29/07#Widgets>
>>>
>>> Anthony
>>>
>>> --
>>>
>>>
>>>
>>>
>>
>> --
>
>
>
>
--
---
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.