[Grok-dev] Re: Problem with applySkin (Grok 0.12)

Sebastian Ware sebastian at urbantalk.se
Fri Jul 11 08:48:44 EDT 2008


Thanks! I was confused when looking at the tutorial where the  
application was called "Webpage", which I read as "a view".

Mvh Sebastian

11 jul 2008 kl. 14.39 skrev Philipp von Weitershausen:

> Sebastian Ware wrote:
>> The skins are working fine with "++skin++mobile" but I can't get  
>> the applySkin to work (I am using grok 0.12). Basically nothing  
>> happens, no error, nothing. It just keeps on using the default  
>> skin. And I have checked that the applySkin method is actually  
>> called.
>>  #############################
>> ###      Mobile skin      ###
>> #############################
>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>> class MobileLayer(IDefaultBrowserLayer):
>>    pass
>> class MobileSkin(grok.Skin):
>>    grok.name('mobile')
>>    grok.layer(MobileLayer)
>> class MobileTemplate(grok.View):
>>    grok.layer(MobileLayer)
>>    grok.context(Interface)
>> from zope.app.publication.interfaces import IBeforeTraverseEvent
>> from zope.publisher.browser import applySkin
>> @grok.subscribe(grok.View, IBeforeTraverseEvent)
>> def handle(obj, event):
>>    if event.request.get('HTTP_USER_AGENT').find('Safari') > -1:
>>        applySkin(event.request, MobileLayer)
>
> You're subscribing to the wrong object. Views are rarely traversed  
> over (e.g. someobj/@@someview/anothersegment). They are only  
> traversed *to* (e.g. someobj/@@someview).
>
> You want to apply the skin to all views, I simply suggest doing so  
> when traversing over the object that will always be traversed over:  
> the application object:
>
>
>  class MyApp(grok.Application, ...):
>      ...
>
>  ...
>
>  @grok.subscribe(MyApp, IBeforeTraverseEvent)
>  def handle(obj, event):
>      ...



More information about the Grok-dev mailing list