[Checkins] SVN: zope.app.publisher/trunk/ Changed my mind: put the <browser:defaultView> handler back in zope.app.publisher, but moved the defaultview API to zope.publisher.
Shane Hathaway
shane at hathawaymix.org
Sat May 23 02:03:28 EDT 2009
Log message for revision 100280:
Changed my mind: put the <browser:defaultView> handler back in zope.app.publisher, but moved the defaultview API to zope.publisher.
Changed:
U zope.app.publisher/trunk/CHANGES.txt
U zope.app.publisher/trunk/setup.py
U zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py
D zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py
U zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml
U zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py
U zope.app.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py
U zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py
-=-
Modified: zope.app.publisher/trunk/CHANGES.txt
===================================================================
--- zope.app.publisher/trunk/CHANGES.txt 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/CHANGES.txt 2009-05-23 06:03:27 UTC (rev 100280)
@@ -12,9 +12,9 @@
zope.app.publisher -> zope.app.publication dependency (which was a
cycle).
-- Moved the <browser:defaultView> directive handler to
- zope.app.publication, since zope.app.publication is what
- uses the registration.
+- 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-22)
==================
Modified: zope.app.publisher/trunk/setup.py
===================================================================
--- zope.app.publisher/trunk/setup.py 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/setup.py 2009-05-23 06:03:27 UTC (rev 100280)
@@ -52,11 +52,11 @@
'zope.interface',
'zope.location',
'zope.pagetemplate',
- 'zope.publisher',
+ 'zope.publisher>=3.8.0',
'zope.schema',
'zope.site',
'zope.security',
- 'zope.traversing >= 3.7.0',
+ 'zope.traversing>=3.7.0',
'zope.componentvocabulary',
'zope.browser',
],
Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py 2009-05-23 06:03:27 UTC (rev 100280)
@@ -24,9 +24,9 @@
import zope.deferredimport
zope.deferredimport.deprecatedFrom(
- "This import has moved to zope.app.publication.defaultview. "
+ "This import has moved to zope.publisher.defaultview. "
"This import will stop working in the future.",
- 'zope.app.publisher.browser._defaultview',
+ 'zope.publisher.defaultview',
'IDefaultViewNameAPI',
'getDefaultViewName',
'queryDefaultViewName',
Deleted: zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py 2009-05-23 06:03:27 UTC (rev 100280)
@@ -1,94 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""Deprecated copy of zope.app.publication.defaultview.
-
-Use zope.app.publication.defaultview instead!
-
-$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.
- """
-
-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.app.publisher.browser._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
Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml 2009-05-23 06:03:27 UTC (rev 100280)
@@ -70,6 +70,13 @@
</meta:complexDirective>
+ <meta:directive
+ name="defaultView"
+ schema=".metadirectives.IDefaultViewDirective"
+ handler=".metaconfigure.defaultView"
+ />
+
+
<!-- browser pages -->
<meta:directive
Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py 2009-05-23 06:03:27 UTC (rev 100280)
@@ -19,7 +19,9 @@
import warnings
from zope import component
+from zope.component.interface import provideInterface
from zope.component.zcml import handler
+from zope.publisher.interfaces import IDefaultViewName
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces.browser import IBrowserSkinType
from zope.publisher.interfaces.browser import IDefaultSkin
@@ -60,3 +62,19 @@
callable = setDefaultSkin,
args = (name, _context.info)
)
+
+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.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py 2009-05-23 06:03:27 UTC (rev 100280)
@@ -148,6 +148,39 @@
required=True
)
+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
+ )
+
#
# browser pages
#
Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2009-05-23 06:00:45 UTC (rev 100279)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2009-05-23 06:03:27 UTC (rev 100280)
@@ -28,6 +28,7 @@
from zope.configuration.xmlconfig import xmlconfig, XMLConfig
from zope.configuration.exceptions import ConfigurationError
from zope.publisher.browser import TestRequest
+from zope.publisher.interfaces import IDefaultViewName
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces.browser import IBrowserSkinType, IDefaultSkin
@@ -38,6 +39,7 @@
from zope.traversing.adapters import DefaultTraversable
from zope.traversing.interfaces import ITraversable
+import zope.publisher.defaultview
import zope.app.publisher.browser
from zope.component.testfiles.views import IC, V1, VZMI, R1, IV
from zope.app.publisher.browser.fileresource import FileResource
@@ -301,6 +303,73 @@
v = component.queryMultiAdapter((ob, request), name='test')
self.assertEqual(v(), "<html><body><p>test</p></body></html>\n")
+ def testDefaultView(self):
+ self.assertEqual(
+ component.queryMultiAdapter((ob, request), IDefaultViewName),
+ None)
+
+ xmlconfig(StringIO(template % (
+ '''
+ <browser:defaultView
+ name="test"
+ for="zope.component.testfiles.views.IC" />
+ '''
+ )))
+
+ self.assertEqual(
+ zope.publisher.defaultview.getDefaultViewName(ob, request),
+ 'test')
+
+ def testDefaultViewWithLayer(self):
+ class FakeRequest(TestRequest):
+ implements(ITestLayer)
+ request2 = FakeRequest()
+
+ self.assertEqual(
+ component.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.publisher.browser.tests.test_directives.ITestLayer"
+ />
+ '''
+ )))
+
+ self.assertEqual(
+ zope.publisher.defaultview.getDefaultViewName(ob, request2),
+ 'test2')
+ self.assertEqual(
+ zope.publisher.defaultview.getDefaultViewName(ob, request),
+ 'test')
+
+ def testDefaultViewForClass(self):
+ self.assertEqual(
+ component.queryMultiAdapter((ob, request), IDefaultViewName),
+ None)
+
+ xmlconfig(StringIO(template % (
+ '''
+ <browser:defaultView
+ for="zope.app.publisher.browser.tests.test_directives.Ob"
+ name="test"
+ />
+ '''
+ )))
+
+ self.assertEqual(
+ zope.publisher.defaultview.getDefaultViewName(ob, request),
+ 'test')
+
+
def testSkinResource(self):
self.assertEqual(
component.queryAdapter(Request(IV), name='test'), None)
More information about the Checkins
mailing list