source: main/waeup.sirp/trunk/src/waeup/sirp/browser/exceptions.py @ 6192

Last change on this file since 6192 was 6192, checked in by uli, 13 years ago

Add layout for exception views and pages for Unauthorized,
NotFound?. There are still some serious things left to be discussed
with that Exception views/pages.

File size: 2.7 KB
Line 
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##
22import grok
23from megrok.layout import Page
24from zope.interface.common.interfaces import IException
25from zope.publisher.interfaces import INotFound
26from zope.security.interfaces import IUnauthorized
27from waeup.sirp.browser.layout import SiteLayout, WAeUPPage
28from waeup.sirp.interfaces import IWAeUPObject
29
30grok.templatedir('templates')
31
32class ExceptionLayout(SiteLayout):
33    """ The general site layout.
34    """
35    grok.context(IException)
36    grok.template('sitelayout')
37
38
39#class ExceptionPage(WAeUPPage):
40#    grok.context(IException)
41#    grok.name('index.html')
42#    grok.template('exception')
43#
44#    title = u'System Error'
45#    pnav = 0
46#
47#    def update(self):
48#        # XXX: That's merely bullshit. We cannot trust to have anything
49#        # ready/setup if some arbitrary exception happens. Maybe we're
50#        # better off with views instead pages here?
51#        self.message = self.context.message
52#        self.args = self.context.args
53#        self.error_context = self.context
54#        if not IWAeUPObject.providedBy(self.context):
55#            self.context = self.context = getattr(
56#                self.context, '__parent__', self.context)
57#            self.context = self.context.context
58#        return
59
60
61class UnauthorizedPage(WAeUPPage):
62    grok.context(IUnauthorized)
63    grok.name('index.html')
64    grok.template('unauthorized')
65
66    title = u'Unauthorized'
67
68    def update(self):
69        self.error_context = self.context
70        forbidden_view = self.context.args[0]
71        self.context = forbidden_view.context
72        pass
73
74class NotFoundPage(WAeUPPage):
75    grok.context(INotFound)
76    grok.name('index.html')
77    grok.template('notfound')
78
79    title = u'404: File Not Found'
80
81    def update(self):
82        try:
83            self.context = self.context.getObject()
84        except:
85            pass
86        self.response.setStatus(404)
87        return
Note: See TracBrowser for help on using the repository browser.