[Checkins] SVN: zope.app.publication/trunk/ Moved the <browser:defaultView> directive handler to

Shane Hathaway shane at hathawaymix.org
Sat May 23 01:09:38 EDT 2009


Log message for revision 100277:
  Moved the <browser:defaultView> directive handler to
  zope.app.publication, since zope.app.publication is what
  uses the registration.
  

Changed:
  U   zope.app.publication/trunk/CHANGES.txt
  U   zope.app.publication/trunk/src/zope/app/publication/meta.zcml
  U   zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py
  U   zope.app.publication/trunk/src/zope/app/publication/metadirectives.py
  U   zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py

-=-
Modified: zope.app.publication/trunk/CHANGES.txt
===================================================================
--- zope.app.publication/trunk/CHANGES.txt	2009-05-23 04:23:22 UTC (rev 100276)
+++ zope.app.publication/trunk/CHANGES.txt	2009-05-23 05:09:37 UTC (rev 100277)
@@ -16,6 +16,10 @@
   zope.app.publication, removing the dependency on
   zope.app.publisher except for testing purposes.
 
+- Moved the <browser:defaultView> directive handler to
+  zope.app.publication, since zope.app.publication is what
+  uses the registration.
+
 3.6.0 (2009-05-18)
 ------------------
 

Modified: zope.app.publication/trunk/src/zope/app/publication/meta.zcml
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/meta.zcml	2009-05-23 04:23:22 UTC (rev 100276)
+++ zope.app.publication/trunk/src/zope/app/publication/meta.zcml	2009-05-23 05:09:37 UTC (rev 100277)
@@ -5,4 +5,12 @@
         schema=".metadirectives.IRequestPublicationDirective"
         handler=".metaconfigure.publisher"
         />
+
+  <meta:directive
+        namespace="http://namespaces.zope.org/browser"
+        name="defaultView"
+        schema=".metadirectives.IDefaultViewDirective"
+        handler=".metaconfigure.defaultView"
+        />
+
 </configure>

Modified: zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py	2009-05-23 04:23:22 UTC (rev 100276)
+++ zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py	2009-05-23 05:09:37 UTC (rev 100277)
@@ -11,16 +11,21 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" Directive handler for publication factory
+""" Directive handlers
 
-See metadirective.py
+See metadirectives.py
 
 $Id$
 """
 __docformat__ = 'restructuredtext'
 
 from zope.app.publication.requestpublicationregistry import factoryRegistry
+from zope.component.interface import provideInterface
+from zope.component.zcml import handler
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces import IDefaultViewName
 
+
 def publisher(_context, name, factory, methods=['*'], mimetypes=['*'],
               priority=0):
 
@@ -33,3 +38,20 @@
                 callable = factoryRegistry.register,
                 args = (method, mimetype, name, priority, factory)
                 )
+
+
+def defaultView(_context, name, for_=None, layer=IBrowserRequest):
+
+    _context.action(
+        discriminator = ('defaultViewName', for_, layer, name),
+        callable = handler,
+        args = ('registerAdapter',
+                name, (for_, layer), IDefaultViewName, '', _context.info)
+        )
+
+    if for_ is not None:
+        _context.action(
+            discriminator = None,
+            callable = provideInterface,
+            args = ('', for_)
+            )

Modified: zope.app.publication/trunk/src/zope/app/publication/metadirectives.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/metadirectives.py	2009-05-23 04:23:22 UTC (rev 100276)
+++ zope.app.publication/trunk/src/zope/app/publication/metadirectives.py	2009-05-23 05:09:37 UTC (rev 100277)
@@ -28,6 +28,7 @@
 
 from zope.interface import Interface
 from zope.configuration.fields import GlobalObject, Tokens
+from zope.configuration.fields import GlobalInterface
 from zope.schema import TextLine, Int
 
 class IRequestPublicationDirective(Interface):
@@ -61,3 +62,37 @@
         description=(u'A priority key used to concurrent'
                      ' publication factories.'),
         required=False)
