From c44888527bc027a49777bc2394a2ae69e64b547c Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 14 Jun 2013 17:26:21 +0200 Subject: [PATCH] Added werkzeug route building, not yet switched bzr revid: nicolas.vanhoren@openerp.com-20130614152621-t8jv4474gt9k6yib --- addons/web/controllers/main.py | 4 ++-- addons/web/http.py | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index d2f425e0c49..87355d075f3 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1477,8 +1477,8 @@ class Export(openerpweb.Controller): """ return sorted([ controller.fmt - for path, controller in openerpweb.controllers_path.iteritems() - if path.startswith(self._cp_path) + for controller in openerpweb.controllers_object.itervalues() + if (controller._cp_path or "").startswith(self._cp_path) if hasattr(controller, 'fmt') ], key=operator.itemgetter("label")) diff --git a/addons/web/http.py b/addons/web/http.py index a9039f38f9e..ddb253c6b22 100644 --- a/addons/web/http.py +++ b/addons/web/http.py @@ -485,7 +485,6 @@ addons_module = {} addons_manifest = {} controllers_class_path = {} controllers_object = {} -controllers_object_path = {} controllers_path = {} class ControllerType(type): @@ -680,7 +679,7 @@ class Root(object): request.parameter_storage_class = werkzeug.datastructures.ImmutableDict request.app = self - handler = self.find_handler(*(request.path.split('/')[1:])) + handler = self.find_handler(request.path) if not handler: response = werkzeug.exceptions.NotFound() @@ -726,25 +725,32 @@ class Root(object): addons_manifest[module] = manifest self.statics['/%s/static' % module] = path_static - for k, v in controllers_class_path.items(): + self.routing_map = routing.Map() + for k, v in controllers_class_path.iteritems(): o = v[1]() controllers_object[v[0]] = o - controllers_object_path[k] = o - if hasattr(o, '_cp_path'): - controllers_path[o._cp_path] = o + members = inspect.getmembers(o) + for mk, mv in members: + if inspect.ismethod(mv) and getattr(mv, 'exposed', False): + url = os.path.join(o._cp_path, mk) + url += "/" + function = (mv, o.get_wrapped_method(mk)) + self.routing_map.add(routing.Rule(url, function)) + controllers_path[o._cp_path] = o app = werkzeug.wsgi.SharedDataMiddleware(self.dispatch, self.statics) self.dispatch = DisableCacheMiddleware(app) - def find_handler(self, *l): + def find_handler(self, path): """ Tries to discover the controller handling the request for the path specified by the provided parameters - :param l: path sections to a controller or controller method + :param path: path to match :returns: a callable matching the path sections, or ``None`` :rtype: ``Controller | None`` """ + l = path.split('/')[1:] if l: ps = '/' + '/'.join(filter(None, l)) method_name = 'index'