[Zope3-checkins] SVN: Zope3/trunk/ Resolved issue 285. applySkin()
is available under
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Sep 23 11:32:48 EDT 2004
Log message for revision 27661:
Resolved issue 285. applySkin() is available under
zope.app.publisher.browser.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/publisher/browser/__init__.py
A Zope3/trunk/src/zope/app/publisher/browser/tests/test_api.py
U Zope3/trunk/src/zope/app/traversing/namespace.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2004-09-23 14:57:33 UTC (rev 27660)
+++ Zope3/trunk/doc/CHANGES.txt 2004-09-23 15:32:47 UTC (rev 27661)
@@ -63,6 +63,11 @@
`interface`, which allows you to directly specify the skin's or
layer's interface instead of autogenerating it.
+ + Created function `applySkin(request, skin)`
+ (`zope.app.publisher.browser`) that allows you to assign a new skin
+ to a request. This effectively replaces the `setPresentationSkin()`
+ method.
+
- Added `apidoc:rootModule` directive, so that third-party products can
add their packages to the class browser documentation module.
Modified: Zope3/trunk/src/zope/app/publisher/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/__init__.py 2004-09-23 14:57:33 UTC (rev 27660)
+++ Zope3/trunk/src/zope/app/publisher/browser/__init__.py 2004-09-23 15:32:47 UTC (rev 27661)
@@ -15,9 +15,10 @@
$Id$
"""
-from zope.interface import implements
+from zope.interface import implements, directlyProvidedBy, directlyProvides
from zope.app.location import Location
from zope.app.publisher.interfaces.browser import IBrowserView
+from zope.publisher.interfaces.browser import ISkin
class BrowserView(Location):
implements(IBrowserView)
@@ -26,3 +27,38 @@
self.context = context
self.request = request
self.__parent__ = context
+
+
+def applySkin(request, skin):
+ """Change the presentation skin for this request.
+
+ >>> import pprint
+ >>> from zope.interface import Interface, providedBy
+ >>> class SkinA(Interface): pass
+ >>> directlyProvides(SkinA, ISkin)
+ >>> class SkinB(Interface): pass
+ >>> directlyProvides(SkinB, ISkin)
+ >>> class IRequest(Interface): pass
+
+ >>> class Request(object):
+ ... implements(IRequest)
+
+ >>> req = Request()
+
+ >>> applySkin(req, SkinA)
+ >>> pprint.pprint(list(providedBy(req).interfaces()))
+ [<InterfaceClass zope.app.publisher.browser.SkinA>,
+ <InterfaceClass zope.app.publisher.browser.IRequest>]
+
+ >>> applySkin(req, SkinB)
+ >>> pprint.pprint(list(providedBy(req).interfaces()))
+ [<InterfaceClass zope.app.publisher.browser.SkinB>,
+ <InterfaceClass zope.app.publisher.browser.IRequest>]
+ """
+ old_skins = [iface for iface in directlyProvidedBy(request)
+ if ISkin.providedBy(iface)]
+
+ for old_skin in old_skins:
+ directlyProvides(request, directlyProvidedBy(request) - old_skin)
+
+ directlyProvides(request, skin)
Added: Zope3/trunk/src/zope/app/publisher/browser/tests/test_api.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_api.py 2004-09-23 14:57:33 UTC (rev 27660)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_api.py 2004-09-23 15:32:47 UTC (rev 27661)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Browser API Tests
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+
+def test_suite():
+ return DocTestSuite('zope.app.publisher.browser')
+
+if __name__=='__main__':
+ unittest.main(defaultTest='test_suite')
Modified: Zope3/trunk/src/zope/app/traversing/namespace.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/namespace.py 2004-09-23 14:57:33 UTC (rev 27660)
+++ Zope3/trunk/src/zope/app/traversing/namespace.py 2004-09-23 15:32:47 UTC (rev 27661)
@@ -24,6 +24,7 @@
from zope.publisher.interfaces.browser import ISkin
from zope.security.proxy import removeSecurityProxy
+from zope.app.publisher.browser import applySkin
from zope.app.traversing.interfaces import ITraversable, IPathAdapter
class UnexpectedParameters(NotFoundError):
@@ -351,13 +352,7 @@
def traverse(self, name, ignored):
self.request.shiftNameToApplication()
skin = component.getUtility(ISkin, name)
- # Remove all existing skin declarations (commonly the default skin).
- ifaces = [iface
- for iface in directlyProvidedBy(self.request)
- if not ISkin.providedBy(iface)]
- # Add the new skin.
- ifaces.append(skin)
- directlyProvides(self.request, *ifaces)
+ applySkin(self.request, skin)
return self.context
class vh(view):
More information about the Zope3-Checkins
mailing list