[Grok-dev] Add forms - one object type to multiple object types

Darryl Cousins darryl at darrylcousins.net.nz
Sat Mar 10 23:36:09 EST 2007

Hi Kevin,

On Sat, 2007-03-10 at 18:14 -0800, Kevin Teague wrote:
> grok.context() declares what interfaces the View (or AddForm) can  
> adapt, so you do not have to pass it a Grok Component, instead you  
> can pass it an Interface. You can say that an AddForm can be adapted  
> to any object with;
> from zope import interface
> class AddPage(grok.AddForm):
>      grok.context(interface.Interface) #base interface, applies to  
> all objects
> This will work fine, although technically you are stating that your  
> AddForm works for anything, when it will only actually work for  
> Container objects. You can specify that your AddForm works with just  
> Containers by doing:
> from zope.app.container.interfaces import IContainer
> class AddPage(grok.AddForm):
>      grok.context(IContainer) # base container interface, only  
> applies to container objects

Cheers for that, I hadn't tried an Interface! I'd read 'object' in the
code - but of course an interface is an object too.


More information about the Grok-dev mailing list