I'm trying to expand on the ZCatalog tutorial at http://www.zope.org/Documentation/How-To/ZCatalogTutorial by creating a ZClass which automatically maintains a catalog of the CatalogAware items within it. So far, I've created: FnordProduct: Product FnordContainerClass: ZClass derived from ObjectManager Catalog: ZCatalog FnordClass: ZClass derived from CatalogAware ... along with a <classname>Info property sheet each and a matching View to boot. Surprise! When I create a FnordContainer and populate it, the Fnords inside it are catalogued in the ZCatalog in the product. That looks like inheritance (sorry, acquisition:) in action. I assume I need to doctor the FnordContainerClass_add method to create a new ZCatalog in the new FnordContainer. How do I do that? CatalogAwareness.py also mentions: This is a Mix-In class to make objects automaticly catalog and uncatalog themselves in Zope, and to provide some other basic attributes that are useful to catalog. Note that if your class or ZClass subclasses CatalogAware, it will only catalog itself when it is added or copied in Zope. If you make changes to your own object, you are responsible for calling your object's index_object method. 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? 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? Regards, Garth. -- <gtk@well.com>
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
In your container class' constructor (MyContainerClass_add), you can programatically create a ZCatalog instance as a subobject, and setup its indexes and metadata automatically.
Cute technique! I tried deriving a ZClass from ZCatalog to do the column and index management itself -- the idea was that I could update all of the FnordCatalogs' designs and methods just by touching one object -- but for some reason it runs right into a wall. Yell if you can read tracebacks; I can reproduce it pretty damn quickly.
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.
Oh, so I can't use views if I want to do that kind of thing? Regards, Garth. -- <gtk@well.com>
At 23:28 13/10/99 , gtk wrote:
In your container class' constructor (MyContainerClass_add), you can programatically create a ZCatalog instance as a subobject, and setup its indexes and metadata automatically.
Cute technique!
I tried deriving a ZClass from ZCatalog to do the column and index management itself -- the idea was that I could update all of the FnordCatalogs' designs and methods just by touching one object -- but for some reason it runs right into a wall. Yell if you can read tracebacks; I can reproduce it pretty damn quickly.
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.
Oh, so I can't use views if I want to do that kind of thing?
I have a project in development right now that uses a ZClass based on ZCatalog and ObjectManager. Works great. In it I have one ZClass that inherits from CatalogAware, and with some twiddling in the constructor methods instances of the CatalogAware classes are indexing themselves in the container ZClass just fine. -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
Okay, I'm completely stuck on this issue of how to create container classes which can catalog the specific objects that are only available to that container (ie one ZClass inside another). Please excuse the attachment. I figure at 4K it's not much bigger than many messages here and should be middling-okay. If you're reeeeally curious and want to wade through the code, there it is.
I have a project in development right now that uses a ZClass based on ZCatalog and ObjectManager. Works great.
I just tried that. Maybe it was the inheritance order, but I couldn't get to any of the catalog management views. <checks something> Aha! Inherit ZCatalog, THEN ObjectManager. - create product "fooproduct" - create ZClass fooproduct/foocontainer from ZCatalog, ObjectManager - create ZClass fooproduct/foocontainer/foo from CatalogAware - visit fooproduct/foocontainer_factory and click "change" (probably un-necessary) - visit fooproduct/foocontainer/foo_factory and click "change" - visit fooproduct/foocontainer:permissions and change the permissions from "add foocontainers" (why is that there?) to "add foos". - visit fooproduct/foocontainer:subobjects and... Problem #1: I can't put "foo" up as a subobject of foocontainer. Why not? Problem #2: By hacking an index_html with a link to foo_addForm, I can add a foo (so why can't I put foo in the list of subobjects?). Cool. Unfortunately, this code in foo_add doesn't result in anything going in the catalog: <dtml-with "foo.createInObjectManager(REQUEST['id'], REQUEST)"> <dtml-call setCatalog(PARENTS[0],REQUEST)> <dtml-call index_object()> Changing the first argument to setCatalog doesn't make a shred of difference. Finally; Problem #3: "Find items to ZCatalog" in an instance of foocontainer doesn't permit me to add foos. Why not?
In it I have one ZClass that inherits from CatalogAware, and with some twiddling in the constructor methods instances of the CatalogAware classes are indexing themselves in the container ZClass just fine.
I don't suppose you're willing to HowTo that one? I'm trying to get a decent level of abstraction here by creating a Regards, Garth. -- <gtk@well.com>
At 20:04 17/10/99 , gtk wrote:
Problem #1: I can't put "foo" up as a subobject of foocontainer. Why not?
ZClasses with a Factory inside an ObjectManager derived ZClass automatically are addable to that ZClass. You cannot add them on the subobject tab because that is only for objects outside the current ObjectManager.
Problem #2: By hacking an index_html with a link to foo_addForm, I can add a foo (so why can't I put foo in the list of subobjects?). Cool. Unfortunately, this code in foo_add doesn't result in anything going in the catalog:
<dtml-with "foo.createInObjectManager(REQUEST['id'], REQUEST)"> <dtml-call setCatalog(PARENTS[0],REQUEST)> <dtml-call index_object()>
Changing the first argument to setCatalog doesn't make a shred of difference.
Where did this setCatalog come from? It's not in the CVS, nor in the current code. I have (simplified): Foo (ZClass) - Inherits ObjectManager, ZCatalog (in that order) - On the Permissions tab 'Add Bars' is selected. - Subobjects: None - Views do not include any ZCatalog specific methods, because I am hiding the fact it is a Catalog. I just use its methods from other views and methods. Foo_factory Foo_addForm Foo_add_permission Bar_add_permission Foo_add - <dtml-with "Foo.createInObjectManager(REQUEST['id'], REQUEST)"> <dtml-call "propertysheets.Basic.manage_editProperties(REQUEST)"> <dtml-comment>I also change the indexes and schema of Catalog here, using manage_delColumns, manage_delIndexes, manage_addColumn and manage_addIndex. </dtml-comment> </dtml-with> Within the Foo ZClass, I have: Bar (Zclass) - Inherits from CatalogAware Bar_addForm Bar_factory Bar_add - <dtml-with "Bar.createInObjectManager(REQUEST['id'], REQUEST)"> <dtml-call "propertysheets.Basic.manage_editProperties(REQUEST)"> <dtml-call "manage_editCataloger(PARENTS[1].id, REQUEST)"> <dtml-call reindex_object> </dtml-with> The manae_editCataloger method sets the ObjectManager and ZCatalog derived ZClass as the Catalog to index this new object. You'll have to make sure that you either have the latest CVS version of CatalogAwareness.py, or change the method signature of manage_editCataloger to: def manage_editCataloger(self, default, REQUEST)
Finally;
Problem #3: "Find items to ZCatalog" in an instance of foocontainer doesn't permit me to add foos. Why not?
I don't know about this one. I don't find the objects into my ZCatalog, I make them add and remove themselves.
In it I have one ZClass that inherits from CatalogAware, and with some twiddling in the constructor methods instances of the CatalogAware classes are indexing themselves in the container ZClass just fine.
I don't suppose you're willing to HowTo that one?
I hereby grant you permission to write a HowTo with the above info =). I am really very busy with two Zope projects right now, plus a lot of personal things thrown in the mix as well.. -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
participants (3)
-
gtk -
Martijn Pieters -
Stuart 'Zen' Bishop