[Zope-dev] Re: [Zope-CMF] CMF Usabiltiy

Tim Hoffman timhoffman@cams.wa.gov.au
16 Jul 2002 11:29:26 +0800


Hi

For what it is worth here are some code snippets from the monkeypatch
that adds the basics to show what I have been doing. It is a bit messy
and probably not the best way to do it, but this gives you the gist of
what is going on.

First off I have been monkeypatching  the DefaultDublinCoreImpl and
adding the following field and method. I also override the behaviour of
manageAfterClone 

# UniqueId -----------------------------------------------------
security.declarePublic( 'UniqueId' )
def UniqueID( self ):
    '''Designing Futures element - UniqueID'''
    try:
        return self.unique_id
    except:
        return ""
    
#------------------------------------------------------------------

import md5, base64, time,  string

def ETIMakeUniqueID(id):
    ''' Generate a unique id '''
    oid=md5.new()
    oid.update(id)
    oid.update(str(time.time()))
    oid=oid.digest()
    oid=string.strip(base64.encodestring(oid))
    return 'DF_OID_'+oid.replace('/','$')



I need to extend the functionality of manage_afterClone so that if an
object is cloned/copied it needs to have the UniqueID regenerated,
otherwise we will end up with duplicate ID's (not a good thing)


def manage_afterClone(self,obj):
    
    obj.unique_id = ETIMakeUniqueID(obj.title_or_id())



Overide the  __init__ method in DefaultDublinCoreImpl
to include self.unique_id = ETIMakeUniqueID(title)

So that the unique id is initialised on object creation.


The bind/rebind these methods to the base classes, so that all content
types will exhibit this behaviour.

DefaultDublinCoreImpl.UniqueID = UniqueID
DefaultDublinCoreImpl.__init__ = __init__
Item.manage_afterClone = manage_afterClone

Then I set up an Index and Metadata for UniqeID in the portal_catalog.

Now any object can be found by UniquID. Irrespective of whats it's path
is, by using the catalog. I find also that an awfull lot of the time the
metadata is often sufficient without having to retrieve the object.

Regards

Tim



On Fri, 2002-07-12 at 23:44, J C Lawrence wrote:
> On 12 Jul 2002 14:43:23 +0800 
> Tim Hoffman <timhoffman@cams.wa.gov.au> wrote:
> 
> > This is a feature I too wanted, and my solution was to to give every
> > object a unique object ID (new metadata field) which get's updated if
> > the object is cloned. This Object ID is then catalogued, and then
> > content which needs links uses the object Id plus a retrieval
> > method. This way doc's can move anywhere and no broken links.
> 
> Neat.  Smart.  Might be a good idea to throw the details and a sample
> code blob up on the Collector for others to follow.
> 
> -- 
> J C Lawrence                
> ---------(*)                Satan, oscillate my metallic sonatas. 
> claw@kanga.nu               He lived as a devil, eh?		  
> http://www.kanga.nu/~claw/  Evil is a name of a foeman, as I live.