[MERGE] Forward-port of saas-4 up to fa739ac
This commit is contained in:
commit
0d330ca25c
|
@ -74,7 +74,6 @@ class ir_http(orm.AbstractModel):
|
||||||
# to url without language so google doesn't see duplicate content
|
# to url without language so google doesn't see duplicate content
|
||||||
return request.redirect(path + '?' + request.httprequest.query_string)
|
return request.redirect(path + '?' + request.httprequest.query_string)
|
||||||
return self.reroute(path)
|
return self.reroute(path)
|
||||||
return self._handle_exception(code=404)
|
|
||||||
return super(ir_http, self)._dispatch()
|
return super(ir_http, self)._dispatch()
|
||||||
|
|
||||||
def reroute(self, path):
|
def reroute(self, path):
|
||||||
|
@ -103,8 +102,8 @@ class ir_http(orm.AbstractModel):
|
||||||
try:
|
try:
|
||||||
_, path = rule.build(arguments)
|
_, path = rule.build(arguments)
|
||||||
assert path is not None
|
assert path is not None
|
||||||
except Exception:
|
except Exception, e:
|
||||||
return self._handle_exception(werkzeug.exceptions.NotFound())
|
return self._handle_exception(e, code=404)
|
||||||
|
|
||||||
if request.httprequest.method in ('GET', 'HEAD'):
|
if request.httprequest.method in ('GET', 'HEAD'):
|
||||||
generated_path = werkzeug.url_unquote_plus(path)
|
generated_path = werkzeug.url_unquote_plus(path)
|
||||||
|
@ -136,55 +135,70 @@ class ir_http(orm.AbstractModel):
|
||||||
if response.status_code == 304:
|
if response.status_code == 304:
|
||||||
return response
|
return response
|
||||||
|
|
||||||
response.mimetype = attach[0]['mimetype']
|
response.mimetype = attach[0]['mimetype'] or 'application/octet-stream'
|
||||||
response.data = datas.decode('base64')
|
response.data = datas.decode('base64')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _handle_exception(self, exception=None, code=500):
|
def _handle_exception(self, exception, code=500):
|
||||||
try:
|
# This is done first as the attachment path may
|
||||||
|
# not match any HTTP controller, so the request
|
||||||
|
# may not be website-enabled.
|
||||||
|
attach = self._serve_attachment()
|
||||||
|
if attach:
|
||||||
|
return attach
|
||||||
|
|
||||||
|
is_website_request = bool(getattr(request, 'website_enabled', False) and request.website)
|
||||||
|
if not is_website_request:
|
||||||
|
# Don't touch non website requests exception handling
|
||||||
return super(ir_http, self)._handle_exception(exception)
|
return super(ir_http, self)._handle_exception(exception)
|
||||||
except Exception:
|
else:
|
||||||
|
try:
|
||||||
|
response = super(ir_http, self)._handle_exception(exception)
|
||||||
|
if isinstance(response, Exception):
|
||||||
|
exception = response
|
||||||
|
else:
|
||||||
|
# if parent excplicitely returns a plain response, then we don't touch it
|
||||||
|
return response
|
||||||
|
except Exception, e:
|
||||||
|
exception = e
|
||||||
|
|
||||||
attach = self._serve_attachment()
|
values = dict(
|
||||||
if attach:
|
exception=exception,
|
||||||
return attach
|
traceback=traceback.format_exc(exception),
|
||||||
|
)
|
||||||
|
code = getattr(exception, 'code', code)
|
||||||
|
|
||||||
if getattr(request, 'website_enabled', False) and request.website:
|
if isinstance(exception, openerp.exceptions.AccessError):
|
||||||
values = dict(
|
code = 403
|
||||||
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(
|
if isinstance(exception, ir_qweb.QWebException):
|
||||||
status_message=werkzeug.http.HTTP_STATUS_CODES[code],
|
values.update(qweb_exception=exception)
|
||||||
status_code=code,
|
if isinstance(exception.qweb.get('cause'), openerp.exceptions.AccessError):
|
||||||
)
|
code = 403
|
||||||
|
|
||||||
if not request.uid:
|
if code == 500:
|
||||||
self._auth_method_public()
|
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'])
|
||||||
|
|
||||||
try:
|
values.update(
|
||||||
html = request.website._render('website.%s' % code, values)
|
status_message=werkzeug.http.HTTP_STATUS_CODES[code],
|
||||||
except Exception:
|
status_code=code,
|
||||||
html = request.website._render('website.http_error', values)
|
)
|
||||||
return werkzeug.wrappers.Response(html, status=code, content_type='text/html;charset=utf-8')
|
|
||||||
|
|
||||||
raise
|
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')
|
||||||
|
|
||||||
class ModelConverter(ir.ir_http.ModelConverter):
|
class ModelConverter(ir.ir_http.ModelConverter):
|
||||||
def __init__(self, url_map, model=False, domain='[]'):
|
def __init__(self, url_map, model=False, domain='[]'):
|
||||||
|
|
|
@ -208,12 +208,16 @@ class WebsiteForum(http.Controller):
|
||||||
}, context=context)
|
}, context=context)
|
||||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), new_question_id))
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), new_question_id))
|
||||||
|
|
||||||
@http.route(['''/forum/<model("forum.forum"):forum>/question/<model("forum.post", "[('forum_id','=',forum[0])]"):question>'''], type='http', auth="public", website=True)
|
@http.route(['''/forum/<model("forum.forum"):forum>/question/<model("forum.post", "[('forum_id','=',forum[0]),('parent_id','=',False)]"):question>'''], type='http', auth="public", website=True)
|
||||||
def question(self, forum, question, **post):
|
def question(self, forum, question, **post):
|
||||||
cr, uid, context = request.cr, request.uid, request.context
|
cr, uid, context = request.cr, request.uid, request.context
|
||||||
# increment view counter
|
# increment view counter
|
||||||
request.registry['forum.post'].set_viewed(cr, SUPERUSER_ID, [question.id], context=context)
|
request.registry['forum.post'].set_viewed(cr, SUPERUSER_ID, [question.id], context=context)
|
||||||
|
|
||||||
|
if question.parent_id:
|
||||||
|
redirect_url = "/forum/%s/question/%s" % (slug(forum), slug(question.parent_id))
|
||||||
|
return werkzeug.utils.redirect(redirect_url, 301)
|
||||||
|
|
||||||
filters = 'question'
|
filters = 'question'
|
||||||
values = self._prepare_forum_values(forum=forum, searches=post)
|
values = self._prepare_forum_values(forum=forum, searches=post)
|
||||||
values.update({
|
values.update({
|
||||||
|
|
|
@ -1251,7 +1251,10 @@ class Root(object):
|
||||||
request = self.get_request(httprequest)
|
request = self.get_request(httprequest)
|
||||||
|
|
||||||
def _dispatch_nodb():
|
def _dispatch_nodb():
|
||||||
func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()
|
try:
|
||||||
|
func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()
|
||||||
|
except werkzeug.exceptions.HTTPException, e:
|
||||||
|
return request._handle_exception(e)
|
||||||
request.set_handler(func, arguments, "none")
|
request.set_handler(func, arguments, "none")
|
||||||
result = request.dispatch()
|
result = request.dispatch()
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue