How to -- Popup window: Record already exists are you sure you want to upload file?

152 views
Skip to first unread message

LoveWeb2py

unread,
Jul 14, 2014, 1:43:22 PM7/14/14
to web...@googlegroups.com
Hello,

I want to create a popup window that lets the user click okay to continue uploading the file if it already exist in the database.

I created a separate table which tracks all the files uploaded in the database. I then append that to a list and check if the filename is in there.

My code looks like this:


def my_form_processing(form):
    fileUploadList = []
    fileToCheck = form.vars.blah.filename
    filesUploaded = db().select(db.myFileTracker.ALL)
    for line in filesUploaded:
      if line.file_name not in fileUploadList:
          fileUploadList.append(line.file_name)
      if fileToCheck in fileUploadList:
        btn = form.element('input',_type="submit)
        btn["_onclick"] = return confirm('File Already exists in database, are you sure you want to resubmit?');"


def processing():
   form = FORM(TABLE(TR(TD('upload file:', INPUT(_type='file', _name='blah')))
   if form.process(onvalidation=my_form_processing).accepted:
      response.flash = "Processed file without errors!"

the problem is it sets the element after the file uploads and i'm not sure how I can make it pop up before the file actually gets uploaded.

Appreciate any help!

Niphlod

unread,
Jul 14, 2014, 3:21:05 PM7/14/14
to web...@googlegroups.com
until the user clicks on "submit", there's no way for web2py (or you) to know the name of the file being uploaded beforehand, using a normal input type="file". it's just not how the browsers work.

Manuele Pesenti

unread,
Jul 15, 2014, 1:39:23 AM7/15/14
to web...@googlegroups.com
Il 14/07/14 21:21, Niphlod ha scritto:
> until the user clicks on "submit", there's no way for web2py (or you)
> to know the name of the file being uploaded beforehand, using a normal
> input type="file". it's just not how the browsers work.
what about to set up a javascript event on the upload like onselect and
make your check via ajax?
just a suggest
hope it could help

M.

Austin Taylor

unread,
Jul 15, 2014, 8:30:07 AM7/15/14
to web...@googlegroups.com

That might work Manuele. How would the code look?

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/F5jydKmKbeA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manuele Pesenti

unread,
Jul 15, 2014, 10:25:54 AM7/15/14
to web...@googlegroups.com
Il 15/07/14 14:29, Austin Taylor ha scritto:

That might work Manuele. How would the code look?

well... for the client side I'd start from something like that: http://jsfiddle.net/dR9tH/19/ (via http://stackoverflow.com/questions/647282/is-there-an-onselect-event-or-equivalent-for-html-select)

first of all define your web service that check for filename existence and returns a json (for example) with the needed information

cheers

    M.
Reply all
Reply to author
Forward
0 new messages