[CMF-checkins] SVN: CMF/trunk/GenericSetup/ Now only a sequence property with the purge="False" attribute will be

Florent Guillaume fg at nuxeo.com
Mon Jan 16 13:05:09 EST 2006


Log message for revision 41332:
  Now only a sequence property with the purge="False" attribute will be
  left alone and not purged. The default is True even for extension
  profiles.
  
  This is so that extension profile defining new objects can be imported
  twice without having their sequence properties be doubled.
  
  

Changed:
  U   CMF/trunk/GenericSetup/CHANGES.txt
  U   CMF/trunk/GenericSetup/tests/test_utils.py
  U   CMF/trunk/GenericSetup/utils.py

-=-
Modified: CMF/trunk/GenericSetup/CHANGES.txt
===================================================================
--- CMF/trunk/GenericSetup/CHANGES.txt	2006-01-16 17:57:56 UTC (rev 41331)
+++ CMF/trunk/GenericSetup/CHANGES.txt	2006-01-16 18:05:08 UTC (rev 41332)
@@ -11,8 +11,8 @@
     - Forward ported changes from GenericSetup 0.11 and 0.12 (which were
       created in a separate repository).
 
-    - In extension profiles, sequence properties are now extended
-      instead of replaced, except if the 'purge' attribute is true.
+    - A sequence property with the purge="False" attribute will not be
+      purged. This is useful in extension profiles.
 
     - Don't export or purge read-only properties. Correctly purge
       non-deletable int/float properties.

Modified: CMF/trunk/GenericSetup/tests/test_utils.py
===================================================================
--- CMF/trunk/GenericSetup/tests/test_utils.py	2006-01-16 17:57:56 UTC (rev 41331)
+++ CMF/trunk/GenericSetup/tests/test_utils.py	2006-01-16 18:05:08 UTC (rev 41332)
@@ -130,6 +130,10 @@
   <element value="Foo"/>
   <element value="Bar"/>
  </property>
+ <property name="lines3" purge="False">
+  <element value="Foo"/>
+  <element value="Bar"/>
+ </property>
 </dummy>
 """
 
@@ -335,19 +339,35 @@
 
         self.assertEqual(doc.toprettyxml(' '), _EMPTY_PROPERTY_EXPORT)
 
-    def test__initProperties_nopurge(self):
+    def test__initProperties_nopurge_base(self):
         node = parseString(_NOPURGE_IMPORT).documentElement
-        self.helpers.environ._should_purge = False
+        self.helpers.environ._should_purge = True # base profile
         obj = self.helpers.context
         obj._properties = ()
         obj.manage_addProperty('lines1', ('A', 'B'), 'lines')
         obj.manage_addProperty('lines2', ('A', 'B'), 'lines')
+        obj.manage_addProperty('lines3', ('A', 'B'), 'lines')
         self.helpers._initProperties(node)
 
-        self.assertEquals(obj.lines1, ('A', 'B', 'Foo', 'Bar'))
+        self.assertEquals(obj.lines1, ('Foo', 'Bar'))
         self.assertEquals(obj.lines2, ('Foo', 'Bar'))
+        self.assertEquals(obj.lines3, ('A', 'B', 'Foo', 'Bar'))
 
+    def test__initProperties_nopurge_extension(self):
+        node = parseString(_NOPURGE_IMPORT).documentElement
+        self.helpers.environ._should_purge = False # extension profile
+        obj = self.helpers.context
+        obj._properties = ()
+        obj.manage_addProperty('lines1', ('A', 'B'), 'lines')
+        obj.manage_addProperty('lines2', ('A', 'B'), 'lines')
+        obj.manage_addProperty('lines3', ('A', 'B'), 'lines')
+        self.helpers._initProperties(node)
 
+        self.assertEquals(obj.lines1, ('Foo', 'Bar'))
+        self.assertEquals(obj.lines2, ('Foo', 'Bar'))
+        self.assertEquals(obj.lines3, ('A', 'B', 'Foo', 'Bar'))
+
+
 class PrettyDocumentTests(unittest.TestCase):
 
     def test_attr_quoting(self):

Modified: CMF/trunk/GenericSetup/utils.py
===================================================================
--- CMF/trunk/GenericSetup/utils.py	2006-01-16 17:57:56 UTC (rev 41331)
+++ CMF/trunk/GenericSetup/utils.py	2006-01-16 18:05:08 UTC (rev 41332)
@@ -686,11 +686,8 @@
                 # are converted to the right type
                 prop_value = self._getNodeText(child).encode('utf-8')
 
-            purge = self.environ.shouldPurge()
-            if child.hasAttribute('purge'):
-                purge = self._convertToBoolean(child.getAttribute('purge'))
-            if not purge:
-                # If not purge mode, append to sequence
+            if not self._convertToBoolean(child.getAttribute('purge') or 'True'):
+                # If the purge attribute is false, append to sequence
                 prop = obj.getProperty(prop_id)
                 if isinstance(prop, (tuple, list)):
                     prop_value = tuple(prop) + tuple(prop_value)



More information about the CMF-checkins mailing list