1 | ## |
---|
2 | ## exceptions.py |
---|
3 | ## Login : <uli@pu.smp.net> |
---|
4 | ## Started on Sun May 22 18:28:46 2011 Uli Fouquet |
---|
5 | ## $Id$ |
---|
6 | ## |
---|
7 | ## Copyright (C) 2011 Uli Fouquet |
---|
8 | ## This program is free software; you can redistribute it and/or modify |
---|
9 | ## it under the terms of the GNU General Public License as published by |
---|
10 | ## the Free Software Foundation; either version 2 of the License, or |
---|
11 | ## (at your option) any later version. |
---|
12 | ## |
---|
13 | ## This program is distributed in the hope that it will be useful, |
---|
14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | ## GNU General Public License for more details. |
---|
17 | ## |
---|
18 | ## You should have received a copy of the GNU General Public License |
---|
19 | ## along with this program; if not, write to the Free Software |
---|
20 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
21 | ## |
---|
22 | import grok |
---|
23 | import zope.errorview.browser |
---|
24 | from megrok.layout import Page |
---|
25 | from zope.interface.common.interfaces import IException |
---|
26 | from zope.publisher.interfaces import INotFound |
---|
27 | from zope.security.interfaces import IUnauthorized |
---|
28 | from waeup.sirp.browser.layout import SiteLayout, WAeUPPage |
---|
29 | from waeup.sirp.interfaces import IWAeUPObject |
---|
30 | |
---|
31 | grok.templatedir('templates') |
---|
32 | |
---|
33 | class ExceptionLayout(SiteLayout): |
---|
34 | """ The general site layout. |
---|
35 | """ |
---|
36 | grok.context(IException) |
---|
37 | grok.template('sitelayout') |
---|
38 | |
---|
39 | |
---|
40 | #class ExceptionPage(WAeUPPage): |
---|
41 | # grok.context(IException) |
---|
42 | # grok.name('index.html') |
---|
43 | # grok.template('exception') |
---|
44 | # |
---|
45 | # title = u'System Error' |
---|
46 | # pnav = 0 |
---|
47 | # |
---|
48 | # def update(self): |
---|
49 | # # XXX: That's merely bullshit. We cannot trust to have anything |
---|
50 | # # ready/setup if some arbitrary exception happens. Maybe we're |
---|
51 | # # better off with views instead pages here? |
---|
52 | # self.message = self.context.message |
---|
53 | # self.args = self.context.args |
---|
54 | # self.error_context = self.context |
---|
55 | # if not IWAeUPObject.providedBy(self.context): |
---|
56 | # self.context = self.context = getattr( |
---|
57 | # self.context, '__parent__', self.context) |
---|
58 | # self.context = self.context.context |
---|
59 | # return |
---|
60 | |
---|
61 | class UnauthorizedView(grok.View, zope.errorview.browser.UnauthorizedView): |
---|
62 | """Base class for rendering views for IUnauthorized exceptions. |
---|
63 | |
---|
64 | Backport from grok 1.6. This is only a view (not a page) because |
---|
65 | we cannot trust that the associated :exc:`Unauthorized` exceptions |
---|
66 | happened inside a w.s. site. |
---|
67 | |
---|
68 | If not, then we have no layout available at time of rendering. |
---|
69 | |
---|
70 | XXX: This view is shared for all apps and objects in the ZODB root. |
---|
71 | """ |
---|
72 | grok.context(IUnauthorized) |
---|
73 | grok.name('index.html') |
---|
74 | grok.template('unauthorized') |
---|
75 | |
---|
76 | def update(self): |
---|
77 | return zope.errorview.browser.UnauthorizedView.update(self) |
---|
78 | |
---|
79 | |
---|
80 | class NotFoundPage(WAeUPPage): |
---|
81 | grok.context(INotFound) |
---|
82 | grok.name('index.html') |
---|
83 | grok.template('notfound') |
---|
84 | |
---|
85 | title = u'404: File Not Found' |
---|
86 | |
---|
87 | def update(self): |
---|
88 | try: |
---|
89 | self.context = self.context.getObject() |
---|
90 | except: |
---|
91 | pass |
---|
92 | self.response.setStatus(404) |
---|
93 | return |
---|