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

Jean-Francois.Doyon@CCRS.NRCan.gc.ca Jean-Francois.Doyon@CCRS.NRCan.gc.ca
Tue, 29 Jul 2003 13:50:02 -0400


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.

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 ?

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])

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.

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 ...

So I'm going to look at the "new" package, and maybe moving the code into
the roduct initilization instead of the class.

Comments welcome!

J.F.

-----Original Message-----
From: Paul Winkler [mailto:pw_lists@slinkp.com]
Sent: Tuesday, July 29, 2003 12:11 PM
To: zope-cmf@zope.org
Subject: Re: [Zope-CMF] DC Metadata aquisition, how to have a child use
it's parent's Met adata


On Tue, Jul 29, 2003 at 11:12:33AM -0400,
Jean-Francois.Doyon@CCRS.NRCan.gc.ca wrote:
> I was however hoping I could use some automated way of doing this,
possibly
> by making use of the DefaultDublinCoreImpl.__dict__ , figuring out the
> "functions" and mapping them to the child class instances ... I've toyed
> wiht this though I'm not sure how I would get the mapping part done
properly
> (I can easily figure out the methods declared by the class, just not sure
> how to "merge" them with my own) ...
> 
> There's also the possibility of using __getattr__ ... But then I need a
way
> of discovering what attributes are managed by the DefaultDublinCoreImpl
> class, which there isn't.

You do not want to override __getattr__ unless you have a nearly
infinite supply of zope zen :-)

If you just mean using getattr(), that's fine...
though it also gets acquired attributes, so getattr(foo.aq_base, 'name')
may be what you want.

When I did something vaguely similar recently, I just defined all 
the DublinCore methods to do what I wanted. Tedious, but reliable.

One thing that might help you do something more dynamic: 
DefaultDublinCoreImpl defines a method, getMetadataHeaders(), 
which tells you all the supported metadata methods.
It returns a tuple of (name, value) for all metadata, e.g.
('Title', 'Some stupid title'). 


-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's THUNDEROUS ROBOT-CHUCKER!
(random hero from isometric.spaceninja.com)

_______________________________________________
Zope-CMF maillist  -  Zope-CMF@zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests