From 1f747d892c08354a96b5bbbe3744496341e64c22 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 24 Aug 2012 16:35:38 +0200 Subject: [PATCH] [IMP] reload static paths when new modules are availables bzr revid: chs@openerp.com-20120824143538-49u29wyaojakhzfu --- addons/web/__init__.py | 1 + addons/web/__openerp__.py | 1 + addons/web/common/http.py | 25 +++++++++++++++---------- openerp-web | 3 ++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/addons/web/__init__.py b/addons/web/__init__.py index 621931e9167..4425f3ce572 100644 --- a/addons/web/__init__.py +++ b/addons/web/__init__.py @@ -2,6 +2,7 @@ import logging from . import common from . import controllers +from . import ir_module _logger = logging.getLogger(__name__) diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index fa32a8595cc..65a7939d8bb 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -1,6 +1,7 @@ { 'name': 'Web', 'category': 'Hidden', + 'version': '7.0.1.0', 'description': """ OpenERP Web core module. diff --git a/addons/web/common/http.py b/addons/web/common/http.py index 9c3664c8da0..4cb5b8d4bf8 100644 --- a/addons/web/common/http.py +++ b/addons/web/common/http.py @@ -461,7 +461,7 @@ class Root(object): only used in case the list of databases is requested by the server, will be filtered by this pattern """ - def __init__(self, options, openerp_addons_namespace=True): + def __init__(self, options): self.config = options if not hasattr(self.config, 'connector'): @@ -473,11 +473,9 @@ class Root(object): self.httpsession_cookie = 'httpsessionid' self.addons = {} + self.statics = {} - static_dirs = self._load_addons(openerp_addons_namespace) - if options.serve_static: - app = werkzeug.wsgi.SharedDataMiddleware( self.dispatch, static_dirs) - self.dispatch = DisableCacheMiddleware(app) + self._load_addons() if options.session_storage: if not os.path.exists(options.session_storage): @@ -490,7 +488,7 @@ class Root(object): """ return self.dispatch(environ, start_response) - def dispatch(self, environ, start_response): + def _dispatch(self, environ, start_response): """ Performs the actual WSGI dispatching for the application, may be wrapped during the initialization of the object. @@ -520,12 +518,13 @@ class Root(object): return response(environ, start_response) - def _load_addons(self, openerp_addons_namespace=True): + def _load_addons(self): """ Loads all addons at the specified addons path, returns a mapping of static URLs to the corresponding directories """ - statics = {} + openerp_addons_namespace = getattr(self.config, 'openerp_addons_namespace', True) + for addons_path in self.config.addons_path: for module in os.listdir(addons_path): if module not in addons_module: @@ -541,14 +540,20 @@ class Root(object): m = __import__(module) addons_module[module] = m addons_manifest[module] = manifest - statics['/%s/static' % module] = path_static + self.statics['/%s/static' % module] = path_static + for k, v in controllers_class: if k not in controllers_object: o = v() controllers_object[k] = o if hasattr(o, '_cp_path'): controllers_path[o._cp_path] = o - return statics + + app = self._dispatch + if self.config.serve_static: + app = werkzeug.wsgi.SharedDataMiddleware(self._dispatch, self.statics) + + self.dispatch = DisableCacheMiddleware(app) def find_handler(self, *l): """ diff --git a/openerp-web b/openerp-web index 3340b95646e..2e12a96ef64 100755 --- a/openerp-web +++ b/openerp-web @@ -105,7 +105,8 @@ if __name__ == "__main__": else: logging.basicConfig(level=getattr(logging, options.log_level.upper())) - app = web.common.http.Root(options, openerp_addons_namespace=False) + options.openerp_addons_namespace = False + app = web.common.http.Root(options) if options.proxy_mode: app = werkzeug.contrib.fixers.ProxyFix(app)