[Grok-dev] Why must a CodeView have a render() method?

Martin Aspeli optilude+lists at gmail.com
Sun Jul 12 12:36:15 EDT 2009


Martin Aspeli wrote:
> Hi,
> 
> I often use views that are not browser pages, i.e. they are not meant to 
> be published, but contain utility functions looked up by traversal in 
> other contexts (e.g. conditional expressions).
> 
> I had thought this was one of the use cases for a 
> grokcore.view.CodeView, but I guess not, since it requires a render() 
> method.
> 
> Would it make sense to either relax this requirement, so that a CodeView 
> without a render method can still be looked up but can't be published 
> directly? Or maybe to add some other kind of base class for this use case?

Mmm... under five.grok, at least, it seems that the view cannot be 
published anyway. I have a view like this:

from five import grok
from zope.interface import Interface

class DebugView(grok.CodeView):
     grok.name('debug')
     grok.context(Interface)

     def render(self):
         import pdb; pdb.set_trace( )
         return ''

However, I can't traverse to @@debug anywhere. This used to work when 
this was just grok.View (which now gives an error).

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