[Grok-dev] Traversing over attributes/methods in grok.View

Sebastian Ware sebastian at urbantalk.se
Wed Sep 15 04:20:50 EDT 2010


You could use:

class Index(grok.View):
    def update(self):
        pass
    
    def publishTraverse(self, request, name):
	# do your stuff and call your methods here...

Mvh Sebastian


13 sep 2010 kl. 14.31 skrev Jasper Spaans:

> On Mon, Sep 13, 2010 at 01:58:23PM +0200, Christian Klinger wrote:
> 
>> i try to access attributes/methods of a grok.View via traversal.
>> But i have no idea where to look for a solution.
>> 
>> Take a look at this exmaple: I think it shows what i want...
>> 
>> class MyView(grok.View):
>> 
>>     def foo(self):
>>         return "foo"
>> 
>>     def render(self):
>>         return "normal view"
>> 
>>>>> browser.open('http://localhost/app/myview')
>>>>> browser.contents
>> "normal view"
>> 
>>>>> browser.open('http://localhost/app/myview/foo')
>>>>> browser.contents
>> "foo"
>> 
>> 
>> Any idea how i can do this? I guess i have to look in zope.publication 
>> and or zope.traversal.
> 
> The closest you can get probably is grok.traversable:
> http://grok.zope.org/doc/current/reference/directives.html#grok.traversable
> but than will need you to have methods which are defined on your Model
> class instead of on your view.
> 
> You can than add an adapter for string-like objects, which returns the
> things as-is, like
> 
> class MyStringViewer(grok.View)
>    grok.context(basestring)
> 
>    def render(self):
>        return self.context
> 
> [*] completely untested code here, but it might work.
> 
> Cheers,
> Jasper
> -- 
> Ir. Jasper Spaans                                   http://jasper.es/
> 14:28:23 up 12262 days,  5:15, 1 user, load average: 0.00 0.00 0.00
> 
>           emacs... car rater vi, c'est un droit inaliénable
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list