summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Correa Neto <fcdoth@gmail.com>2008-12-09 23:16:56 +0000
committerFernando Correa Neto <fcdoth@gmail.com>2008-12-09 23:16:56 +0000
commit67b8a1ceda0d73739b18045c8b405a1d22b4480a (patch)
treeba340a43cfd0f030833b8714137f7439bbb45feb
parentd1925330a4b9c9fae0ac28025b5c1023a0a5c0a6 (diff)
downloadpyramid-67b8a1ceda0d73739b18045c8b405a1d22b4480a.tar.gz
pyramid-67b8a1ceda0d73739b18045c8b405a1d22b4480a.tar.bz2
pyramid-67b8a1ceda0d73739b18045c8b405a1d22b4480a.zip
Add context.root to router so the root model can be easily accessed from a view
-rw-r--r--CHANGES.txt5
-rw-r--r--docs/narr/traversal.rst7
-rw-r--r--repoze/bfg/router.py1
-rw-r--r--repoze/bfg/traversal.py5
4 files changed, 17 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 566aab498..a310d2c27 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,8 @@
+0.5.4 (12/9/2008)
+
+ - Add ``request.root`` to ``router.Router`` in order to have easy
+ access to the application root.
+
0.5.3 (12/7/2008)
- Remove the ``ITestingTemplateRenderer`` interface. When
diff --git a/docs/narr/traversal.rst b/docs/narr/traversal.rst
index f85c012e6..ead48aac4 100644
--- a/docs/narr/traversal.rst
+++ b/docs/narr/traversal.rst
@@ -272,3 +272,10 @@ The :term:`view name` will always be available to a view as the
single string (possibly the empty string if we're rendering a default
view).
+The :term:`root` will always be available to a view as the
+``root`` attribute of the :term:`request` object. It will be the
+root model instance of the current application.
+
+The :term:`context` will always be available to a view as the
+``context`` attribute of the :term:`request` object. It will be the
+model instance of the current application. \ No newline at end of file
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