Permalink
Browse files

- The system value ``r`` is now supplied to renderers as an alias for

  ``request``.  This means that you can now, for example, in a template, do
  ``r.route_url(...)`` instead of ``request.route_url(...)``.

Fixes #413.
  • Loading branch information...
1 parent f9bcf47 commit 4786cae2e7a053b01091b5e185102f9c26885b08 @mcdonc mcdonc committed Feb 16, 2012
Showing with 29 additions and 13 deletions.
  1. +4 −0 CHANGES.txt
  2. +3 −0 TODO.txt
  3. +9 −9 docs/narr/renderers.rst
  4. +6 −1 docs/whatsnew-1.3.rst
  5. +3 −1 pyramid/renderers.py
  6. +4 −2 pyramid/tests/test_renderers.py
View
@@ -28,6 +28,10 @@ Features
more information. This is not a new feature, it just provides an API for
adding a traverser without needing to use the ZCA API.
+- The system value ``r`` is now supplied to renderers as an alias for
+ ``request``. This means that you can now, for example, in a template, do
+ ``r.route_url(...)`` instead of ``request.route_url(...)``.
+
Documentation
-------------
View
@@ -4,6 +4,9 @@ Pyramid TODOs
Nice-to-Have
------------
+- Fix renderers chapter to better document system values passed to template
+ renderers.
+
- Add set_resource_url_generator method.
- Put includes in development.ini on separate lines and fix project.rst to
View
@@ -333,15 +333,15 @@ dictionary, an error will be raised.
Before passing keywords to the template, the keyword arguments derived from
the dictionary returned by the view are augmented. The callable object --
-whatever object was used to define the view -- will be automatically
-inserted into the set of keyword arguments passed to the template as the
-``view`` keyword. If the view callable was a class, the ``view`` keyword
-will be an instance of that class. Also inserted into the keywords passed to
-the template are ``renderer_name`` (the string used in the ``renderer``
-attribute of the directive), ``renderer_info`` (an object containing
-renderer-related information), ``context`` (the context resource of the view
-used to render the template), and ``request`` (the request passed to the view
-used to render the template).
+whatever object was used to define the view -- will be automatically inserted
+into the set of keyword arguments passed to the template as the ``view``
+keyword. If the view callable was a class, the ``view`` keyword will be an
+instance of that class. Also inserted into the keywords passed to the
+template are ``renderer_name`` (the string used in the ``renderer`` attribute
+of the directive), ``renderer_info`` (an object containing renderer-related
+information), ``context`` (the context resource of the view used to render
+the template), and ``request`` (the request passed to the view used to render
+the template). ``request`` is also available as ``r`` in Pyramid 1.3+.
Here's an example view configuration which uses a Chameleon ZPT renderer:
View
@@ -54,7 +54,8 @@ to make some changes:
- We've replaced the ``paster`` command with Pyramid-specific analogues.
-- We've made the default WSGI server the ``waitress`` server.
+- We've made the default WSGI server used by Pyramid scaffolding the
+ :term:`waitress` server.
Previously (in Pyramid 1.0, 1.1 and 1.2), you created a Pyramid application
using ``paster create``, like so::
@@ -283,6 +284,10 @@ Minor Feature Additions
something like "AttributeError: 'NoneType' object has no attribute
'rfind'".
+- The system value ``r`` is now supplied to renderers as an alias for
+ ``request``. This means that you can now, for example, in a template, do
+ ``r.route_url(...)`` instead of ``request.route_url(...)``.
+
Backwards Incompatibilities
---------------------------
View
@@ -390,7 +390,8 @@ def render_view(self, request, response, view, context):
'renderer_name':self.name, # b/c
'renderer_info':self,
'context':context,
- 'request':request
+ 'request':request,
+ 'r':request,
}
return self.render_to_response(response, system, request=request)
@@ -403,6 +404,7 @@ def render(self, value, system_values, request=None):
'renderer_info':self,
'context':getattr(request, 'context', None),
'request':request,
+ 'r':request,
}
system_values = BeforeRender(system_values, value)
@@ -484,7 +484,8 @@ def test_render_view(self):
'renderer_name': 'loo.foo',
'request': request,
'context': 'context',
- 'view': 'view'}
+ 'view': 'view',
+ 'r': request,}
)
def test_render_explicit_registry(self):
@@ -517,7 +518,8 @@ def test_render_system_values_is_None(self):
'context':context,
'renderer_name':'loo.foo',
'view':None,
- 'renderer_info':helper
+ 'renderer_info':helper,
+ 'r':request,
}
self.assertEqual(result[0], 'values')
self.assertEqual(result[1], system)

0 comments on commit 4786cae

Please sign in to comment.