Glad to hear it.

On Mar 13, 1:48 pm, Joe  Barnhart <joe.barnh...@gmail.com> wrote:
> Thanks Massimo --
>
> I don't know what my problem was other than the view was confusing
> me.
>
> Your code works perfectly on my end as well (Python 2.5.2 on Mac
> here).  The view still reports request.var.import_csv as a
> "FieldStorage" object, but the form.accepts() processing gets
> triggered properly and the file is read.
>
> I'm a happy camper and this pattern is going into my website!  I'll
> have a link to it here soon so everyone can take a look.  It's not
> beautiful to anyone but me so far, but it makes pretty extensive use
> of web2py's DAL power.  The users of the site (high school swim
> coaches) are ecstatic to have it.
>
> Regards,
>
> -- Joe B.
>
> On Mar 13, 7:26 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > I tried this:
>
> > def import_csv():
> >     from gluon.sqlhtml import form_factory
> >     form=form_factory(SQLField('import_csv','upload'))
> >     if form.accepts(request.vars,session):
> >         request.flash='Received: %s'%request.vars.import_csv
> >         print request.vars.import_csv.filename
> >         print len(request.vars.import_csv.file.read()),'bytes'
> >     return dict(form=form)
>
> > and it works great for me. Are you using python 2.6 by any chance?
>
> > On Mar 13, 3:53 am, Joe  Barnhart <joe.barnh...@gmail.com> wrote:
>
> > > I must be doing something very wrong.  The field I get back does not
> > > seem to have any of the components it should have.
>
> > > Here is my controlller:
>
> > > def import_csv():
> > >     from gluon.sqlhtml import form_factory
> > >     form=form_factory(SQLField('import_csv','upload'))
> > >     if form.accepts(request.vars,session):
> > >         request.flash='Received: %s'%request.vars.import_csv
> > >         #do more processing here
> > >     return dict(form=form)
>
> > > And here is the view:
>
> > > {{extend 'layout.html'}}
> > > <h1>This is the meets/import_csv.html template</h1>
> > > {{=form}}
> > > {{=BEAUTIFY(request.vars.import_csv.filename if
> > > request.vars.import_csv else '')}}
>
> > > The if clause above was to see if the field contained anything under
> > > "import_csv".  It did not.
>
> > > I was trying to follow the information in the manual on page 177 but
> > > there seemed to be missing information (like the input field itself).
>
> > > I am currently using version 1.56.3.  I plan to update as soon as the
> > > current swim meet is over and I can take the site down for awhile as I
> > > work on it.
>
> > > On Mar 12, 6:15 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > you can get the file content from
>
> > > >   request.vars.my_field_name.file.read()
>
> > > > and the file name from
>
> > > >   request.vars.my_field_name.filename
>
> > > > hope this helps.
>
> > > > On Mar 12, 7:55 pm, Joe  Barnhart <joe.barnh...@gmail.com> wrote:
>
> > > > > Let me preface this by explaining that I am a noob at creating
> > > > > websites.  This is probably so simple that anyone who's been around
> > > > > the block knows the answer and is thus confused at the empty-
> > > > > headedness of my question.
>
> > > > > I wanted to take advantage of web2py's built-in handling of update
> > > > > fields -- it pops up a file chooser and allows the user to pick the
> > > > > the file to upload on his local computer.  The file is then streamed
> > > > > up to the server running web2py and usually placed in the "uploads"
> > > > > directory and linked into a database table.  In my case, rather than
> > > > > storing the file or a reference to it in a database, I wish to process
> > > > > the file immediately in the controller and store the processed
> > > > > results.
>
> > > > > I can create a form using form_factory with a single SQLField
> > > > > definition for a field of type "upload".  When I invoke this form it
> > > > > correctly displays a file chooser and lets me pick a file.  After that
> > > > > -- nothing.  The form.accepts() part of the controller is never
> > > > > triggered.  I can look at the contents of the
> > > > > request.vars.my_field_name and see that it now contains an object of
> > > > > FieldStorage, but I'm not sure what it is good for.
>
> > > > > Thank you for your patience and responses.
>
> > > > > On Mar 12, 5:23 pm, Wes James <compte...@gmail.com> wrote:
>
> > > > > > On Thu, Mar 12, 2009 at 6:20 PM, Joe Barnhart 
> > > > > > <joe.barnh...@gmail.com> wrote:
>
> > > > > > > Actually, I need to process the CSV file before it can be inserted
> > > > > > > into the database.  I was hoping to upload it to disk (or even 
> > > > > > > memory
> > > > > > > as the files are small), do the processing, and commit the 
> > > > > > > changes to
> > > > > > > db.
>
> > > > > > How about uploading it to the static files folder in web2py admin 
> > > > > > then
> > > > > > process if from there?  Not sure what you are trying to do though??
> > > > > > upload via browser or copy over via sftp? then process??
> > > > > > -wj
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to