summaryrefslogtreecommitdiff
path: root/addons/website/models
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2014-05-27 20:49:49 +0200
committerOlivier Dony <odo@openerp.com>2014-05-27 20:49:49 +0200
commit04211015fc3d4be2a8c65b9d977c2d9c4dac8be7 (patch)
treeb651a2900e630ed2ff780ddb960b55470f3bd118 /addons/website/models
parente16233217c6919b33e6d1135ff07538d839f6a2f (diff)
parent045285123f2551ca74753260fcf807af4bc413d0 (diff)
[MERGE] Forward-port of latest saas-4 fixes, up to 0452851
Diffstat (limited to 'addons/website/models')
-rw-r--r--addons/website/models/ir_http.py85
-rw-r--r--addons/website/models/ir_qweb.py16
-rw-r--r--addons/website/models/website.py5
3 files changed, 60 insertions, 46 deletions
diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py
index 360b34c877c..44b3f771f62 100644
--- a/addons/website/models/ir_http.py
+++ b/addons/website/models/ir_http.py
@@ -141,49 +141,50 @@ class ir_http(orm.AbstractModel):
return response
def _handle_exception(self, exception=None, code=500):
- if isinstance(exception, werkzeug.exceptions.HTTPException) and hasattr(exception, 'response') and exception.response:
- return exception.response
-
- attach = self._serve_attachment()
- if attach:
- return attach
-
- if getattr(request, 'website_enabled', False) and request.website:
- values = dict(
- exception=exception,
- traceback=traceback.format_exc(exception),
- )
- if exception:
- code = getattr(exception, 'code', code)
- if isinstance(exception, ir_qweb.QWebException):
- values.update(qweb_exception=exception)
- if isinstance(exception.qweb.get('cause'), openerp.exceptions.AccessError):
- code = 403
- if code == 500:
- logger.error("500 Internal Server Error:\n\n%s", values['traceback'])
- if 'qweb_exception' in values:
- view = request.registry.get("ir.ui.view")
- views = view._views_get(request.cr, request.uid, exception.qweb['template'], request.context)
- to_reset = [v for v in views if v.model_data_id.noupdate is True]
- values['views'] = to_reset
- elif code == 403:
- logger.warn("403 Forbidden:\n\n%s", values['traceback'])
-
- values.update(
- status_message=werkzeug.http.HTTP_STATUS_CODES[code],
- status_code=code,
- )
-
- if not request.uid:
- self._auth_method_public()
-
- try:
- html = request.website._render('website.%s' % code, values)
- except Exception:
- html = request.website._render('website.http_error', values)
- return werkzeug.wrappers.Response(html, status=code, content_type='text/html;charset=utf-8')
+ try:
+ return super(ir_http, self)._handle_exception(exception)
+ except Exception:
- return super(ir_http, self)._handle_exception(exception)
+ attach = self._serve_attachment()
+ if attach:
+ return attach
+
+ if getattr(request, 'website_enabled', False) and request.website:
+ values = dict(
+ exception=exception,
+ traceback=traceback.format_exc(exception),
+ )
+ if exception:
+ code = getattr(exception, 'code', code)
+ if isinstance(exception, ir_qweb.QWebException):
+ values.update(qweb_exception=exception)
+ if isinstance(exception.qweb.get('cause'), openerp.exceptions.AccessError):
+ code = 403
+ if code == 500:
+ logger.error("500 Internal Server Error:\n\n%s", values['traceback'])
+ if 'qweb_exception' in values:
+ view = request.registry.get("ir.ui.view")
+ views = view._views_get(request.cr, request.uid, exception.qweb['template'], request.context)
+ to_reset = [v for v in views if v.model_data_id.noupdate is True]
+ values['views'] = to_reset
+ elif code == 403:
+ logger.warn("403 Forbidden:\n\n%s", values['traceback'])
+
+ values.update(
+ status_message=werkzeug.http.HTTP_STATUS_CODES[code],
+ status_code=code,
+ )
+
+ if not request.uid:
+ self._auth_method_public()
+
+ try:
+ html = request.website._render('website.%s' % code, values)
+ except Exception:
+ html = request.website._render('website.http_error', values)
+ return werkzeug.wrappers.Response(html, status=code, content_type='text/html;charset=utf-8')
+
+ raise
class ModelConverter(ir.ir_http.ModelConverter):
def __init__(self, url_map, model=False, domain='[]'):
diff --git a/addons/website/models/ir_qweb.py b/addons/website/models/ir_qweb.py
index ad2b63a6dd9..0e1fe2beb89 100644
--- a/addons/website/models/ir_qweb.py
+++ b/addons/website/models/ir_qweb.py
@@ -15,6 +15,7 @@ import urllib2
import urlparse
import re
+import werkzeug.urls
import werkzeug.utils
from dateutil import parser
from lxml import etree, html
@@ -265,10 +266,19 @@ class Image(orm.AbstractModel):
if options is None: options = {}
classes = ['img', 'img-responsive'] + options.get('class', '').split()
- return ir_qweb.HTMLSafe('<img class="%s" src="/website/image?model=%s&field=%s&id=%s"/>' % (
+ url_params = {
+ 'model': record._model._name,
+ 'field': field_name,
+ 'id': record.id,
+ }
+ for options_key in ['max_width', 'max_height']:
+ if options.get(options_key):
+ url_params[options_key] = options[options_key]
+
+ return ir_qweb.HTMLSafe('<img class="%s" src="/website/image?%s"/>' % (
' '.join(itertools.imap(werkzeug.utils.escape, classes)),
- record._model._name,
- field_name, record.id))
+ werkzeug.urls.url_encode(url_params)
+ ))
local_url_re = re.compile(r'^/(?P<module>[^]]+)/static/(?P<rest>.+)$')
def from_html(self, cr, uid, model, column, element, context=None):
diff --git a/addons/website/models/website.py b/addons/website/models/website.py
index 433d8644698..db02dcce51e 100644
--- a/addons/website/models/website.py
+++ b/addons/website/models/website.py
@@ -541,7 +541,10 @@ class website(osv.osv):
response.mimetype = Image.MIME[image.format]
w, h = image.size
- max_w, max_h = int(max_width), int(max_height)
+ try:
+ max_w, max_h = int(max_width), int(max_height)
+ except:
+ max_w, max_h = (maxint, maxint)
if w < max_w and h < max_h:
response.data = data