[Checkins] SVN: zope.publisher/trunk/ Moved the default view API to zope.publisher to make

Shane Hathaway shane at hathawaymix.org
Sat May 23 02:00:46 EDT 2009


Log message for revision 100279:
  Moved the default view API to zope.publisher to make
  the API accessible to packages that need it
  

Changed:
  U   zope.publisher/trunk/CHANGES.txt
  A   zope.publisher/trunk/src/zope/publisher/defaultview.py
  A   zope.publisher/trunk/src/zope/publisher/tests/test_defaultview.py

-=-
Modified: zope.publisher/trunk/CHANGES.txt
===================================================================
--- zope.publisher/trunk/CHANGES.txt	2009-05-23 05:13:22 UTC (rev 100278)
+++ zope.publisher/trunk/CHANGES.txt	2009-05-23 06:00:45 UTC (rev 100279)
@@ -8,6 +8,10 @@
   zope.app.http to zope.publisher.interfaces.http, fixing dependency
   cycles involving zope.app.http.
 
+- Moved the DefaultViewName API from zope.app.publisher.browser to
+  zope.publisher.defaultview, making it accessible to other packages
+  that need it.
+
 3.7.0 (2009-05-13)
 ------------------
 

Copied: zope.publisher/trunk/src/zope/publisher/defaultview.py (from rev 100276, zope.app.publication/trunk/src/zope/app/publication/defaultview.py)
===================================================================
--- zope.publisher/trunk/src/zope/publisher/defaultview.py	                        (rev 0)
+++ zope.publisher/trunk/src/zope/publisher/defaultview.py	2009-05-23 06:00:45 UTC (rev 100279)
@@ -0,0 +1,92 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Default view name API
+
+$Id$
+"""
+from zope.component.interfaces import ComponentLookupError
+from zope.component import getSiteManager
+
+import zope.interface
+from zope.publisher.interfaces import IDefaultViewName
+
+
+class IDefaultViewNameAPI(zope.interface.Interface):
+
+    def getDefaultViewName(object, request, context=None):
+        """Get the name of the default view for the object and request.
+
+        If a matching default view name cannot be found, raises
+        ComponentLookupError.
+
+        If context is not specified, attempts to use
+        object to specify a context.
+        """
+
+    def queryDefaultViewName(object, request, default=None, context=None):
+        """Look for the name of the default view for the object and request.
+
+        If a matching default view name cannot be found, returns the default.
+
+        If context is not specified, attempts to use object to specify
+        a context.
+        """
+
+# TODO: needs tests
+def getDefaultViewName(object, request, context=None):
+    name = queryDefaultViewName(object, request, context=context)
+    if name is not None:
+        return name
+    raise ComponentLookupError("Couldn't find default view name",
+                               context, request)
+
+def queryDefaultViewName(object, request, default=None, context=None):
+    """
+    query the default view for a given object and request.
+
+      >>> from zope.publisher.defaultview import queryDefaultViewName
+
+    lets create an object with a default view.
+
+      >>> import zope.interface
+      >>> class IMyObject(zope.interface.Interface):
+      ...   pass
+      >>> class MyObject(object):
+      ...   zope.interface.implements(IMyObject)
+      >>> queryDefaultViewName(MyObject(), object()) is None
+      True
+
+    Now we can will set a default view.
+
+      >>> import zope.component
+      >>> import zope.publisher.interfaces
+      >>> zope.component.provideAdapter('name',
+      ...     adapts=(IMyObject, zope.interface.Interface),
+      ...     provides=zope.publisher.interfaces.IDefaultViewName)
+      >>> queryDefaultViewName(MyObject(), object())
+      'name'
+
+    This also works if the name is empty
+
+      >>> zope.component.provideAdapter('',
+      ...     adapts=(IMyObject, zope.interface.Interface),
+      ...     provides=zope.publisher.interfaces.IDefaultViewName)
+      >>> queryDefaultViewName(MyObject(), object())
+      ''
+    """
+    name = getSiteManager(context).adapters.lookup(
+        map(zope.interface.providedBy, (object, request)), IDefaultViewName)
+    if name is None:
+        return default
+    return name


Property changes on: zope.publisher/trunk/src/zope/publisher/defaultview.py
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: zope.publisher/trunk/src/zope/publisher/tests/test_defaultview.py (from rev 100277, zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py)
===================================================================
--- zope.publisher/trunk/src/zope/publisher/tests/test_defaultview.py	                        (rev 0)
+++ zope.publisher/trunk/src/zope/publisher/tests/test_defaultview.py	2009-05-23 06:00:45 UTC (rev 100279)
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+"""Default View Tests
+
+$Id$
+"""
+import unittest
+from zope.testing.cleanup import cleanUp
+from zope.testing.doctestunit import DocTestSuite
+
+def cleanUpDoc(args):
+    cleanUp()
+
+def test_suite():
+    return DocTestSuite('zope.publisher.defaultview',
+            setUp=cleanUpDoc, tearDown=cleanUpDoc)
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: zope.publisher/trunk/src/zope/publisher/tests/test_defaultview.py
___________________________________________________________________
Added: svn:mergeinfo
   + 



More information about the Checkins mailing list