From 67b8a1ceda0d73739b18045c8b405a1d22b4480a Mon Sep 17 00:00:00 2001 From: Fernando Correa Neto Date: Tue, 9 Dec 2008 23:16:56 +0000 Subject: Add context.root to router so the root model can be easily accessed from a view --- repoze/bfg/router.py | 1 + repoze/bfg/traversal.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'repoze') diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index cd040c0c8..89101cb5e 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -48,6 +48,7 @@ class Router(object): settings = queryUtility(ISettings) context, name, subpath = traverser(environ) + request.root = root request.context = context request.view_name = name request.subpath = subpath diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py index 4c5bb930d..61b66c040 100644 --- a/repoze/bfg/traversal.py +++ b/repoze/bfg/traversal.py @@ -66,7 +66,10 @@ class ModelGraphTraverser(object): def find_root(model): """ Find the root node in the graph to which ``model`` - belongs. Note that ``model`` should be :term:`location`-aware.""" + belongs. Note that ``model`` should be :term:`location`-aware. + Note that the root node is available in the request object by + accessing the ``request.root`` attribute. + """ for location in lineage(model): if location.__parent__ is None: model = location -- cgit v1.2.3