Re: [Zope-dev] Updating a ZCatalog when objects in it change their path

2000-12-30 Thread Chris Withers

cheers :-)

if people start bitching that it's too slow, I'll give this a go...

Chris

Steve Alexander wrote:
> 
> Chris Withers wrote:
> 
> >
> > However, the only way I could find to solve it was to add a
> > manage_afterAdd method to Squishdot Sites which recatalogued all
> > postings. This is a _lot_ more resource intensive than it needs to be,
> > since I don't actually want to recatalog all postings (quite expensive
> > when there are 3000+ of them ;-), I just want to modify the paths that
> > ZCatalog has stored.
> >
> > Is there any way to do this? There probably should be ;-)
> 
> Look in the new ZCatalog product (released for testing a few weeks ago),
> in the manage_normalize_paths method of ZCatalog.py (line 603).
> 
> This method goes through every item in the Catalog, and checks to see if
> its path needs to be changed to the new convention of using the physical
> path to the object.
> 
> You could use a modified version of this method to do what you want,
> calling it from manage_afterAdd. You may need to store the old path to
> the ZCatalog instance in an attribute, so you'll know how to change the
> paths.
> 
> The following code should help, although I haven't tested it. It is
> shamelessly cribbed from Chris P's manage_normalize_paths method.
> 
>paths = self._catalog.paths
>uids = self._catalog.uids
> 
>for path, rid in uids.items():
>new_path=_method_to_return_new_path_after_add(path)
>del uids[path]
>paths[rid] = new_path
>uids[ppath] = rid
> 
> --
> Steve Alexander
> Software Engineer
> Cat-Box limited
> http://www.cat-box.net

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] Updating a ZCatalog when objects in it change their path

2000-12-30 Thread Steve Alexander

Chris Withers wrote:

>
> However, the only way I could find to solve it was to add a
> manage_afterAdd method to Squishdot Sites which recatalogued all
> postings. This is a _lot_ more resource intensive than it needs to be,
> since I don't actually want to recatalog all postings (quite expensive
> when there are 3000+ of them ;-), I just want to modify the paths that
> ZCatalog has stored.
> 
> Is there any way to do this? There probably should be ;-)

Look in the new ZCatalog product (released for testing a few weeks ago), 
in the manage_normalize_paths method of ZCatalog.py (line 603).

This method goes through every item in the Catalog, and checks to see if 
its path needs to be changed to the new convention of using the physical 
path to the object.

You could use a modified version of this method to do what you want, 
calling it from manage_afterAdd. You may need to store the old path to 
the ZCatalog instance in an attribute, so you'll know how to change the 
paths.

The following code should help, although I haven't tested it. It is 
shamelessly cribbed from Chris P's manage_normalize_paths method.

   paths = self._catalog.paths
   uids = self._catalog.uids

   for path, rid in uids.items():
   new_path=_method_to_return_new_path_after_add(path)
   del uids[path]
   paths[rid] = new_path
   uids[ppath] = rid


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )