[Zope-CMF] A modest proposal to add a Unique ID to all content/folder objects in CMF

Grégoire Weber gregoire.weber@switzerland.org
Thu, 12 Sep 2002 13:31:19 +0200


Hi Tim, 
hi all,

I have to mixin some behaviour to existing objects also and I saw your
example below, which I understand how it works.

What I do not understand is how mixing in a class exactly works 
(what I have to do):

   How do you mix in the UniqueId class exactly into CMFCore.PortalContent?
   By hotfixing CMFCore.PortalContent?
   How do you get the ZID method seen by the catalog?

   Is there an example (Product) out there (didn't find How-Tos and hints 
   on zope-cmf@zope.org), where I can analyze the code?

Greetings, Greg

>P.S. Below is a first cut at the UniqueZid mixin class, plus a simple 
>Pythonscript to retrieve an object by it's UniqueZid  
>
>UniqueZid.py
>
>from Globals import InitializeClass,Persistent
>import sha
>from time import asctime,gmtime,clock
>from Acquisition import aq_base
>
>class UniqueZid(Persistent):
>    """
>        Mix-in class which provides a unique id for the object,
>        and will remain Unique if this object is cloned
>        if you are concerned about how unique the hash digest
>        will be, add some additional information by 
>        way of the hash_string argument. If you want to ensure
>        Uniqueness across sites include a prefix (maybe)
>        The prefix is preserved
>    """
[...]

>   def ZID(self):
>        ''' return unique id named nicely for 
>            portal_catalog index names
>        '''
>        return self.getZid()
[...]
>getObjectByZid python script
>
>#parameter = zid
>
>result=context.portal_catalog(ZID=zid)
>if len(result):
>     if len(result) > 1:
>         raise LookupError,"More than one object has the same ZID!"
>     result = result[0]
>     object = result.getObject(result.data_record_id_)
>     return object.view()
>else:
>  return None

_____________________________________
Grégoire Weber
mailto:gregoire.weber@switzerland.org