[Grok-dev] Re: Custom Exception Views and application_url
Roman Lacko
rlacko at gratex.com
Wed Apr 2 04:29:05 EDT 2008
Martijn Faassen <faassen <at> startifact.com> writes:
>
> Lacko Roman wrote:
> [snip]
> > 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
> happens.
>
> * 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
> (untested):
>
> class MyLayer(grok.IGrokLayer):
> pass
>
> class MySkin(grok.Skin):
> grok.layer(MyLayer)
>
> and you make your views be in that layer:
>
> class MyView(grok.View):
> grok.layer(MyLayer)
>
> Regards,
>
> Martijn
>
Hi Martijn and others,
I have one more problem with layers and "static" files.
In my main template "master.pt" I have following expression:
<link tal:attributes="href static/styles.css"
rel="stylesheet" type="text/css" href="styles.css" />
when I try browse my application, exception raised:
Traceback (most recent call last):
...
<list of files in stack>
...
return expression(self)
- d:\src\klucsiteenv\klucsite\src\klucsite\app_templates\master.pt
- Line 10, Column 2
- Expression: <PathExpr standard:u'static/styles.css'>
- Names:
{'args': (),
'context': TraversalError(None, 'styles.css'),
'default': <object object at 0x00A705C0>,
'loop': {},
'nothing': None,
'options': {},
'repeat': {},
'request': <zc.resourcelibrary.publication.Request instance
URL=http://localhost:8080/klucsite/@@index>,
'static': None,
'template': <grok.components.TrustedFilePageTemplate object at
0x02B07E70>,
'view': <klucsite.app.SystemError object at 0x02EF6EB0>}
File
"d:\src\klucsiteenv\klucsite\buildout-eggs\
zope.tales-3.4.0a1-py2.5.egg\zope\tales\expressions.py",
line 217, in __call__
return self._eval(econtext)
File
"d:\src\klucsiteenv\klucsite\buildout-eggs\
zope.tales-3.4.0a1-py2.5.egg\zope\tales\expressions.py",
line 194, in _eval
ob = self._subexprs[-1](econtext)
File
"d:\src\klucsiteenv\klucsite\buildout-eggs\
zope.tales-3.4.0a1-py2.5.egg\zope\tales\expressions.py",
line 124, in _eval
ob = self._traverser(ob, element, econtext)
File
"d:\src\klucsiteenv\klucsite\buildout-eggs\
zope.app.pagetemplate-3.4.0-py2.5.egg\zope\app\pagetemplate\engine.py",
line 68, in __call__
request=request)
File
"d:\src\klucsiteenv\klucsite\buildout-eggs\
zope.traversing-3.5.0a1.dev_r78730-py2.5.egg\zope\traversing\adapters.py",
line 164, in traversePathElement
return traversable.traverse(nm, further_path)
- __traceback_info__: (None, 'styles.css')
File
"d:\src\klucsiteenv\klucsite\buildout-eggs\
zope.traversing-3.5.0a1.dev_r78730-py2.5.egg\zope\traversing\adapters.py",
line 52, in traverse
raise TraversalError(subject, name)
- __traceback_info__: (None, 'styles.css', [])
TraversalError: (None, 'styles.css')
It seems that path expression "static/styles.css" was evaluated to
"None/styles.css"
Can some one show me how to properly handling static files
when using layers and skins ?
Thank for your help
Roman
More information about the Grok-dev
mailing list