[Zope] ZCatalog, CatalogAware, and ZClasses

Stuart 'Zen' Bishop zen@cs.rmit.edu.au
Wed, 13 Oct 1999 16:19:24 +1000 (EST)


On Wed, 13 Oct 1999, gtk wrote:

> I assume I need to doctor the FnordContainerClass_add method to create a new
> ZCatalog in the new FnordContainer. How do I do that?

I've just written up a tip on Zope.org that covers this. Here is the relevant
details section:

In your container class' constructor (MyContainerClass_add), you can programatically create a ZCatalog instance as a subobject, and setup its indexes and metadata automatically.

In this example, the container class is MyContainerClass and the ZCatalog id is Catalog::

 <dtml-with "MyContainerClass.createInObjectManager(REQUEST['id'], REQUEST)">

  <dtml-comment>Create the ZCatalog instance called 'Catalog'</dtml-comment>
  <dtml-call "manage_addProduct['ZCatalog'].manage_addZCatalog(this(),'Catalog','')"> 

  <dtml-with "Catalog">  
    <dtml-call "manage_delColumns(['summary',],REQUEST,RESPONSE,URL1)">

    <dtml-call "manage_addColumn('container',REQUEST,RESPONSE,URL1)">
    <dtml-call "manage_addIndex('container','FieldIndex',REQUEST,RESPONSE,URL1)">

    <dtml-call "manage_addColumn('queue',REQUEST,RESPONSE,URL1)">
    <dtml-call "manage_addIndex('queue','FieldIndex',REQUEST,RESPONSE,URL1)">

    <dtml-call "manage_addColumn('area',REQUEST,RESPONSE,URL1)">
    <dtml-call "manage_addIndex('area','FieldIndex',REQUEST,RESPONSE,URL1)">

    <dtml-call "manage_addColumn('job',REQUEST,RESPONSE,URL1)">
    <dtml-call "manage_addIndex('job','FieldIndex',REQUEST,RESPONSE,URL1)">

    <dtml-call "manage_addIndex('text','TextIndex',REQUEST,RESPONSE,URL1)">
  </dtml-with>
 </dtml-with>

 <dtml-comment>Create a ZSearch interface automatically</dtml-comment>
 <dtml-call "manage_addProduct['ZSQLMethods'].manage_addZSearch(self=Catalog,report_id='report',report_title='',report_style=0,input_id='index_html',input_title='Search the Catalog',queries=['Catalog',])">

> Uh, fine. At the moment, I'm only editing my Fnords via their Properties
> view. How do I doctor the view so that index_object is called?

Havn't got that far yet - my objects are static though so that is for
a future project :-) You will probably need to write your own form
that submits the results to a DTML method that calls index_object and 
manage_editProperties.

> Finally; I've added an index_html method to my FnordContainerClass and used
> the Z Search Interface pseudo-product (all it does is create DTML methods,
> and one day I'll investigate and find out how the beggars did it) to create
> search and results methods.
> 
> For some reason, it can't find any of the items in the Catalog. Wierd. Any
> ideas?

Is your ZCatalog called 'Catalog'? This is the default ZCatalog searched
for by CatalogAware objects, and if you want to use a different name you
will need to call setCatalog('MyWierdCatalog',REQUEST) in each of your
ZClass' constructors. Mine works anyway, so it is possible :-)

 ___
   //     Zen (alias Stuart Bishop)     Work: zen@cs.rmit.edu.au
  // E N  Senior Systems Alchemist      Play: zen@shangri-la.dropbear.id.au
 //__     Computer Science, RMIT 	 WWW: http://www.cs.rmit.edu.au/~zen