ArchGenXML: Uncatalog tools

Jean Rodrigo Ferri <jeanrodrigoferri-/E1597aS9LRfJ/[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.devel
Message-ID <[email protected]>
Hi,

I was implementing something to automatically uncatalog windowZ tool. 
But I thought the best way is to implement this feature in ArchGenXML to 
automatically uncatalog all generated tools.

So I implemented this into ArchGenXML and I would like to know what you 
think about it. Should I commit this attached patch?

I think, tools should not be catalogued, mainly because Plone 2.1 
displays objects in folder_contents from catalog, so tools are displayed 
too.

Regards,

-- 
Jean Ferri
archgenxml.diff (text/plain, 3.7 KB)
Index: codesnippets.py
===================================================================
--- codesnippets.py	(revisão 6265)
+++ codesnippets.py	(cópia de trabalho)
@@ -272,6 +272,12 @@
         self.setTitle('%s')
         """
 
+TEMPL_POST_EDIT_METHOD_TOOL = """
+    # tool should not appear in portal_catalog
+    def at_post_edit_script(self):
+        self.unindexObject()
+        """
+
 TEMPLATE_HEADER = """\
 from AccessControl import ClassSecurityInfo
 from Products.Archetypes.atapi import *
Index: templates/Install.py
===================================================================
--- templates/Install.py	(revisão 6265)
+++ templates/Install.py	(cópia de trabalho)
@@ -113,7 +113,7 @@
 </dtml-if>
 <dtml-let autoinstall_tools="[c.getName() for c in generator.getGeneratedTools(package) if not utils.isTGVFalse(c.getTaggedValue('autoinstall')) ]">
 <dtml-if "autoinstall_tools">
-    #autoinstall tools
+    # autoinstall tools
     portal = getToolByName(self,'portal_url').getPortalObject()
     for t in <dtml-var "repr(autoinstall_tools)">:
         try:
@@ -126,11 +126,19 @@
             e = sys.exc_info()
             if e[0] != 'Bad Request':
                 raise
+
 </dtml-if>
 </dtml-let>
 <dtml-let all_tools="[c for c in generator.getGeneratedTools(package)]">
 <dtml-if "all_tools">
-    #hide tools in the navigation
+    # uncatalog tools
+    for toolname in <dtml-var "[t.getTaggedValue('tool_instance_name') or 'portal_%s' % t.getName().lower() for t in all_tools]">:
+        try:
+            portal[toolname].unindexObject()
+        except:
+            pass
+
+    # hide tools in the navigation
     portalProperties = getToolByName(self, 'portal_properties', None)
     if portalProperties is not None:
         navtreeProperties = getattr(portalProperties, 'navtree_properties', None)
Index: ArchetypesGenerator.py
===================================================================
--- ArchetypesGenerator.py	(revisão 6265)
+++ ArchetypesGenerator.py	(cópia de trabalho)
@@ -1583,6 +1583,13 @@
         if element.hasStereoType(self.portal_tools, umlprofile=self.uml_profile) and '__init__' not in method_names:
             method_names.append('__init__')
 
+        #as __init__ above if at_post_edit_script has to be generated for tools
+        #I want _not_ at_post_edit_script to be preserved (hacky but works)
+        #if it is added to method_names it wont be recognized as a manual method
+        if element.hasStereoType(self.portal_tools, umlprofile=self.uml_profile) \
+           and 'at_post_edit_script' not in method_names:
+            method_names.append('at_post_edit_script')
+
         if self.method_preservation:
             log.debug("We are to preserve methods, so we're looking for manual methods.")
             cl = self.parsed_class_sources.get(element.getPackage().getFilePath()+'/'+element.name, None)
@@ -2238,13 +2245,16 @@
 
         self.generateProtectedSection(outfile, element, 'class-header', 1)
 
-        # tool __init__
+        # tool __init__ and at_post_edit_script
         if element.hasStereoType(self.portal_tools, umlprofile=self.uml_profile):
             tool_instance_name = element.getTaggedValue('tool_instance_name') \
                                  or 'portal_%s' % element.getName().lower()
             print >> outfile, TEMPL_CONSTR_TOOL % (baseclass,tool_instance_name,archetype_name)
             self.generateProtectedSection(outfile, element,
                                           'constructor-footer', 2)
+            print >> outfile, TEMPL_POST_EDIT_METHOD_TOOL
+            self.generateProtectedSection(outfile, element,
+                                          'post-edit-method-footer', 2)
             print >> outfile
 
         self.generateMethods(outfile, element)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.