[Zope-PTK] Tools

Lucas Hofman lucas.hofman@oslo.pgs.com
Mon, 15 Jan 2001 14:07:31 +0100


Shane Hathaway wrote:
> 
> Lucas Hofman wrote:
> >
> > Shane Hathaway wrote:
> > >...  Or you can write a product that subclasses portal tools or
> > > even ignores the standard base classes while implementing all the
> > > required methods.
> > >
> > Do you have an example on how to do this? I find it difficult to see the
> > whole picture.
> 
> I see what you're saying now.  You'd simply create another product with
> some of the following code:
> 
> from Products.PTKBase.CatalogTool import CatalogTool
> from Products.PTKBase.PortalObject import PortalObject
> 
> class HofmanCatalogTool(CatalogTool):
> 
>   def __init__(self):
>     CatalogTool.__init__(self)
>     # Add my own indices
> 
> class HofmanPortal(PortalObject):
>   # Add code here which instantiates a HofmanCatalogTool
>   # instead of a CatalogTool.
> 
Shane, it does not work:

I created a file called demoCatalogTool in PTKDemo which has the
followingcontent:
from Products.PTKBase.CatalogTool import CatalogTool
from Products.PTKBase.PortalObject import PortalObjectBase

class DemoCatalogTaol (CatalogTool):

    def __init__(self):
        CatalogTool.__init__(self)
        # add all Seres indexes
        self._catalog.addIndex('Project', 'FieldIndex')
        self._catalog.addIndex('Consortium', 'FieldIndex')
        self._catalog.addIndex('NotOnMainPage', 'FieldIndex')
        # add meta data
        self._catalog.addColumn('eventDate') 

in Portalobject only PortalObjectBase exists. 


Changed __init__.py:
..
import PropertiesTool, DemoInterfaceTool, DemoMembershipTool,
DemoCatalogTool
..
tools = ( DemoInterfaceTool.DemoInterfaceTool
        , DemoMembershipTool.DemoMembershipTool
        , DemoRegistrationTool.DemoRegistrationTool
        , DemoCatalogTool.DemoCatalogTool
        , URLTool.URLTool
        )

Changed Portal.py:
        addPTKBaseTool(self, 'PTK Basic Actions Tool', None)
        # addPTKBaseTool(self, 'PTK Basic Catalog', None)
        addPTKBaseTool(self, 'PTK Basic Discussion Tool', None)
        addPTKBaseTool(self, 'PTK Basic Workflow Tool', None)
        addPTKBaseTool(self, 'PTK Basic Undo Tool', None)

        addPTKDemoTool =
self.manage_addProduct['PTKDemo'].manage_addTool
        addPTKDemoTool(self, 'PTK Demo Membership Tool', None)
        addPTKDemoTool(self, 'PTK Demo Registration Tool', None)
        addPTKDemoTool(self, 'PTK Demo URL Tool', None)
        addPTKDemoTool(self, 'PTK Demo Interface Tool', None)
        addPTKDemoTool(self, 'PTK Demo Catalog', None)

When restarting Zope the PTKDemo product is broken. Traceback is:
Traceback (innermost last):
  File "/usr/share/Zope-2.2.2-linux2-x86/lib/python/OFS/Application.py",
line 397, in import_products
    product=__import__(pname, global_dict, global_dict, silly)
  File
"/usr/share/Zope-2.2.2-linux2-x86/lib/python/Products/PTKDemo/__init__.py",
line 56, in ?
    tools = ( DemoInterfaceTool.DemoInterfaceTool
AttributeError: DemoCatalogTool

Where do I go wrong?


Lucas
-- 
Lucas Hofman
PGS Seres                                        tel: +47 67514059
PO Box 354                                       fax: +47 67526640
N-1324 Lysaker, Norway