Massimo,

I fixed this by replacing "SQLFORM.factory" with the use of "SQLFORM" and
"dbio = False", and it works fine.
However, in case you thought it should behave differently I have copied my
code below.

The html generated by SQLFORM.factory gives the likes of id="no_table
_Attachment", even though I specify a name in the method call...

----------------------

The model has nothing out of the ordinary:

db.define_table('CAR_Report',
    Field('Complaint_Base_id', db.Complaint_Base),
    Field('From_Department', db.department, ondelete='NO ACTION'),
    Field('To_Department', db.department, ondelete='NO ACTION'),
    Field('Details', 'text', requires = IS_NOT_EMPTY()),
    Field('Suggested_Action', 'text', requires = IS_NOT_EMPTY()),
    Field('CAR_Status', requires = IS_IN_SET(
        [
        'Unassigned',
        'Assigned',
        'Actioned',
        'Reviewed and closed'
        ]), default='Unassigned'),
    Field('Assignee', db[UserTableName], ondelete='NO ACTION'),
    Field('Assignment_Comments', 'text'),
    Field('Attachment', 'upload')
    )

The controller is something like:

def raisenew():
    form = SQLFORM.factory(db.CAR_Report, fields=FieldsToDisplay,
name=db.CAR_Report)

    if form.accepts(request.vars, session):
        #Pull all the fields from the form
        FieldValues = dict()
        for f in db[TableName].fields:
            if form.vars.has_key(f):
                FieldValues[f] = form.vars[f]
        #Add a few more like so....
        FieldValues['CAR_Status'] = 'Unassigned'
        #Insert into the table...
        db.CAR_Report.insert(**FieldValues)




On Wed, Sep 1, 2010 at 2:35 PM, mdipierro <mdipie...@cs.depaul.edu> wrote:

> I need to see the code because I miss the logic. If a form is generate
> with SQLFORM.factory than there is table and no model and the uploaded
> file cannot go in the database becsause there isn't any connected to
> it.
>
> On Sep 1, 5:24 am, Andrew Buchan <andyha...@gmail.com> wrote:
> > Hello,
> >
> > I have two tables with 'file upload' fields. One is populated from a
> > form generated with SQLFORM, and the other with SQLFORM.factory.
> >
> > The file uploads in the table populated by the SQLFORM.factory form
> > cannot be downloaded, not even in appadmin, which generates hyperlinks
> > like the one below:
> >
> > <a href="/HubForms/appadmin/download/db/
> > no_table.Attachment.a2a08ab9ddf454ec.
> > 47757275204e616e616b2036303831382e706466.pdf">file</a>
> >
> > The error I get is:
> >
> > Traceback (most recent call last):
> >   File "C:\Program Files\Hub Pages\web2py\gluon\restricted.py", line
> > 178, in restricted
> >     exec ccode in environment
> >   File "C:/Program Files/Hub Pages/web2py/applications/HubForms/
> > controllers/appadmin.py", line 410, in <module>
> >   File "C:\Program Files\Hub Pages\web2py\gluon\globals.py", line 96,
> > in <lambda>
> >     self._caller = lambda f: f()
> >   File "C:/Program Files/Hub Pages/web2py/applications/HubForms/
> > controllers/appadmin.py", line 138, in download
> >     return response.download(request,db)
> >   File "C:\Program Files\Hub Pages\web2py\gluon\globals.py", line 194,
> > in download
> >     field = db[t][f]
> >   File "C:\Program Files\Hub Pages\web2py\gluon\sql.py", line 1323, in
> > __getitem__
> >     return dict.__getitem__(self, str(key))
> > KeyError: 'no_table'
> >
> > It's the "no_table" part which makes any attempt to download the file
> > fail, although the file is also called
> > "no_table.Attachment.a2a08ab9ddf454ec.
> > 47757275204e616e616b2036303831382e706466.pdf"
> >
> > The table is generated with:
> >
> > form = SQLFORM.factory(db.CAR_Report, fields=FieldsToDisplay,
> > name=db.CAR_Report)
> >
> > So the question is, how do I make SQLFORM.factory upload files storing
> > the correct table name?

Reply via email to