From 4d6cd1a3901495f66513934bb7e1a6ac58116400 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 29 May 2011 19:56:16 +0200 Subject: [PATCH] URL building should work in theory --- flask/app.py | 14 ++++++++++++++ flask/helpers.py | 1 + 2 files changed, 15 insertions(+) diff --git a/flask/app.py b/flask/app.py index 9ac6319c..662d6ca0 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1013,6 +1013,20 @@ class Flask(_PackageBoundObject): return self.url_map.bind_to_environ(request.environ, server_name=self.config['SERVER_NAME']) + def inject_url_defaults(self, endpoint, values): + """Injects the URL defaults for the given endpoint directly into + the values dictionary passed. This is used internally and + automatically called on URL building. + + .. versionadded:: 0.7 + """ + funcs = self.url_default_functions.get(None, ()) + if '.' in endpoint: + bp = endpoint.split('.', 1)[0] + funcs = chain(funcs, self.url_default_functions.get(bp, ())) + for func in funcs: + func(endpoint, values) + def preprocess_request(self): """Called before the actual request dispatching and will call every as :meth:`before_request` decorated function. diff --git a/flask/helpers.py b/flask/helpers.py index a2afa0f6..14521ce1 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -180,6 +180,7 @@ def url_for(endpoint, **values): elif endpoint.startswith('.'): endpoint = endpoint[1:] external = values.pop('_external', False) + ctx.app.inject_url_defaults(endpoint, values) return ctx.url_adapter.build(endpoint, values, force_external=external)