summaryrefslogtreecommitdiff
path: root/addons/web/controllers/main.py
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2019-11-22 11:37:09 +0000
committerJulien Mougenot <jum@odoo.com>2020-01-06 14:37:16 +0000
commit3c5194a00b3c0525dfd84552233e9c8f85a150f4 (patch)
treeaa2057962f6aefe00418de4c037f74010c7eb879 /addons/web/controllers/main.py
parent34bbdd88c0bc354b76b254bb78c4eb786f3d08c0 (diff)
[ADD] web: Custom File Input
New component: the custom file input. Its purpose is to define a input of type file with a custom trigger (button, link, etc.). Its construction is the following: - attributes: behaviour of the actual input (route to call, multifile, allowed extensions etc.) - inner template: the trigger that will fire the upload prompt when clicked Once a file has been uploaded, the component will emit a 'uploaded' custom event containing the files. closes odoo/odoo#38423 Related: odoo/enterprise#6031 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/controllers/main.py')
-rw-r--r--addons/web/controllers/main.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index b1e86ff2643..90657b2e764 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1469,7 +1469,7 @@ class Binary(http.Controller):
@http.route('/web/binary/upload', type='http', auth="user")
@serialize_exception
- def upload(self, callback, ufile):
+ def upload(self, ufile, callback=None):
# TODO: might be useful to have a configuration flag for max-length file uploads
out = """<script language="javascript" type="text/javascript">
var win = window.top.window;
@@ -1481,11 +1481,11 @@ class Binary(http.Controller):
ufile.content_type, base64.b64encode(data)]
except Exception as e:
args = [False, str(e)]
- return out % (json.dumps(callback), json.dumps(args))
+ return out % (json.dumps(callback), json.dumps(args)) if callback else json.dumps(args)
@http.route('/web/binary/upload_attachment', type='http', auth="user")
@serialize_exception
- def upload_attachment(self, callback, model, id, ufile):
+ def upload_attachment(self, model, id, ufile, callback=None):
files = request.httprequest.files.getlist('ufile')
Model = request.env['ir.attachment']
out = """<script language="javascript" type="text/javascript">
@@ -1519,7 +1519,7 @@ class Binary(http.Controller):
'id': attachment.id,
'size': attachment.file_size
})
- return out % (json.dumps(callback), json.dumps(args))
+ return out % (json.dumps(callback), json.dumps(args)) if callback else json.dumps(args)
@http.route([
'/web/binary/company_logo',