[silva-dev] adding metadata (using metadata access handlers)

Andy Altepeter aaltepet at bethel.edu
Wed Oct 12 21:37:31 CEST 2005


(resurrecting an old thread)

I asked awhile ago about conditionally displaying/using metadatasets on a 
content type.  Specifically, I wanted to show a custom metadata set on 
SilvaDocuments that were under a certain directory path.  jw was very helpful 
in pointing me in the right direction.  I thought it may be a good idea to 
post some documentation on this, especially since it seems little-used but 
very useful (for me!).  Anyways, here's a link:

http://altepeter.net/tech/sm-access-handlers/

Cheers,
Andy

On Monday 13 June 2005 12:01 pm, Andy Altepeter wrote:
> Hi jw and the rest,
>
> On Monday 13 June 2005 10:39 am, Jan-Wijbrand Kolman wrote:
> > Andy Altepeter wrote:
> > > Is there a way to conditionally display a metadata set for a content
> > > type (silva document)?
> > >
> > > What I want is to only display the set if the document is located in a
> > > specific place.  Can I use the new 'category' property  in 1.3 to
> > > achieve this?
> >
> > I don't think so. The 'category' property is really only useful to
> > distinguish metadata sets for a particular use ('content' metadata, vs.
> > for example 'layout settings' metadata).
> >
> > Conditionally showing a metadata set sounds rather difficult to me, in
> > the current framework...
> >
> > Maybe, just maybe, you might be able to do something with the metadata
> > 'access handlers'. There're registered in SilvaMetadata/Access.py. If you
> > register another access handler that returns only the sets according to
> > the conditions you'd like... maybe that's an idea?
>
> This works perfectly!  I created an md access handler wich checks the
> content's physical path (via getPhysicalPath) to see if it is contained in
> a certain publication.  If it is not, then I remove my custom set from the
> list.
>
> Access Handlers need to registered during startup; they aren't something
> that is persistent.  I registered the access handler in  my custom products
> __init__.py, in the initialize function.  Here's the code:
>
> from Products.SilvaMetadata.Binding import MetadataBindAdapter
> from Products.SilvaMetadata.Compatibility import getContentType
> from Products.SilvaMetadata.Exceptions import BindingError
> from Products.SilvaMetadata.Access import registerAccessHandler
> def kb_metadata_access_handler(tool, content_type, content):
>     type_mapping = tool.getTypeMapping()
>     metadata_sets = type_mapping.getMetadataSetsFor(content_type)
>     if 'kb' not in content.getPhysicalPath():
>         metadata_sets = [ m for m in metadata_sets if m.id != 'its-kb' ]
>     if not metadata_sets:
>         raise BindingError("no metadata sets defined for %s" %
> content_type) return MetadataBindAdapter(content,
> metadata_sets).__of__(content)
>
> def initialize(context):
>   #...
>   #add a metadata register access handler.  This function (defined above)
> is called
>   #whenever the metadata sets for SDV are retrieved.  This one filters
> would the its-kb
>   #set if the version isn't within the knowledgebase container.
>   registerAccessHandler('Silva Document Version',
> kb_metadata_access_handler)
>
> Thanks jw for the suggestion!
> Andy
> _______________________________________________
> silva-dev mailing list
> silva-dev at infrae.com
> https://infrae.com/mailman/listinfo/silva-dev



More information about the silva-dev mailing list