The workflow is ambiguous. You are not editing a record therefore it is not
clear whether an empty submission means you want to keep or remove the
default.
It thinks you want to remove it.
If you want to keep it, still, it is not a proper default for the input
(since it is no a fieldstorage to be processed). You can do (for now):
def tab1():
if request.args(0):
print "editing record"
row=db(db.tab1.id==request.args(0)).select()[0]
db.tab1['f1'].default = row.f1
db.tab1['f2'].default = row.f2
form=SQLFORM.factory(db.tab1,upload=URL('download'))
if form.process():
if 'f2 in form.errors: del form.errors['f2']
if not form.errors:
form.vars['f2'] = db.tab1['f2'].default
print "updating or creating record"
return dict(form=form)
On Monday, 8 April 2013 04:44:36 UTC-5, Ramos wrote:
>
> Hello
>
> my db.py
>
> db.define_table('tab1',
> Field('f1'),
>
> Field('f2','upload',uploadfolder=os.path.join(request.folder,'uploads'))
> )
> db.tab1.f2.requires=IS_NOT_EMPTY()
>
> my controller
> def tab1():
> if request.args(0):
> print "editing record"
> row=db(db.tab1.id==request.args(0)).select()[0]
> db.tab1['f1'].default = row.f1
> db.tab1['f2'].default = row.f2
> form=SQLFORM.factory(db.tab1,upload=URL('download'))
> if form.process().accepted: #update or create
> print "updating or creating record"
> return dict(form=form)
> first i create a record with some text in f1 and a file in f2.
> then i edit this record with myapp/default/tab1/*1*
> If i submit without changing f1 or f2 field, i get the error about field
> f2 not having a file to upload.
>
>
> Can someone help me to understand how to edit a record with
> sqlform.factory and upload fields?
>
> *This is just a demo of my problem. *
> *In my project i´m using sqlform.factory to edit records from more than
> one table.*
>
> Thank you
> António
>
--
---
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.