1 | ## $Id: exceptions.py 7819 2012-03-08 22:28:46Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | import zope.errorview.browser |
---|
20 | from zope.interface.common.interfaces import IException |
---|
21 | from zope.errorview.http import SystemErrorViewMixin |
---|
22 | from zope.publisher.interfaces import INotFound |
---|
23 | from zope.security.interfaces import IUnauthorized |
---|
24 | from waeup.kofa.browser.layout import KofaPage |
---|
25 | |
---|
26 | grok.templatedir('templates') |
---|
27 | |
---|
28 | class ExceptionView(grok.View, zope.errorview.browser.ExceptionView, |
---|
29 | SystemErrorViewMixin): |
---|
30 | """Base class for rendering views for uncaught exceptions that occur during |
---|
31 | the application run-time and are not otherwise rendered. |
---|
32 | |
---|
33 | Backport from Grok 1.6. |
---|
34 | |
---|
35 | XXX: This view is shared for all apps and objects in the ZODB root. |
---|
36 | """ |
---|
37 | grok.context(IException) |
---|
38 | grok.name('index.html') |
---|
39 | grok.template('exception') |
---|
40 | |
---|
41 | def update(self): |
---|
42 | return zope.errorview.browser.ExceptionView.update(self) |
---|
43 | |
---|
44 | class UnauthorizedView(grok.View, zope.errorview.browser.UnauthorizedView): |
---|
45 | """Base class for rendering views for IUnauthorized exceptions. |
---|
46 | |
---|
47 | Backport from grok 1.6. This is only a view (not a page) because |
---|
48 | we cannot trust that the associated :exc:`Unauthorized` exceptions |
---|
49 | happened inside a w.k. site. |
---|
50 | |
---|
51 | If not, then we have no layout available at time of rendering. |
---|
52 | |
---|
53 | XXX: This view is shared for all apps and objects in the ZODB root. |
---|
54 | """ |
---|
55 | grok.context(IUnauthorized) |
---|
56 | grok.name('index.html') |
---|
57 | grok.template('unauthorized') |
---|
58 | |
---|
59 | def update(self): |
---|
60 | return zope.errorview.browser.UnauthorizedView.update(self) |
---|
61 | |
---|
62 | |
---|
63 | class NotFoundPage(KofaPage): |
---|
64 | """A page rendered when an object cannot be found. |
---|
65 | |
---|
66 | XXX: This page won't work for objects above a w.k.University. |
---|
67 | """ |
---|
68 | grok.context(INotFound) |
---|
69 | grok.name('index.html') |
---|
70 | grok.template('notfound') |
---|
71 | |
---|
72 | title = u'404: File Not Found' |
---|
73 | |
---|
74 | def update(self): |
---|
75 | try: |
---|
76 | self.context = grok.getSite() |
---|
77 | except: |
---|
78 | pass |
---|
79 | self.response.setStatus(404) |
---|
80 | return |
---|