[Grok-dev] Re: Custom Exception Views and application_url

Lacko Roman rlacko at gratex.com
Tue Apr 1 08:59:59 EDT 2008

Thank you Martijn for answer

I thing, for now (and for my application), layers and skins are best choice

Will report my failures and success here later


-----Original Message-----
From: grok-dev-bounces at zope.org [mailto:grok-dev-bounces at zope.org] On Behalf Of Martijn Faassen
Sent: Tuesday, April 01, 2008 2:41 PM
To: grok-dev at zope.org
Subject: [Grok-dev] Re: Custom Exception Views and application_url

Lacko Roman wrote:
> Please can someone tell me how to properly use custom exception views ?

I think the main problem is that it's hard to make a custom exception
view for IUnauthorized. I think other exception views shouldn't have the
problem you faced.

The problem here is two-fold:

* I believe the default exception view for IUnauthorized is the one that
causes the login-prompt to be shown. You're overriding it, so it never

* You get your special view outside of an application, so it cannot find
the application root.

Generally I believe that using Zope 3's authentication mechanism is
probably preferable to overriding IUnauthorized, but I'm handwaving some
details here. I can't think for the moment how one would customize the
view you see if your login *failed* without overriding IUnauthorized.

Skins are indeed a possible way around this. If you make sure your
application works in a skin and your IUnauthorized view is in a skin,
the you cannot get it when you're not in that skin yet, i.e. the grok
installation screen.

You can make your application be in another skin by default by doing
something like this:

from zope.app.publication.interfaces import IBeforeTraverseEvent

@grok.subscribe(MyApp, IBeforeTraverseEvent)
def setSkin(obj, event):
    zope.publisher.browser.applySkin(event.request, MyLayer)

where MyLayer is used by the skin you want to apply, something like this

class MyLayer(grok.IGrokLayer):

class MySkin(grok.Skin):

and you make your views be in that layer:

class MyView(grok.View):



Grok-dev mailing list
Grok-dev at zope.org

More information about the Grok-dev mailing list