+
+
+class IDefaultViewDirective(Interface):
+    """
+    The name of the view that should be the default.
+
+    This name refers to view that should be the
+    view used by default (if no view name is supplied
+    explicitly).
+    """
+
+    name = TextLine(
+        title=u"The name of the view that should be the default.",
+        description=u"""
+        This name refers to view that should be the view used by
+        default (if no view name is supplied explicitly).""",
+        required=True
+        )
+
+    for_ = GlobalObject(
+        title=u"The interface this view is the default for.",
+        description=u"""Specifies the interface for which the view is
+        registered. All objects implementing this interface can make use of
+        this view. If this attribute is not specified, the view is available
+        for all objects.""",
+        required=False
+        )
+
+    layer = GlobalInterface(
+        title=u"The layer the default view is declared for",
+        description=u"The default layer for which the default view is "
+                    u"applicable. By default it is applied to all layers.",
+        required=False
+        )

Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py	2009-05-23 04:23:22 UTC (rev 100276)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py	2009-05-23 05:09:37 UTC (rev 100277)
@@ -15,13 +15,117 @@
 
 $Id$
 """
-from unittest import main
+from cStringIO import StringIO
+from zope.component import queryMultiAdapter
+from zope.component.testfiles.views import IC
+from zope.configuration.xmlconfig import XMLConfig
+from zope.configuration.xmlconfig import xmlconfig
+from zope.interface import implements
+from zope.publisher.browser import TestRequest
+from zope.publisher.interfaces import IDefaultViewName
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.testing.cleanup import cleanUp
 from zope.testing.doctestunit import DocTestSuite
-from zope.component.testing import setUp, tearDown
+import unittest
 
+template = """<configure
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:browser='http://namespaces.zope.org/browser'
+   i18n_domain='zope'>
+   %s
+   </configure>"""
+
+
+class TestDefaultViewDirective(unittest.TestCase):
+
+    def setUp(self):
+        cleanUp()
+        import zope.app.publication
+        XMLConfig('meta.zcml', zope.app.publication)()
+
+    def tearDown(self):
+        cleanUp()
+
+    def testDefaultView(self):
+        ob = TestOb()
+        request = TestRequest()
+        self.assertEqual(
+            queryMultiAdapter((ob, request), IDefaultViewName), None)
+
+        xmlconfig(StringIO(template % (
+            '''
+            <browser:defaultView
+                name="test"
+                for="zope.component.testfiles.views.IC" />
+            '''
+            )))
+
+        from zope.app.publication.defaultview import getDefaultViewName
+        self.assertEqual(getDefaultViewName(ob, request), 'test')
+
+    def testDefaultViewWithLayer(self):
+        ob = TestOb()
+        request = TestRequest()
+        class FakeRequest(TestRequest):
+            implements(ITestLayer)
+        request2 = FakeRequest()
+
+        self.assertEqual(
+            queryMultiAdapter((ob, request2), IDefaultViewName), None)
+
+        xmlconfig(StringIO(template % (
+            '''
+            <browser:defaultView
+                name="test"
+                for="zope.component.testfiles.views.IC" />
+
+            <browser:defaultView
+                name="test2"
+                for="zope.component.testfiles.views.IC"
+                layer="
+                  zope.app.publication.tests.test_defaultview.ITestLayer"
+                />
+            '''
+            )))
+
+        from zope.app.publication.defaultview import getDefaultViewName
+        self.assertEqual(getDefaultViewName(ob, request2), 'test2')
+        self.assertEqual(getDefaultViewName(ob, request), 'test')
+
+    def testDefaultViewForClass(self):
+        ob = TestOb()
+        request = TestRequest()
+        self.assertEqual(
+            queryMultiAdapter((ob, request), IDefaultViewName), None)
+
+        xmlconfig(StringIO(template % (
+            '''
+            <browser:defaultView
+                for="zope.app.publication.tests.test_defaultview.TestOb"
+                name="test"
+                />
+            '''
+            )))
+
+        from zope.app.publication.defaultview import getDefaultViewName
+        self.assertEqual(getDefaultViewName(ob, request), 'test')
+
+
+class ITestLayer(IBrowserRequest):
+    """Test Layer."""
+
+class TestOb(object):
+    implements(IC)
+
+def cleanUpDoc(args):
+    cleanUp()
+
 def test_suite():
-    return DocTestSuite('zope.app.publication.defaultview',
-                        setUp=setUp, tearDown=tearDown)
+    return unittest.TestSuite([
+        DocTestSuite('zope.app.publication.defaultview',
+            setUp=cleanUpDoc, tearDown=cleanUpDoc),
+        unittest.makeSuite(TestDefaultViewDirective),
+        ])
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')



More information about the Checkins mailing list