From 35aa2a977f5169db12b6a7367f7d3b7fa87277cc Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 8 Nov 2017 11:29:41 +0100 Subject: [PATCH] [FIX] website_slide: fix traceback when slide is a google doc or youtube link In case we are not uploading a file but add a slide based on google doc url or youtube link, post['datas'] is not set and the code will crash. Javascript don't check the onError, so the user never see the error and wait that nothing happend. --- addons/website_slides/controllers/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py index 70f83b18a37..b49fb349069 100644 --- a/addons/website_slides/controllers/main.py +++ b/addons/website_slides/controllers/main.py @@ -292,9 +292,11 @@ class website_slides(http.Controller): @http.route(['/slides/add_slide'], type='json', auth='user', methods=['POST'], website=True) def create_slide(self, *args, **post): - file_size = len(post['datas']) * 3 / 4; # base64 - if (file_size / 1024.0 / 1024.0) > 25: - return {'error': _('File is too big. File size cannot exceed 25MB')} + # check the size only when we upload a file. + if post.get('datas'): + file_size = len(post['datas']) * 3 / 4 # base64 + if (file_size / 1024.0 / 1024.0) > 25: + return {'error': _('File is too big. File size cannot exceed 25MB')} values = dict((fname, post[fname]) for fname in [ 'name', 'url', 'tag_ids', 'slide_type', 'channel_id',