[Grok-dev] view-no-view Was: Grok 1.0 final?

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Apr 16 03:06:10 EDT 2009


Martin Aspeli wrote:
> For the record, I need a view-with-no-rendering-at-all component. I want 
> to be able to define a "utility" view that I can traverse to and invoke 
> methods on from templates.
> 
>> For backwards compatibility the first will keep the name "View" and the
>> latter will be called "CodeView".
> 
> Sure. What will you call the one with no 'render' or default __call__? ;-)

(I vaguely remember you mentioned this before, can you point me to the
right thread?)

Not sure what mean to accomplish. Would it be something like this?

app.py:

  import grok

  class Viewnoview(grok.Application, grok.Container):
      pass

  class Index(grok.View):
      pass # see app_templates/index.pt

  from zope.interface import Interface

  class NotReallyAView(grok.MultiAdapter):
      grok.adapts(Viewnoview, grok.IBrowserRequest)
      grok.name('notreally')
      grok.provides(Interface)

      def __init__(self, context, request):
          self.context = context
          self.request = request

      def just_do_something(self):
          return "Something!"

app_templates/index.pt:

  <html>
  <head>
  </head>
  <body>
    <h1>View-no-view</h1>
    <tal:block replace="context/@@notreally"/>
    <tal:block replace="context/@@notreally/just_do_something"/>
  </body>
  </html>

I'd like to note though that the mechanism for pagetemplates to be able
to "traverse" to "context/@@notreally" is more or less the same as going
to the URL "http://localhost/myapp/@@notreally".

In other words, I do not think it would be easy for Grok to have a
"view-ish" component available in ZPT paths, but not accessible through
URLs.

But maybe this all has been discussed before in another thread...

regards,
jw





More information about the Grok-dev mailing list