diff options
| author | Chris McDonough <chrism@plope.com> | 2011-07-23 14:02:53 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-07-23 14:02:53 -0400 |
| commit | 3835781dab5791282073252d2cee685668bc7b1e (patch) | |
| tree | e19be2ec32d516b85e2e5a89e7e8935caf517b4a | |
| parent | 070bfdbaa6f3cffbda3a0bfe86534e24ea01142c (diff) | |
| parent | 566a276a37fad8073206b46ec77b27498a126f02 (diff) | |
| download | pyramid-3835781dab5791282073252d2cee685668bc7b1e.tar.gz pyramid-3835781dab5791282073252d2cee685668bc7b1e.tar.bz2 pyramid-3835781dab5791282073252d2cee685668bc7b1e.zip | |
Merge branch 'master' into wrapviews
| -rw-r--r-- | CHANGES.txt | 10 | ||||
| -rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
| -rw-r--r-- | docs/narr/hooks.rst | 3 | ||||
| -rw-r--r-- | docs/narr/introduction.rst | 2 | ||||
| -rw-r--r-- | docs/whatsnew-1.1.rst | 10 | ||||
| -rw-r--r-- | pyramid/events.py | 12 | ||||
| -rw-r--r-- | pyramid/interfaces.py | 4 | ||||
| -rw-r--r-- | pyramid/renderers.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_events.py | 9 |
9 files changed, 42 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index a2ad1f720..57ab76e46 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,13 @@ +Next release +============ + +Features +-------- + +- The ``pyramid.events.BeforeRender`` event now has an attribute named + ``rendering_val``. This can be used to introspect the value returned by a + view in a BeforeRender subscriber. + 1.1 (2011-07-22) ================ diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index cdc011f87..4e9d944ea 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -142,3 +142,5 @@ Contributors - Michael Merickel, 2011/5/25 - Christoph Zwerschke, 2011/06/07 + +- Shane Hathaway, 2011/07/22 diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst index 2a6414e1f..985934736 100644 --- a/docs/narr/hooks.rst +++ b/docs/narr/hooks.rst @@ -601,6 +601,9 @@ to make sure the object implements every attribute and method outlined in :class:`pyramid.interfaces.IResponse` and you'll have to ensure that it's marked up with ``zope.interface.implements(IResponse)``: +.. code-block:: python + :linenos: + from pyramid.interfaces import IResponse from zope.interface import implements diff --git a/docs/narr/introduction.rst b/docs/narr/introduction.rst index 6cc5a87e5..63c31d340 100644 --- a/docs/narr/introduction.rst +++ b/docs/narr/introduction.rst @@ -30,7 +30,7 @@ create web applications. own via a set of libraries if the framework provides a set of facilities that fits your application requirements. -Pyramid attempts to follow follow these design and engineering principles: +Pyramid attempts to follow these design and engineering principles: Simplicity :app:`Pyramid` takes a *"pay only for what you eat"* approach. You can get diff --git a/docs/whatsnew-1.1.rst b/docs/whatsnew-1.1.rst index 6761aaff8..18d0aa0b1 100644 --- a/docs/whatsnew-1.1.rst +++ b/docs/whatsnew-1.1.rst @@ -152,7 +152,7 @@ to only influence ``Cache-Control`` headers, pass a tuple as ``http_cache`` with the first element of ``None``, e.g.: ``(None, {'public':True})``. The environment setting ``PYRAMID_PREVENT_HTTP_CACHE`` and configuration -file value ``prevent_http_cache`` are synomymous and allow you to prevent +file value ``prevent_http_cache`` are synonymous and allow you to prevent HTTP cache headers from being set by Pyramid's ``http_cache`` machinery globally in a process. see :ref:`influencing_http_caching` and :ref:`preventing_http_caching`. @@ -479,7 +479,7 @@ Deprecations and Behavior Differences these methods will be removed entirely. - A custom request factory is now required to return a request object that - has a ``response`` attribute (or "reified"/lazy property) if they the + has a ``response`` attribute (or "reified"/lazy property) if the request is meant to be used in a view that uses a renderer. This ``response`` attribute should be an instance of the class :class:`pyramid.response.Response`. @@ -542,8 +542,8 @@ Deprecations and Behavior Differences - Deprecated the :meth:`pyramid.config.Configurator.set_renderer_globals_factory` method and the ``renderer_globals`` Configurator constructor parameter. Users should - use convert code using this feature to use a BeforeRender event als - :ref:`beforerender_event`. + convert code using this feature to use a BeforeRender event. See the section + :ref:`beforerender_event` in the Hooks chapter. - In Pyramid 1.0, the :class:`pyramid.events.subscriber` directive behaved contrary to the documentation when passed more than one interface object to @@ -586,7 +586,7 @@ Deprecations and Behavior Differences - The :meth:`pyramid.config.Configurator.add_route` method allowed two routes with the same route to be added without an intermediate call to - :meth:`pyramid.config.Configurator.commit``. If you now receive a + :meth:`pyramid.config.Configurator.commit`. If you now receive a ``ConfigurationError`` at startup time that appears to be ``add_route`` related, you'll need to either a) ensure that all of your route names are unique or b) call ``config.commit()`` before adding a second route with the diff --git a/pyramid/events.py b/pyramid/events.py index b536bfd67..4021b94cc 100644 --- a/pyramid/events.py +++ b/pyramid/events.py @@ -193,10 +193,16 @@ class BeforeRender(dict): BeforeRender subscriber, your subscriber code will need to (using ``.get`` or ``__contains__`` of the event object) ensure no value already exists in the renderer globals dictionary before setting an overriding - value.""" + value. - def __init__(self, system): + The event has an additional attribute named ``rendering_val``. This is + the (non-system) value returned by a view or passed to ``render*`` as + ``value``. This feature is new in Pyramid 1.1.1. + """ + + def __init__(self, system, rendering_val=None): self._system = system + self.rendering_val = rendering_val def __setitem__(self, name, value): """ Set a name/value pair into the dictionary which is passed to a @@ -230,4 +236,4 @@ class BeforeRender(dict): """ Return the value for key ``k`` from the renderer globals dictionary, or the default if no such value exists.""" return self._system.get(k) - + diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py index d3a67e1aa..ec1d23acf 100644 --- a/pyramid/interfaces.py +++ b/pyramid/interfaces.py @@ -309,6 +309,10 @@ class IBeforeRender(Interface): """ Return the value for key ``k`` from the renderer globals dictionary, or the default if no such value exists.""" + rendering_val = Attribute('The value returned by a view or passed to a ' + '``render`` method for this rendering. ' + 'This feature is new in Pyramid 1.1.1.') + class IRenderer(Interface): def __call__(value, system): """ Call a the renderer implementation with the result of the diff --git a/pyramid/renderers.py b/pyramid/renderers.py index 52459ee90..c718cf1bb 100644 --- a/pyramid/renderers.py +++ b/pyramid/renderers.py @@ -409,7 +409,7 @@ class RendererHelper(object): if renderer_globals: system_values.update(renderer_globals) - registry.notify(BeforeRender(system_values)) + registry.notify(BeforeRender(system_values, value)) result = renderer(value, system_values) return result diff --git a/pyramid/tests/test_events.py b/pyramid/tests/test_events.py index e3a10ccad..116a48bb7 100644 --- a/pyramid/tests/test_events.py +++ b/pyramid/tests/test_events.py @@ -179,9 +179,9 @@ class TestSubscriber(unittest.TestCase): [(foo, dec.register, 'pyramid')]) class TestBeforeRender(unittest.TestCase): - def _makeOne(self, system): + def _makeOne(self, system, val=None): from pyramid.events import BeforeRender - return BeforeRender(system) + return BeforeRender(system, val) def test_instance_conforms(self): from zope.interface.verify import verifyObject @@ -246,6 +246,11 @@ class TestBeforeRender(unittest.TestCase): event = self._makeOne(system) self.assertEqual(event.get('a'), None) + def test_rendering_val(self): + system = {} + val = {} + event = self._makeOne(system, val) + self.assertTrue(event.rendering_val is val) class DummyConfigurator(object): def __init__(self): |
