[Grok-dev] Making an interface the default module context

Martin Aspeli optilude at gmx.net
Sun Aug 3 20:31:57 EDT 2008


Hi,

Let's say I have a module like:

  ...

  class IFoo(Schema):
      pass

  class FooView(grok.View):
      grok.require('hello')

Here, Schema is imported from elsewhere, and is just a marker interface, 
i.e.:

  class Schema(Interface):
     pass

Schema exists purely to make IFoo above grokkable with some optional 
directives.

In the example above, I'd hoped that the context for FooView would 
default to IFoo if there was no other obvious context (e.g. a model). 
IFoo could be a marker interface, for example, which espouses a new view.

However, FooView does not know its context, so I have to use 
grok.context(). I tried to let Schema provide IContext, and also to let 
IFoo provide IContext explicitly via alsoProvides(). Neither seems to stick.

Is it possible to infer that the context for FooView should be IFoo in 
this case?

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book



More information about the Grok-dev mailing list