diff options
Diffstat (limited to 'addons/website/controllers/main.py')
| -rw-r--r-- | addons/website/controllers/main.py | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index b9fc68bb667..eac1f163cf6 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -9,7 +9,6 @@ import datetime from sys import maxint -import psycopg2 import werkzeug import werkzeug.exceptions import werkzeug.utils @@ -27,6 +26,7 @@ logger = logging.getLogger(__name__) # Completely arbitrary limits MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT = IMAGE_LIMITS = (1024, 768) + class Website(openerp.addons.web.controllers.main.Home): #------------------------------------------------------ # View @@ -179,6 +179,7 @@ class Website(openerp.addons.web.controllers.main.Home): result.append({ 'name': v.inherit_option_id.name, 'id': v.id, + 'xml_id': v.xml_id, 'inherit_id': v.inherit_id.id, 'header': True, 'active': False @@ -187,6 +188,7 @@ class Website(openerp.addons.web.controllers.main.Home): result.append({ 'name': v.name, 'id': v.id, + 'xml_id': v.xml_id, 'inherit_id': v.inherit_id.id, 'header': False, 'active': (v.inherit_id.id == v.inherit_option_id.id) or (not optional and v.inherit_id.id) @@ -239,13 +241,20 @@ class Website(openerp.addons.web.controllers.main.Home): @http.route('/website/attach', type='http', auth='user', methods=['POST'], website=True) def attach(self, func, upload): - req = request.httprequest url = message = None try: + image_data = upload.read() + image = Image.open(cStringIO.StringIO(image_data)) + w, h = image.size + if w*h > 42e6: # Nokia Lumia 1020 photo resolution + raise ValueError( + u"Image size excessive, uploaded images must be smaller " + u"than 42 million pixel") + attachment_id = request.registry['ir.attachment'].create(request.cr, request.uid, { 'name': upload.filename, - 'datas': upload.read().encode('base64'), + 'datas': image_data.encode('base64'), 'datas_fname': upload.filename, 'res_model': 'ir.ui.view', }, request.context) @@ -259,7 +268,7 @@ class Website(openerp.addons.web.controllers.main.Home): }) except Exception, e: logger.exception("Failed to upload image to attachment") - message = str(e) + message = unicode(e) return """<script type='text/javascript'> window.parent['%s'](%s, %s); @@ -366,5 +375,34 @@ class Website(openerp.addons.web.controllers.main.Home): return response - -# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: + #------------------------------------------------------ + # Server actions + #------------------------------------------------------ + @http.route(['/website/action/<id_or_xml_id>'], type='http', auth="public", website=True) + def actions_server(self, id_or_xml_id, **post): + cr, uid, context = request.cr, request.uid, request.context + res, action_id, action = None, None, None + ServerActions = request.registry['ir.actions.server'] + + # find the action_id, either an int, an int into a basestring, or an xml_id + if isinstance(id_or_xml_id, basestring) and '.' in id_or_xml_id: + action_id = request.registry['ir.model.data'].xmlid_to_res_id(request.cr, request.uid, id_or_xml_id, raise_if_not_found=False) + else: + try: + action_id = int(id_or_xml_id) + except ValueError: + pass + # check it effectively exists + if action_id: + action_ids = ServerActions.exists(cr, uid, [action_id], context=context) + action_id = action_ids and action_ids[0] or None + # run it, return only LazyResponse that are templates to be rendered + if action_id: + action = ServerActions.browse(cr, uid, action_id, context=context) + if action.state == 'code' and action.website_published: + action_res = ServerActions.run(cr, uid, [action_id], context=context) + if isinstance(action_res, LazyResponse): + res = action_res + if res: + return res + return request.redirect('/') |
