[Checkins] SVN: megrok.layout/branches/jj-errorviews/ Add error view baseclasses.
Jan-Jaap Driessen
jdriessen at thehealthagency.com
Wed Jul 6 03:13:13 EDT 2011
Log message for revision 122122:
Add error view baseclasses.
Changed:
_U megrok.layout/branches/jj-errorviews/
U megrok.layout/branches/jj-errorviews/setup.py
U megrok.layout/branches/jj-errorviews/src/megrok/layout/README.txt
U megrok.layout/branches/jj-errorviews/src/megrok/layout/__init__.py
U megrok.layout/branches/jj-errorviews/src/megrok/layout/components.py
U megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/ftesting.zcml
A megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/models/errorviews.py
-=-
Property changes on: megrok.layout/branches/jj-errorviews
___________________________________________________________________
Modified: svn:ignore
- develop-eggs
bin
parts
.installed.cfg
+ develop-eggs
bin
parts
.installed.cfg
coverage
Modified: megrok.layout/branches/jj-errorviews/setup.py
===================================================================
--- megrok.layout/branches/jj-errorviews/setup.py 2011-07-06 07:12:49 UTC (rev 122121)
+++ megrok.layout/branches/jj-errorviews/setup.py 2011-07-06 07:13:13 UTC (rev 122122)
@@ -47,7 +47,9 @@
'grokcore.view >= 2.3',
'martian',
'setuptools',
+ 'zope.authentication',
'zope.component >= 3.9.1',
+ 'zope.errorview',
'zope.interface',
'zope.publisher',
],
Modified: megrok.layout/branches/jj-errorviews/src/megrok/layout/README.txt
===================================================================
--- megrok.layout/branches/jj-errorviews/src/megrok/layout/README.txt 2011-07-06 07:12:49 UTC (rev 122121)
+++ megrok.layout/branches/jj-errorviews/src/megrok/layout/README.txt 2011-07-06 07:13:13 UTC (rev 122122)
@@ -103,8 +103,9 @@
u'Header. Page: Looks like an elephant. Footer'
-Forms
-=====
+Forms & Errorpages
+==================
-You have as well a Form, AddForm, EditForm and DisplayForm availables,
-which are all aware of Layout components like Page does.
+Baseclasses for Form views (Form, AddForm, EditForm and DisplayForm) and Error
+views (NotFoundView, ExceptionView, UnauthorizedView) are available which are
+all aware of Layout components like Page is.
Modified: megrok.layout/branches/jj-errorviews/src/megrok/layout/__init__.py
===================================================================
--- megrok.layout/branches/jj-errorviews/src/megrok/layout/__init__.py 2011-07-06 07:12:49 UTC (rev 122121)
+++ megrok.layout/branches/jj-errorviews/src/megrok/layout/__init__.py 2011-07-06 07:13:13 UTC (rev 122122)
@@ -3,3 +3,5 @@
from megrok.layout.interfaces import ILayout, IPage
from megrok.layout.components import Layout, Page, Form
from megrok.layout.components import AddForm, EditForm, DisplayForm
+from megrok.layout.components import UnauthorizedView, NotFoundView
+from megrok.layout.components import ExceptionView
Modified: megrok.layout/branches/jj-errorviews/src/megrok/layout/components.py
===================================================================
--- megrok.layout/branches/jj-errorviews/src/megrok/layout/components.py 2011-07-06 07:12:49 UTC (rev 122121)
+++ megrok.layout/branches/jj-errorviews/src/megrok/layout/components.py 2011-07-06 07:13:13 UTC (rev 122122)
@@ -8,7 +8,11 @@
from megrok.layout.interfaces import IPage, ILayout
from zope.interface import Interface
+import zope.publisher.interfaces
+import zope.security.interfaces
from zope.publisher.publish import mapply
+import zope.interface.common.interfaces
+import zope.errorview.browser
from zope.component.hooks import getSite
@@ -184,3 +188,36 @@
"""
grok.baseclass()
template = default_display_template
+
+
+class ExceptionView(Page, zope.errorview.browser.ExceptionView):
+ grok.context(zope.interface.common.interfaces.IException)
+ grok.baseclass()
+
+ def update(self):
+ return zope.errorview.browser.ExceptionView.update(self)
+
+ def render(self):
+ return zope.errorview.browser.ExceptionView.render(self)
+
+
+class NotFoundView(Page, zope.errorview.browser.NotFoundView):
+ grok.context(zope.publisher.interfaces.INotFound)
+ grok.baseclass()
+
+ def update(self):
+ return zope.errorview.browser.NotFoundView.update(self)
+
+ def render(self):
+ return zope.errorview.browser.NotFoundView.render(self)
+
+
+class UnauthorizedView(Page, zope.errorview.browser.UnauthorizedView):
+ grok.context(zope.security.interfaces.IUnauthorized)
+ grok.baseclass()
+
+ def update(self):
+ return zope.errorview.browser.UnauthorizedView.update(self)
+
+ def render(self):
+ return zope.errorview.browser.UnauthorizedView.render(self)
Modified: megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/ftesting.zcml
===================================================================
--- megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/ftesting.zcml 2011-07-06 07:12:49 UTC (rev 122121)
+++ megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/ftesting.zcml 2011-07-06 07:13:13 UTC (rev 122122)
@@ -12,6 +12,9 @@
<grok:grok package=".layout" />
<grok:grok package=".models" />
+ <!-- In order to test the errorviews that stem from zope.errorview. -->
+ <include package="zope.errorview.tests" file="ftesting.zcml"/>
+
<!-- We do not grok the other packages on purpose -->
</configure>
Added: megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/models/errorviews.py
===================================================================
--- megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/models/errorviews.py (rev 0)
+++ megrok.layout/branches/jj-errorviews/src/megrok/layout/tests/models/errorviews.py 2011-07-06 07:13:13 UTC (rev 122122)
@@ -0,0 +1,63 @@
+"""
+ >>> from zope.component import getMultiAdapter
+ >>> from zope.publisher.browser import TestRequest
+ >>> view = getMultiAdapter((Exception(), TestRequest()), name='index')
+ >>> import megrok.layout
+ >>> isinstance(view, megrok.layout.ExceptionView)
+ True
+ >>> print view.render()
+ A system error occurred.
+ >>> print view()
+ <html>
+ <body>
+ <div class="layout">A system error occurred.</div>
+ </body>
+ </html>
+
+ >>> from zope.security.interfaces import Unauthorized
+ >>> class MockPrincipal(object):
+ ... id = 'mock principal'
+ >>> request = TestRequest()
+ >>> request.setPrincipal(MockPrincipal())
+ >>> errorpage = getMultiAdapter((Unauthorized(), request), name='index')
+ >>> print errorpage()
+ <html>
+ <body>
+ <div class="layout">Access to the requested resource is forbidden.</div>
+ </body>
+ </html>
+
+ >>> from zope.publisher.interfaces import NotFound
+ >>> request = TestRequest()
+ >>> errorpage = getMultiAdapter(
+ ... (NotFound(None, request), request), name='index')
+ >>> print errorpage()
+ <html>
+ <body>
+ <div class="layout">The requested resource can not be found.</div>
+ </body>
+ </html>
+
+"""
+import grokcore.component as grok
+
+from grokcore.view import templatedir
+from megrok.layout import Layout, ExceptionView, NotFoundView, UnauthorizedView
+
+
+templatedir('templates')
+
+
+class Master(Layout):
+ grok.name('master')
+ grok.context(Exception)
+
+
+class MyExceptionView(ExceptionView):
+ grok.name('index')
+
+class MyUnauthorizedView(UnauthorizedView):
+ grok.name('index')
+
+class MyNotFoundView(NotFoundView):
+ grok.name('index')
More information about the checkins
mailing list