[CMF-checkins] SVN: CMF/branches/1.5/C Added 'skinname' to the
thread-specific tuple created by the Skinnable base class to
cache the skin path lookup.
Tres Seaver
tseaver at palladion.com
Sat Nov 5 16:39:56 EST 2005
Log message for revision 39938:
Added 'skinname' to the thread-specific tuple created by the Skinnable base class to cache the skin path lookup.
This name facilitates later querying. Added a 'getCurrentSkinName' to the
Skinnable API to do the query.
Thanks to Laurent Rowe for the patch.
Changed:
U CMF/branches/1.5/CHANGES.txt
U CMF/branches/1.5/CMFCore/Skinnable.py
U CMF/branches/1.5/CMFCore/tests/test_SkinsTool.py
-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt 2005-11-05 20:32:11 UTC (rev 39937)
+++ CMF/branches/1.5/CHANGES.txt 2005-11-05 21:39:56 UTC (rev 39938)
@@ -16,6 +16,11 @@
Features
+ - CMFCore: added 'skinname' to the thread-specific tuple created by
+ the Skinnable base class to cache the skin path lookup, to facilitate
+ querying later; added a 'getCurrentSkinName' to the Skinnable API
+ to do the query. Thanks to Laurent Rowe for the patch.
+
- CMFSetup: added support for importing and exporting workflow script
metadata for scripts that are External Methods. One very important
difference to other scripts remains: Since the CMFSetup machinery
Modified: CMF/branches/1.5/CMFCore/Skinnable.py
===================================================================
--- CMF/branches/1.5/CMFCore/Skinnable.py 2005-11-05 20:32:11 UTC (rev 39937)
+++ CMF/branches/1.5/CMFCore/Skinnable.py 2005-11-05 21:39:56 UTC (rev 39938)
@@ -40,7 +40,7 @@
_marker = [] # Create a new marker object.
-SKINDATA = {} # mapping thread-id -> (skinobj, ignore, resolve)
+SKINDATA = {} # mapping thread-id -> (skinobj, skinname, ignore, resolve)
class SkinDataCleanup:
"""Cleanup at the end of the request."""
@@ -71,7 +71,7 @@
if not name.startswith('_') and not name.startswith('aq_'):
sd = SKINDATA.get(get_ident())
if sd is not None:
- ob, ignore, resolve = sd
+ ob, skinname, ignore, resolve = sd
if not ignore.has_key(name):
if resolve.has_key(name):
return resolve[name]
@@ -126,11 +126,29 @@
skinobj = self.getSkin(skinname)
if skinobj is not None:
tid = get_ident()
- SKINDATA[tid] = (skinobj, {}, {})
+ SKINDATA[tid] = (skinobj, skinname, {}, {})
REQUEST = getattr(self, 'REQUEST', None)
if REQUEST is not None:
REQUEST._hold(SkinDataCleanup(tid))
+ security.declarePublic('getCurrentSkinName')
+ def getCurrentSkinName(self):
+ '''Return the current skin name.
+ '''
+ sd = SKINDATA.get(get_ident())
+ if sd is not None:
+ ob, skinname, ignore, resolve = sd
+ if skinname is not None:
+ return skinname
+ # nothing here, so assume the default skin
+ sfn = self.getSkinsFolderName()
+ if sfn is not None:
+ sf = getattr(self, sfn, None)
+ if sf is not None:
+ return sf.getDefaultSkin()
+ # and if that fails...
+ return None
+
security.declarePublic('clearCurrentSkin')
def clearCurrentSkin(self):
"""Clear the current skin."""
Modified: CMF/branches/1.5/CMFCore/tests/test_SkinsTool.py
===================================================================
--- CMF/branches/1.5/CMFCore/tests/test_SkinsTool.py 2005-11-05 20:32:11 UTC (rev 39937)
+++ CMF/branches/1.5/CMFCore/tests/test_SkinsTool.py 2005-11-05 21:39:56 UTC (rev 39938)
@@ -102,10 +102,47 @@
self.failUnless(paths.find('.svn') == -1)
+class SkinnableTests(TestCase):
+
+ def _makeOne(self):
+ from Products.CMFCore.SkinsTool import SkinsTool
+ from Products.CMFCore.Skinnable import SkinnableObjectManager
+
+ class TestSkinnableObjectManager(SkinnableObjectManager):
+ tool = SkinsTool()
+ # This is needed otherwise REQUEST is the string
+ # '<Special Object Used to Force Acquisition>'
+ REQUEST = None
+ def getSkinsFolderName(self):
+ '''tool'''
+ return 'tool'
+
+ return TestSkinnableObjectManager()
+
+ def test_getCurrentSkinName(self):
+ som = self._makeOne()
+
+ pathA = ('foo, bar')
+ pathB = ('bar, foo')
+
+ som.tool.addSkinSelection('skinA', pathA)
+ som.tool.addSkinSelection('skinB', pathB)
+
+ som.tool.manage_properties(default_skin='skinA')
+
+ # Expect the default skin name to be returned
+ self.failUnless(som.getCurrentSkinName() == 'skinA')
+
+ # after a changeSkin the new skin name should be returned
+ som.changeSkin('skinB')
+ self.failUnless(som.getCurrentSkinName() == 'skinB')
+
+
def test_suite():
return TestSuite((
makeSuite(SkinsContainerTests),
makeSuite(SkinsToolTests),
+ makeSuite(SkinnableTests),
))
if __name__ == '__main__':
More information about the CMF-checkins
mailing list