diff options
| -rw-r--r-- | CHANGES.txt | 4 | ||||
| -rw-r--r-- | TODO.txt | 3 | ||||
| -rw-r--r-- | docs/narr/renderers.rst | 18 | ||||
| -rw-r--r-- | docs/whatsnew-1.3.rst | 7 | ||||
| -rw-r--r-- | pyramid/renderers.py | 4 | ||||
| -rw-r--r-- | pyramid/tests/test_renderers.py | 6 |
6 files changed, 29 insertions, 13 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 0bb2c164b..d9106ddb9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 ------------- @@ -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 diff --git a/docs/narr/renderers.rst b/docs/narr/renderers.rst index 67354a1ed..1622f1f29 100644 --- a/docs/narr/renderers.rst +++ b/docs/narr/renderers.rst @@ -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: diff --git a/docs/whatsnew-1.3.rst b/docs/whatsnew-1.3.rst index 918870018..c4bde2b54 100644 --- a/docs/whatsnew-1.3.rst +++ b/docs/whatsnew-1.3.rst @@ -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 --------------------------- diff --git a/pyramid/renderers.py b/pyramid/renderers.py index 61f5e0b35..a94d86e20 100644 --- a/pyramid/renderers.py +++ b/pyramid/renderers.py @@ -390,7 +390,8 @@ class RendererHelper(object): '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 @@ class RendererHelper(object): 'renderer_info':self, 'context':getattr(request, 'context', None), 'request':request, + 'r':request, } system_values = BeforeRender(system_values, value) diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py index dbdfb06b3..2c27c6c29 100644 --- a/pyramid/tests/test_renderers.py +++ b/pyramid/tests/test_renderers.py @@ -484,7 +484,8 @@ class TestRendererHelper(unittest.TestCase): 'renderer_name': 'loo.foo', 'request': request, 'context': 'context', - 'view': 'view'} + 'view': 'view', + 'r': request,} ) def test_render_explicit_registry(self): @@ -517,7 +518,8 @@ class TestRendererHelper(unittest.TestCase): '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) |
