[Checkins] SVN: CMF/trunk/CMFCore/exportimport/ Add support for a 'based-on' attribute for <skin-path> elements in skins.xml.

Wichert Akkerman wichert at wiggy.net
Wed Jan 31 10:28:30 EST 2007


Log message for revision 72278:
  Add support for a 'based-on' attribute for <skin-path> elements in skins.xml.
  Patch from http://www.zope.org/Collectors/CMF/464
  

Changed:
  U   CMF/trunk/CMFCore/exportimport/skins.py
  U   CMF/trunk/CMFCore/exportimport/tests/test_skins.py

-=-
Modified: CMF/trunk/CMFCore/exportimport/skins.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/skins.py	2007-01-31 15:02:20 UTC (rev 72277)
+++ CMF/trunk/CMFCore/exportimport/skins.py	2007-01-31 15:28:29 UTC (rev 72278)
@@ -132,10 +132,25 @@
                     path = self._updatePath(path, child)
                     self.context.addSkinSelection(path_id, path)
             else:
+                path = ''
+                if child.hasAttribute('based-on'):
+                    try:
+                        basename = child.getAttribute('based-on')
+                        path = self.context._getSelections()[basename]
+                    except KeyError:
+                        pass
                 if path_id in self.context._getSelections():
-                    path = self.context._getSelections()[path_id]
-                else:
-                    path = ''
+                    oldpath = self.context._getSelections()[path_id].split(',')
+                    for layer in oldpath:
+                        if layer not in path:
+                            layernode = self._doc.createElement('layer')
+                            layernode.setAttribute('name', layer)
+                            if oldpath.index(layer) == 0:
+                                layernode.setAttribute('insert-before', '*')
+                            else:
+                                pos = oldpath[oldpath.index(layer)-1]
+                                layernode.setAttribute('insert-after', pos)
+                            child.appendChild(layernode)
                 path = self._updatePath(path, child)
                 self.context.addSkinSelection(path_id, path)
         #

Modified: CMF/trunk/CMFCore/exportimport/tests/test_skins.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/tests/test_skins.py	2007-01-31 15:02:20 UTC (rev 72277)
+++ CMF/trunk/CMFCore/exportimport/tests/test_skins.py	2007-01-31 15:28:29 UTC (rev 72278)
@@ -125,7 +125,20 @@
 </object>
 """
 
+_FRAGMENT5_IMPORT = """\
+<?xml version="1.0"?>
+<object name="portal_skins" meta_type="Dummy Skins Tool">
+ <skin-path name="existing" based-on="basic">
+ </skin-path>
+ <skin-path name="new" based-on="basic">
+  <layer name="two" insert-before="three"/>
+ </skin-path>
+ <skin-path name="wrongbase" based-on="invalid_base_id">
+  <layer name="two" insert-before="three"/>
+ </skin-path>
+</object>"""
 
+
 class DummySite(Folder):
 
     _skin_setup_called = False
@@ -317,6 +330,7 @@
     _FRAGMENT2_IMPORT = _FRAGMENT2_IMPORT
     _FRAGMENT3_IMPORT = _FRAGMENT3_IMPORT
     _FRAGMENT4_IMPORT = _FRAGMENT4_IMPORT
+    _FRAGMENT5_IMPORT = _FRAGMENT5_IMPORT
     _NORMAL_EXPORT = _NORMAL_EXPORT
 
     def test_empty_default_purge(self):
@@ -531,7 +545,36 @@
         self.assertEqual(skin_paths[1], ('fancy', 'two,one,four'))
         self.assertEqual(len(skins_tool.objectItems()), 4)
 
+    def test_fragment5_based_skin(self):
+        from Products.CMFCore.exportimport.skins import importSkinsTool
 
+        _IDS = ('one', 'two', 'three', 'four')
+        _PATHS = {'basic': 'one,three,four', 'existing': 'one,two,four'}
+
+        site = self._initSite(selections=_PATHS, ids=_IDS)
+        skins_tool = site.portal_skins
+
+        skin_paths = skins_tool.getSkinPaths()
+        self.assertEqual(len(skin_paths), 2)
+        self.assertEqual(skin_paths[0], ('basic', 'one,three,four'))
+        self.assertEqual(skin_paths[1], ('existing', 'one,two,four'))
+        self.assertEqual(len(skins_tool.objectItems()), 4)
+
+        context = DummyImportContext(site, False)
+        context._files['skins.xml'] = self._FRAGMENT5_IMPORT
+
+        importSkinsTool(context)
+
+        self.failUnless(site._skin_setup_called)
+        skin_paths = skins_tool.getSkinPaths()
+        self.assertEqual(len(skin_paths), 4)
+        self.assertEqual(skin_paths[0], ('basic', 'one,three,four'))
+        self.assertEqual(skin_paths[1], ('existing', 'one,two,three,four'))
+        self.assertEqual(skin_paths[2], ('new', 'one,two,three,four'))
+        self.assertEqual(skin_paths[3], ('wrongbase', 'two'))
+        self.assertEqual(len(skins_tool.objectItems()), 4)
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(DirectoryViewAdapterTests),



More information about the Checkins mailing list