Re: [web2py] simple file uploader to database as a plugin

2016-06-17 Thread Manuele Pesenti
Il 14/06/16 20:50, Vic Ding ha scritto:
> It works when I directly access the index page, however when I LOAD it
> to other pages it stops working. No ticket, no error. 
> |
> {{=LOAD('plugin_upload_file','index',args=('item',item_id),user_signature=True)}}
> |
>
>
> Any idea?

maybe it could help:
http://www.web2py.com/books/default/chapter/29/12/components-and-plugins#Ajax-post-does-not-support-multipart-forms

>From a vary fast reading I think it's just about a case like yours...

M.

-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] simple file uploader to database as a plugin

2016-06-14 Thread Vic Ding

Hi all,
I know it's 2 things in one post: how to make a file uploader as a plugin?
It should upload a file store it in the database and keep a record of the 
table and record to which it belong to (associate the uploaded file with a 
record in another table). 

model is plugin_upload_file.py

db.define_table('plugin_upload_file',
auth.signature,
Field('title', 'string'),
Field('description', 'text'),
Field('upload_file', 'upload'),
Field('table_name', 'string'),
Field('record_id', 'integer'),
format = '%(title)s'
)



I have controller/plugin_upload_file.py

def index():

table_name = request.args(0)
record_id = request.args(1, cast=long)

## pre-fill the table_name and record_id
db.plugin_upload_file.table_name.default = table_name
db.plugin_upload_file.record_id.default = record_id

plugin_upload_file_form = SQLFORM(db.plugin_upload_file).process()
if plugin_upload_file_form.accepted:
response.flash=T('File saved')
redirect(URL('index', args=(table_name, record_id)))
else:
response.flash=T('Error')

return locals()


Finally the view in view/plugin_upload_file/index.html

{{=plugin_upload_file_form}}


It works when I directly access the index page, however when I LOAD it to 
other pages it stops working. No ticket, no error. 

{{=LOAD('plugin_upload_file', 'index', args=('item', item_id), 
user_signature=True)}}



Any idea?

Thanks
Vic

-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.