[Zope-CMF] GenericSetup: remove columns from catalog.xml
Maurits van Rees
m.van.rees at zestsoftware.nl
Tue May 15 10:59:15 EDT 2007
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:
<column value="outdatedColumn" remove="True" />
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.
maurits at kronos:~/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 @@
<extra name="index_type" value="Okapi BM25 Rank"/>
<extra name="lexicon_id" value="foo_plexicon"/>
</index>
- <column value="eggs"/>
+%s <column value="eggs"/>
<column value="spam"/>
</object>
"""
@@ -78,17 +78,33 @@
<extra name="lexicon_id" value="foo_plexicon"/>
</index>
<index name="non_existing" remove="True"/>
+ <column value="non_existing" remove="True"/>
+ <column value="bacon" remove="True"/>
</object>
"""
+# START SITUATION
+#
+# The catalog starts out as the _CATALOG_BODY above with the following
+# xml snippets inserted.
+
+_VOCABULARY_XML = """\
+ <object name="foo_vocabulary" meta_type="Vocabulary" deprecated="True"/>
+"""
+
_TEXT_XML = """\
<index name="foo_text" meta_type="TextIndex" deprecated="True"/>
"""
-_VOCABULARY_XML = """\
- <object name="foo_vocabulary" meta_type="Vocabulary" deprecated="True"/>
+_COLUMN_XML = """\
+ <column value="bacon"/>
"""
+# END SITUATION
+#
+# The catalog ends as the _CATALOG_BODY above with the following
+# xml snippets and some empty strings inserted.
+
_ZCTEXT_XML = """\
<index name="foo_text" meta_type="ZCTextIndex">
<indexed_attr value="foo_text"/>
@@ -97,7 +113,6 @@
</index>
"""
-
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."
More information about the Zope-CMF
mailing list