[Zope-CMF] DC Metadata aquisition, how to have a child use it 's parent's Met adata

Paul Winkler pw_lists@slinkp.com
Tue, 29 Jul 2003 15:23:29 -0400


On Tue, Jul 29, 2003 at 01:50:02PM -0400, Jean-Francois.Doyon@CCRS.NRCan.gc.ca wrote:
> Hmmm this acquired attribute thing might be what I want ... 
> 
> I noticed for instance that calling Description() on my calss (which
> subclasses CMFDefault.Document) worked, and got the descrption from the
> parent.

That's odd; you should have got it from self since Document provides
Description().

> This however did not work for ALL methods/attributes.  The Description() and
> Keywords() (An extension of mine, behaves like Subject()) worked, getting
> their values from the parent, but others, such as Title, did not. (My object
> does NOT __init__ the Metadata).
> 
> I'm not sure why this is ... If ALL Metadata worked properly than I would be
> satisfied with relying on that ... Anyone know how to fix this or what the
> problem is ?

nope, sorry
`
> Actually I've just discovered the "new" library package that may proove of
> some use.
> 
> I was also playing with something like this:
> 
> for key inn DefaultDublinCoreImpl.__dict__.keys():
> 	if ( type(DefaultDublinCoreImpl.__dict__[key] == types.FunctionType
> ):
> 		setattr(self,key,DefaultDublinCoreImpl.__dict__[key])

there's a much nicer way to do that:

class MyClass(DefaultDublinCoreImpl):
    pass

:-)


> Which gets me part of the way there.  The problem is I need to be able to
> specify somewhere that I want those functions to be applied to the parent
> ... I may look at using the apply() for that.

hmmm. maybe something like (untested):

    def _makeFunction(self, name):
        def foo(self):
	    method = getattr(self.aq_parent, name)
	    return method()
	setattr(self, name, foo)

    def manage_afterAdd(self):
        for n in list_of_metadata_method_names:
            self._makeFunction(n) 
	...
        # Be sure to call superclass' manage_afterAdd methods too.

I don't know if that will actually work :-)

> Also, right now the only good place to do it I've fond is __init__ for my
> class, which is a problem because this ties the functions to specific
> instances.
> And, at initialisation, there is no self.aq_parent it seems ...

that is correct.
If you need to refer to the context, then you should use
manage_afterAdd instead of __init__.

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's BLUE GEOLOGIST TREE!
(random hero from isometric.spaceninja.com)