summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-09-14 08:15:01 +0000
committerChris McDonough <chrism@agendaless.com>2009-09-14 08:15:01 +0000
commita37220b84dee4cc8b1b12f34643ce97dad89ffe1 (patch)
tree0286c73411245e55cf28879e593c68ba6536f57c
parent032f080026c6d298d594e4a6781b3f91af066676 (diff)
downloadpyramid-a37220b84dee4cc8b1b12f34643ce97dad89ffe1.tar.gz
pyramid-a37220b84dee4cc8b1b12f34643ce97dad89ffe1.tar.bz2
pyramid-a37220b84dee4cc8b1b12f34643ce97dad89ffe1.zip
- The ``view`` attribute of the ``view`` ZCML directive is no longer
required if the ZCML directive has a ``template`` attribute.
-rw-r--r--CHANGES.txt3
-rw-r--r--docs/narr/views.rst6
-rw-r--r--repoze/bfg/tests/test_zcml.py29
-rw-r--r--repoze/bfg/zcml.py7
4 files changed, 43 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 91c16a362..c94364efd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,9 @@
Next release
============
+- The ``view`` attribute of the ``view`` ZCML directive is no longer
+ required if the ZCML directive has a ``template`` attribute.
+
- A ZCML ``view`` directive (and the associated ``bfg_view``
decorator) can now accept a "wrapper" value. If a "wrapper" value
is supplied, it is the value of a separate view's *name* attribute.
diff --git a/docs/narr/views.rst b/docs/narr/views.rst
index 2efe84fac..3916e6aac 100644
--- a/docs/narr/views.rst
+++ b/docs/narr/views.rst
@@ -227,7 +227,11 @@ The ``view`` ZCML directive has these possible attributes:
view
- The Python dotted-path name to the view callable.
+ The Python dotted-path name to the view callable. This attribute is
+ required unless a ``template`` attribute also exists. If a
+ ``template`` attribute exists on the directive, this attribute
+ defaults to a view that returns an empty dictionary (see
+ :ref:`views_with_templates`).
for
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index dcf6e17f8..208e8e754 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -355,6 +355,35 @@ class TestViewDirective(unittest.TestCase):
result = wrapper(None, None)
self.assertEqual(result.body, 'Hello.\n')
+ def test_with_template_no_view_callable(self):
+ from zope.interface import Interface
+ from zope.component import getSiteManager
+ from repoze.bfg.interfaces import IRequest
+ from repoze.bfg.interfaces import IView
+ from repoze.bfg.interfaces import IViewPermission
+
+ import repoze.bfg.tests
+
+ context = DummyContext(repoze.bfg.tests)
+ class IFoo(Interface):
+ pass
+ import os
+ fixture = 'fixtures/minimal.txt'
+ self._callFUT(context, 'repoze.view', IFoo, template=fixture)
+ actions = context.actions
+ self.assertEqual(len(actions), 1)
+
+ action = actions[0]
+ discrim = ('view', IFoo, '', IRequest, IView, None, None, None, None,
+ None)
+ self.assertEqual(action['discriminator'], discrim)
+ register = action['callable']
+ register()
+ sm = getSiteManager()
+ wrapper = sm.adapters.lookup((IFoo, IRequest), IView, name='')
+ result = wrapper(None, None)
+ self.assertEqual(result.body, 'Hello.\n')
+
def test_request_type_asinterface(self):
from zope.component import getSiteManager
from zope.interface import Interface
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index bca28d47e..ff2549447 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -89,7 +89,12 @@ def view(
):
if not view:
- raise ConfigurationError('"view" attribute was not specified')
+ if template:
+ def view(context, request):
+ return {}
+ else:
+ raise ConfigurationError('"view" attribute was not specified and '
+ 'no template specified')
sm = getSiteManager()