[FIX] ir_http : move the handeling of virtual path to ir_attachment from website to base. This will allow css generated from less to be called in the backend.
This commit is contained in:
@@ -80,7 +80,7 @@ class ir_http(orm.AbstractModel):
|
||||
if self.geo_ip_resolver and request.httprequest.remote_addr:
|
||||
record = self.geo_ip_resolver.record_by_addr(request.httprequest.remote_addr) or {}
|
||||
request.session['geoip'] = record
|
||||
|
||||
|
||||
if request.website_enabled:
|
||||
try:
|
||||
if func:
|
||||
@@ -170,38 +170,8 @@ class ir_http(orm.AbstractModel):
|
||||
path += '?' + request.httprequest.query_string
|
||||
return werkzeug.utils.redirect(path, code=301)
|
||||
|
||||
def _serve_attachment(self):
|
||||
domain = [('type', '=', 'binary'), ('url', '=', request.httprequest.path)]
|
||||
attach = self.pool['ir.attachment'].search_read(request.cr, openerp.SUPERUSER_ID, domain, ['__last_update', 'datas', 'mimetype'], context=request.context)
|
||||
if attach:
|
||||
wdate = attach[0]['__last_update']
|
||||
datas = attach[0]['datas']
|
||||
response = werkzeug.wrappers.Response()
|
||||
server_format = openerp.tools.misc.DEFAULT_SERVER_DATETIME_FORMAT
|
||||
try:
|
||||
response.last_modified = datetime.datetime.strptime(wdate, server_format + '.%f')
|
||||
except ValueError:
|
||||
# just in case we have a timestamp without microseconds
|
||||
response.last_modified = datetime.datetime.strptime(wdate, server_format)
|
||||
|
||||
response.set_etag(hashlib.sha1(datas).hexdigest())
|
||||
response.make_conditional(request.httprequest)
|
||||
|
||||
if response.status_code == 304:
|
||||
return response
|
||||
|
||||
response.mimetype = attach[0]['mimetype'] or 'application/octet-stream'
|
||||
response.data = datas.decode('base64')
|
||||
return response
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#----------------------------------------------------------
|
||||
# ir_http modular http routing
|
||||
#----------------------------------------------------------
|
||||
import datetime
|
||||
import hashlib
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
@@ -94,9 +97,39 @@ class ir_http(osv.AbstractModel):
|
||||
raise openerp.exceptions.AccessDenied()
|
||||
return auth_method
|
||||
|
||||
def _serve_attachment(self):
|
||||
domain = [('type', '=', 'binary'), ('url', '=', request.httprequest.path)]
|
||||
attach = self.pool['ir.attachment'].search_read(request.cr, openerp.SUPERUSER_ID, domain, ['__last_update', 'datas', 'mimetype', 'checksum'], context=request.context)
|
||||
if attach:
|
||||
wdate = attach[0]['__last_update']
|
||||
datas = attach[0]['datas'] or '' # support empty ir_attachment
|
||||
response = werkzeug.wrappers.Response()
|
||||
server_format = openerp.tools.misc.DEFAULT_SERVER_DATETIME_FORMAT
|
||||
try:
|
||||
response.last_modified = datetime.datetime.strptime(wdate, server_format + '.%f')
|
||||
except ValueError:
|
||||
# just in case we have a timestamp without microseconds
|
||||
response.last_modified = datetime.datetime.strptime(wdate, server_format)
|
||||
|
||||
response.set_etag(attach[0]['checksum'])
|
||||
response.make_conditional(request.httprequest)
|
||||
|
||||
if response.status_code == 304:
|
||||
return response
|
||||
|
||||
response.mimetype = attach[0]['mimetype'] or 'application/octet-stream'
|
||||
response.data = datas.decode('base64')
|
||||
return response
|
||||
|
||||
def _handle_exception(self, exception):
|
||||
# If handle_exception returns something different than None, it will be used as a response
|
||||
|
||||
# This is done first as the attachment path may
|
||||
# not match any HTTP controller
|
||||
attach = self._serve_attachment()
|
||||
if attach:
|
||||
return attach
|
||||
|
||||
# Don't handle exception but use werkeug debugger if server in --dev mode
|
||||
if openerp.tools.config['dev_mode']:
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user