[ZODB-Dev] I would like append an indexer with uuid key at root of my ZODB, how can I append an function to commit event to update this uuid catalog ?

Alexandru Plugaru alexandru.plugaru at gmail.com
Tue Jun 28 05:18:47 EDT 2011


Hi Stéphane,

Maybe this will be helpful:
http://www.zodb.org/documentation/articles/ZODB2.html#persistent-aware-types
I think what you are looking for is an OOBTree with the key being your uuid
and the  value being the path to your Resources object.

def get_uuid(uuid, context):
   resource_path = context.my_btree.get(uuid, None)
   if uuid is not None:
       return context.unrestrictedTraverse(resource_path)

You can get the path of an object in OFS by calling absolute_url method of
that object.

Hope this helps,
Alex.

On 28 June 2011 12:10, Stéphane Klein <stephane at harobed.org> wrote:

> Le 28/06/2011 10:21, Thierry Florac a écrit :
> >> I use ZODB to record some Resources.
> >>
> >> All my Resources have an "uuid" field.
> >>
> >> All work well but I would like append a BTree to ZODB root object to
> >> "index" uuid of all my resources.
> >>
> >> I would like record to this BTree index only Resources commited to ZODB
> >> database.
> >>
> >> How can I connect a function to "commit" event ?
> >> In this function, how can I found all object modified ?
> >> How can I found all object removed to the database ?
> >>
> >> Other question : are there already a package to perform this task ?
> >
> >
> > The matching package is zope.catalog.
> > It provides all you need (catalog and indexes) to handle your task.
> > Objects creations and modifications are followed automatically by several
> > subscribers as soon as this package is correctly registered.
> > z3c.catalog and hurry.query packages can be good extensions packages to
> > look at...
>
> I've already looked zope.catalog and repoze.catalog.
>
> Question : I haven't docid, can I use uuid here ? but it isn't the
> feature I want : I would like retrieve my object from uuid.
>
> Do you have an example of code about it ?
>
> More information about my aim :
>
> root (ZODB)
>   uuid => { "uuid_value1": resource_A, "uuid_value2": resource_B, ... }
>   folder_1
>     resource_A
>     folder_2
>       resource_B
>
> I would like this function :
>
>  >>> get_by_uuid("uuid_value1")
> => return resource_A
>
> Regards,
> Stephane
>
> --
> Stéphane Klein <stephane at harobed.org>
> blog: http://stephane-klein.info
> Twitter: http://twitter.com/klein_stephane
> pro: http://www.is-webdesign.com
>
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list  -  ZODB-Dev at zope.org
> https://mail.zope.org/mailman/listinfo/zodb-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zodb-dev/attachments/20110628/35b56ddd/attachment.html 


More information about the ZODB-Dev mailing list