[Grok-dev] Adapter order/overriding/"inheritance"

Matthias nitro at dr-code.org
Fri Feb 18 13:45:43 EST 2011


here's a somewhat fundamental question about using adapters. I'll  
illustrate it with a quick example:

class PreferredLangugageAdapter(grok.Adapter):

     def getPreferredLanguages(self):
         default = BrowserLanguages(self.context).getPreferredLanguages()
         if some_condition:
             return default
         return []

This adapter overrides the default adapter for (IHTTPRequest,  
IUserPreferredLanguages) in zope.publication.browser. Now in some cases I  
want to return the value returned by the adapter I override (the "default"  
in the example).

The code above works, but it relies on the fact that I know which adapter  
I am overriding (the BrowserLanguages adapter). Wouldn't it make sense if  
I could do something like

default = grok.superAdapter(self).getPreferredLanguages()

I am not familiar enough with the zca to see if this makes sense at all or  
if there's already something built-in to solve this problem. There was  
also the recent postings by sylvain/j-w and those subscription adapters  
which can work like a "filter chain". That's basically what my example  
above is doing, too.

Any hints if this pattern is common/good and what people typically do to  
implement it?


More information about the Grok-dev mailing list