« Return to Thread: Making an interface the default module context

Making an interface the default module context

by Martin Aspeli :: Rate this Message:

Reply to Author | View in Thread

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

_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

 « Return to Thread: Making an interface the default module context

LightInTheBox - Buy quality products at wholesale price!