[Zope-dev] view lookup based on location

Marius Gedminas marius at gedmin.as
Sat Apr 11 15:51:36 EDT 2009


On Sat, Apr 11, 2009 at 06:37:18PM +0100, Chris Withers wrote:
> Hi All,
> 
> Suppose I have the following:
> 
> a = Folder()
> b = Folder()
> c = Folder()
> 
> a.b = b
> a.c = c
> 
> What's the canonical way of registering a view on b that is different to 
> a view of the same name on a, and ditto with c?

Marker interfaces.

  alsoProvides(b, IMyVerySpecialFolder)
  alsoProvides(c, ISomeOtherKindOfAVerySpecialFolder)

  # alternatively, subclass Folder, make it implement those marker
  # interfaces, then make b and c instances of your folder subclasses.

Or you could hook up a custom traverser (i.e. an adapter on
(ISomeInterfaceDistinguishingAFromAllOtherFolders, IBrowserRequests) to
IBrowserPublisher) and do magic in its publishTraverse (maybe wrap the
subfolders 'b' and 'c' in some kind of proxies that provide interfaces).
Handwave, handwave.  I do not recommend this way.

Marius Gedminas
-- 
http://pov.lt/ -- Zope 3 consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20090411/a0941d18/attachment.bin 


More information about the Zope-Dev mailing list