Hi,
A while ago I proposed to add the possibility to say in GenericSetup's
catalog.xml that an index should be removed. This has been added to
the code already.
Now I propose to do the same for metadata columns. So the following
should remove the column from the catalog:
I do most of my testing on Plone 2.5, so we are talking GenericSetup
branch 1.2 here. The code below ought to do it. I added test code
for this. And I added some comments to the test to clarify how the
testing is done, as I find myself wondering about that every time I
look at the current test code. :)
If this diff is good, can someone commit it? I have no rights.
[EMAIL PROTECTED]:~/svn/plone25-zope29/GenericSetup $ svn diff
Index: ZCatalog/tests/test_exportimport.py
===
--- ZCatalog/tests/test_exportimport.py (revision 75759)
+++ ZCatalog/tests/test_exportimport.py (working copy)
@@ -62,7 +62,7 @@
-
+%s
"""
@@ -78,17 +78,33 @@
+
+
"""
+# START SITUATION
+#
+# The catalog starts out as the _CATALOG_BODY above with the following
+# xml snippets inserted.
+
+_VOCABULARY_XML = """\
+
+"""
+
_TEXT_XML = """\
"""
-_VOCABULARY_XML = """\
-
+_COLUMN_XML = """\
+
"""
+# END SITUATION
+#
+# The catalog ends as the _CATALOG_BODY above with the following
+# xml snippets and some empty strings inserted.
+
_ZCTEXT_XML = """\
@@ -97,7 +113,6 @@
"""
-
class ZCatalogXMLAdapterTests(BodyAdapterTestCase):
def _getTargetClass(self):
@@ -151,6 +166,7 @@
self._populate(self._obj)
obj._setObject('foo_vocabulary', Vocabulary('foo_vocabulary'))
obj.addIndex('foo_text', 'TextIndex')
+obj.addColumn('bacon')
def setUp(self):
import Products.GenericSetup.PluginIndexes
@@ -165,22 +181,24 @@
zcml.load_config('configure.zcml', Products.GenericSetup.ZCTextIndex)
self._obj = ZCatalog('foo_catalog')
-self._BODY = _CATALOG_BODY % ('', '')
+self._BODY = _CATALOG_BODY % ('', '', '')
def test_body_get_special(self):
+# Assert that the catalog starts out the way we expect it to.
self._populate_special(self._obj)
context = DummySetupEnviron()
adapted = getMultiAdapter((self._obj, context), IBody)
self.assertEqual(adapted.body,
- _CATALOG_BODY % (_VOCABULARY_XML, _TEXT_XML))
+ _CATALOG_BODY % (_VOCABULARY_XML, _TEXT_XML,
_COLUMN_XML))
def test_body_set_update(self):
+# Assert that the catalog ends up the way we expect it to.
self._populate_special(self._obj)
context = DummySetupEnviron()
context._should_purge = False
adapted = getMultiAdapter((self._obj, context), IBody)
adapted.body = _CATALOG_UPDATE_BODY
-self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML))
+self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML, ''))
def test_suite():
Index: ZCatalog/exportimport.py
===
--- ZCatalog/exportimport.py(revision 75759)
+++ ZCatalog/exportimport.py(working copy)
@@ -137,5 +137,10 @@
if child.nodeName != 'column':
continue
col = str(child.getAttribute('value'))
+if child.hasAttribute('remove'):
+# Remove the column if it is there
+if col in self.context.schema()[:]:
+self.context.delColumn(col)
+continue
if col not in self.context.schema()[:]:
self.context.addColumn(col)
--
Maurits van Rees | http://maurits.vanrees.org/ [NL]
Work | http://zestsoftware.nl/
"Do not worry about your difficulties in computers,
I can assure you mine are still greater."
___
Zope-CMF maillist - Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf
See http://collector.zope.org/CMF for bug reports and feature requests