Hi,

I've already spent quite some time with the following problem which I
think should be fairly easy. I hope someone can help me.

# model
db.define_table('admin_setting',
    Field('name', 'string', notnull=True),
    Field('value', 'string', notnull=True))

in the controller I'm creating a form for various admin settings.
form = SQLFORM.factory(
        Field('invoice_logo', 'upload'), ...)

the view works well and displays all fields.

When uploading a file for the logo the file should be handled like
always (file uploaded to uploads folder, renamed to uuid filename). in
the table admin_setting I want to store the filename of the uploaded
file in a row where name='invoice_logo' (the filename should be stored
in the value field).

How can I achieve this? currently I have this code (the update is
performed later and not shown here):
if form.accepts(request.vars, formname='admin_setting_form',
dbio=False):
  if request.vars.invoice_logo != None:
    if type(request.vars.invoice_logo) != str:
      request.vars.invoice_logo_filename =
request.vars.invoice_logo.filename
      field = Field('invoice_logo', 'upload')
      # field.store fails because field does not have a _tablename
      uploaded_file = field.store(request.vars.invoice_logo.file,
request.vars.invoice_logo.filename)
    else:
       del request.vars.invoice_logo # do not delete existing logo

Reply via email to