[Grok-dev] Re: grok directive for only grokking during development mode

Philipp von Weitershausen philipp at weitershausen.de
Thu Feb 7 10:14:12 EST 2008

Martijn Faassen wrote:
> Hi there,
> I think it would be useful to have a directive that can be put on a 
> component so it only gets grokked during development mode, not in 
> production mode. Something like this:
> class MyView(grok.View):
>    grok.devel()
> 'MyView' would only be grokked and thus only registered in development 
> mode, not in production mode. This requires us figuring out what 
> development-mode and production-mode currently mean in Zope and how to 
> detect it during the grokking process...
> Or perhaps we should generalize this to the tagging story we already 
> discussed quite a while ago:
> class MyView(grok.View):
>    grok.tag('devel')
> the 'grok.tag' directive would receive one or more tags. Tags are then 
> used to determine what gets grokked or not, perhaps like this:
> <grok:grok package="." include_tags="a b" exclude_tags="c d" />
> It'd be nice to be able to spell out the include_tags and exclude_tags 
> in Python somehow, so that we don't end up writing a lot of ZCML in the 
> end. :)
> Some tags could be given special meaning, like 'devel', which means 
> "don't include during production mode". Anyway, a bit of design to work 
> out.
> What do people think? Ideas? Suggestions?

I like this. I would suggest working closely with ZCML conditionals, 
mostly because our grokkers already use the underlying ZCML action 
machinery and it would integrate with the rest of Zope 3 very nicely.

I think especially the ability to check for "features" is useful here 
(see also my response to Wichert down the thread).

I could see something like this:

   class DebugView(grok.View):

(much like <browser:view zcml:condition="have devmode" ... />)

Here's another useful example:

   class PDFView(grok.View):

       def render(self):
           import reportlab

(analogous to <browser:view zcml:condition="installed reportlab" ... />)

More information about the Grok-dev mailing list