[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
|
||||
return request.redirect(path + '?' + request.httprequest.query_string)
|
||||
return self.reroute(path)
|
||||
return self._handle_exception(code=404)
|
||||
return super(ir_http, self)._dispatch()
|
||||
|
||||
def reroute(self, path):
|
||||
|
@ -103,8 +102,8 @@ class ir_http(orm.AbstractModel):
|
|||
try:
|
||||
_, path = rule.build(arguments)
|
||||
assert path is not None
|
||||
except Exception:
|
||||
return self._handle_exception(werkzeug.exceptions.NotFound())
|
||||
except Exception, e:
|
||||
return self._handle_exception(e, code=404)
|
||||
|
||||
if request.httprequest.method in ('GET', 'HEAD'):
|
||||
generated_path = werkzeug.url_unquote_plus(path)
|
||||
|
@ -136,30 +135,47 @@ class ir_http(orm.AbstractModel):
|
|||
if response.status_code == 304:
|
||||
return response
|
||||
|
||||
response.mimetype = attach[0]['mimetype']
|
||||
response.mimetype = attach[0]['mimetype'] or 'application/octet-stream'
|
||||
response.data = datas.decode('base64')
|
||||
return response
|
||||
|
||||
def _handle_exception(self, exception=None, code=500):
|
||||
try:
|
||||
return super(ir_http, self)._handle_exception(exception)
|
||||
except Exception:
|
||||
|
||||
def _handle_exception(self, exception, code=500):
|
||||
# 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
|
||||
|
||||
if getattr(request, 'website_enabled', False) and request.website:
|
||||
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)
|
||||
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
|
||||
|
||||
values = dict(
|
||||
exception=exception,
|
||||
traceback=traceback.format_exc(exception),
|
||||
)
|
||||
if exception:
|
||||
code = getattr(exception, 'code', code)
|
||||
|
||||
if isinstance(exception, openerp.exceptions.AccessError):
|
||||
code = 403
|
||||
|
||||
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:
|
||||
|
@ -184,8 +200,6 @@ class ir_http(orm.AbstractModel):
|
|||
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='[]'):
|
||||
super(ModelConverter, self).__init__(url_map, model)
|
||||
|
|
|
@ -208,12 +208,16 @@ class WebsiteForum(http.Controller):
|
|||
}, context=context)
|
||||
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):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
# increment view counter
|
||||
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'
|
||||
values = self._prepare_forum_values(forum=forum, searches=post)
|
||||
values.update({
|
||||
|
|
|
@ -1251,7 +1251,10 @@ class Root(object):
|
|||
request = self.get_request(httprequest)
|
||||
|
||||
def _dispatch_nodb():
|
||||
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")
|
||||
result = request.dispatch()
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue