[Zope] ZClass Catalog Update

Dieter Maurer dieter at handshake.de
Sun Jan 25 18:01:26 EST 2004


KJZZ Webmaster wrote at 2004-1-24 12:04 -0700:
> ...
>> >1)  Is there a way to update only the individual ZClass object in the
>> >catalog
>>
>> The method is "catalog_object" -- it, too, has a well chosen name ;-)
>
>I have some questions about this, if the object is already in the catalog
>and just needs to be updated.  Would I still use this method, or would this
>create an additional object in the database?

You call this same object and it does the right thing whether
the object is new or already known.

> ...
>I found the following python script which mentions how to use the
>catalog_object method:
>
>http://www.zopera.org/Members/Caro07/updatecatalog
>
>request = context.REQUEST
>catalog = context.Catalog
>
>myobject = getattr (context, id)
>catalog.catalog_object (myobject, id)
>
>However, when I try using this, I receive an error saying that "global name
>'id' is not defined"

In general, you should *NOT* follow this example!

The example assumes that

  1.  you locate the object to be indexed via its "id" from "context"
      (this is rarely the case)

  2.  you want the object to be indexed with "id" as its unique id
      (this is almost never the case).

Of course, "id" must come from somewhere. As in your script,
it is not defined, you get the error.


A better example would be:

  1.   obtain the object "obj" to be indexed by any adequate way
       (through a search, via its id (as shown above),
       via "restrictedTraverse", ...

  2.   call "catalog.catalog_object(obj)" to catalog (or re-catalog
       when it already is catalogued) the object

-- 
Dieter



More information about the Zope mailing list