[Checkins]
SVN: Products.GenericSetup/branches/1.4/Products/GenericSetup/
Update PropertyManagerHelpers to make it possible to remove
elements from a
Wichert Akkerman
wichert at wiggy.net
Tue Jul 8 06:56:07 EDT 2008
Log message for revision 88103:
Update PropertyManagerHelpers to make it possible to remove elements from a
property by adding a remove="True" attribute to the element. This can also be
used to reorder elements since new elements are always added at the end of the
list.
Changed:
U Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt
U Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/test_utils.py
U Products.GenericSetup/branches/1.4/Products/GenericSetup/utils.py
-=-
Modified: Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt 2008-07-08 10:33:28 UTC (rev 88102)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt 2008-07-08 10:56:06 UTC (rev 88103)
@@ -4,7 +4,10 @@
GenericSetup 1.4.2 (unreleased)
-------------------------------
- ...
+- Update PropertyManagerHelpers to make it possible to remove elements from a
+ property by adding a remove="True" attribute to the element. This can
+ also be used to reorder elements since new elements are always added
+ at the end of the list.
GenericSetup 1.4.1 (2008-05-27)
Modified: Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/test_utils.py
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/test_utils.py 2008-07-08 10:33:28 UTC (rev 88102)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/test_utils.py 2008-07-08 10:56:06 UTC (rev 88103)
@@ -157,6 +157,15 @@
</property>
</dummy>
"""
+_REMOVE_ELEMENT_IMPORT = """\
+<?xml version="1.0"?>
+<dummy>
+ <property name="lines1" purge="False">
+ <element value="Foo" remove="True" />
+ <element value="Bar" />
+ </property>
+</dummy>
+"""
_NORMAL_MARKER_EXPORT = """\
<?xml version="1.0"?>
@@ -415,7 +424,17 @@
self.assertEquals(obj.lines2, ('Foo', 'Bar'))
self.assertEquals(obj.lines3, ('Gee', 'Foo', 'Bar'))
+ def test_initProperties_remove_elements(self):
+ node = parseString(_REMOVE_ELEMENT_IMPORT).documentElement
+ self.helpers.environ._should_purge = False # extension profile
+ obj = self.helpers.context
+ obj._properties = ()
+ obj.manage_addProperty('lines1', ('Foo', 'Gee'), 'lines')
+ self.helpers._initProperties(node)
+ self.assertEquals(obj.lines1, ('Gee', 'Bar'))
+
+
class MarkerInterfaceHelpersTests(unittest.TestCase):
def _getTargetClass(self):
Modified: Products.GenericSetup/branches/1.4/Products/GenericSetup/utils.py
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/utils.py 2008-07-08 10:33:28 UTC (rev 88102)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/utils.py 2008-07-08 10:56:06 UTC (rev 88103)
@@ -729,14 +729,23 @@
if not 'w' in prop_map.get('mode', 'wd'):
raise BadRequest('%s cannot be changed' % prop_id)
- elements = []
+ new_elements = []
+ remove_elements = []
for sub in child.childNodes:
if sub.nodeName == 'element':
- value = sub.getAttribute('value')
- elements.append(value.encode(self._encoding))
+ value = sub.getAttribute('value').encode(self._encoding)
+ if self._convertToBoolean(sub.getAttribute('remove')
+ or 'False'):
+ remove_elements.append(value)
+ if value in new_elements:
+ new_elements.remove(value)
+ else:
+ new_elements.append(value)
+ if value in remove_elements:
+ remove_elements.remove(value)
- if elements or prop_map.get('type') == 'multiple selection':
- prop_value = tuple(elements) or ()
+ if new_elements or prop_map.get('type') == 'multiple selection':
+ prop_value = tuple(new_elements) or ()
elif prop_map.get('type') == 'boolean':
prop_value = self._convertToBoolean(self._getNodeText(child))
else:
@@ -750,7 +759,8 @@
prop = obj.getProperty(prop_id)
if isinstance(prop, (tuple, list)):
prop_value = (tuple([p for p in prop
- if p not in prop_value]) +
+ if p not in prop_value and
+ p not in remove_elements]) +
tuple(prop_value))
obj._updateProperty(prop_id, prop_value)
More information about the Checkins
mailing list