[Checkins] SVN: grok/trunk/src/grok/ make sure the update/render for the error view baseclasses play nicely with grokcore.view.View and zope.errorview

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Jan 20 06:24:58 EST 2011


Log message for revision 119745:
  make sure the update/render for the error view baseclasses play nicely with grokcore.view.View and zope.errorview

Changed:
  U   grok/trunk/src/grok/components.py
  U   grok/trunk/src/grok/ftests/errorviews/errorviews.py

-=-
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2011-01-20 09:31:02 UTC (rev 119744)
+++ grok/trunk/src/grok/components.py	2011-01-20 11:24:57 UTC (rev 119745)
@@ -22,7 +22,7 @@
 
 import zope.location
 from zope.container.interfaces import IReadContainer
-from zope.errorview.browser import ExceptionView, NotFoundView, UnauthorizedView
+import zope.errorview.browser
 from zope import component
 from zope import interface
 from zope.interface.common.interfaces import IException
@@ -153,21 +153,82 @@
         grokcore.message.send(message, type=type, name='session')
 
 
-class ExceptionView(ExceptionView, grokcore.view.View):
+class ExceptionView(View, zope.errorview.browser.ExceptionView):
+    """Base class for rendering views for uncaught exceptions that occur during
+    the application run-time and are not otherwise rendered.
+
+    Note that when this class in not subclassed, the default error view
+    from zope.errorview is being rendered.
+    """
     grok.context(IException)
     grok.name('index.html')
 
+    def update(self):
+        return zope.errorview.browser.ExceptionView.update(self)
 
-class NotFoundView(NotFoundView, grokcore.view.View):
+    def render(self):
+        """An error view can either be rendered by an associated template, or
+        it can implement this method to render itself from Python. This is
+        useful if the view's output isn't XML/HTML but something computed in
+        Python (plain text, PDF, etc.)
+
+        Contrary to regular views, render() does *not* accept any parameters.
+        """
+        return zope.errorview.browser.ExceptionView.render(self)
+
+    render.base_method = True
+
+
+class NotFoundView(View, zope.errorview.browser.NotFoundView):
+    """Base class for rendering views for INotFound exceptions.
+
+    Note that when this class in not subclassed, the default error view
+    from zope.errorview is being rendered.
+    """
     grok.context(INotFound)
     grok.name('index.html')
 
+    def update(self):
+        return zope.errorview.browser.NotFoundView.update(self)
 
-class UnauthorizedView(UnauthorizedView, grokcore.view.View):
+    def render(self):
+        """An error view can either be rendered by an associated template, or
+        it can implement this method to render itself from Python. This is
+        useful if the view's output isn't XML/HTML but something computed in
+        Python (plain text, PDF, etc.)
+
+        Contrary to regular views, render() does *not* accept any parameters.
+        """
+        return zope.errorview.browser.NotFoundView.render(self)
+
+    render.base_method = True
+
+
+class UnauthorizedView(View, zope.errorview.browser.UnauthorizedView):
+    """Base class for rendering views for IUnauthorized exceptions.
+
+    Note that when this class in not subclassed, the default error view
+    from zope.errorview is being rendered.
+    """
     grok.context(IUnauthorized)
     grok.name('index.html')
 
+    def update(self):
+        return zope.errorview.browser.UnauthorizedView.update(self)
 
+    def render(self):
+        """An error view can either be rendered by an associated template, or
+        it can implement this method to render itself from Python. This is
+        useful if the view's output isn't XML/HTML but something computed in
+        Python (plain text, PDF, etc.)
+
+        Contrary to regular views, render() does *not* accept any parameters.
+        """
+        return zope.errorview.browser.UnauthorizedView.render(self)
+
+    render.base_method = True
+
+
 class Form(grokcore.formlib.Form, View):
     """The base class for forms in Grok applications.
 

Modified: grok/trunk/src/grok/ftests/errorviews/errorviews.py
===================================================================
--- grok/trunk/src/grok/ftests/errorviews/errorviews.py	2011-01-20 09:31:02 UTC (rev 119744)
+++ grok/trunk/src/grok/ftests/errorviews/errorviews.py	2011-01-20 11:24:57 UTC (rev 119745)
@@ -47,7 +47,6 @@
   >>> class MyNotFoundView(NotFoundView):
   ...     def render(self):
   ...         return u'This is my idea of a not found view.'
-  >>> from grok.testing import grok_component
   >>> grok_component('MyNotFoundView', MyNotFoundView)
   True
 
@@ -61,7 +60,6 @@
   >>> class MyUnauthorizedView(UnauthorizedView):
   ...     def render(self):
   ...         return u'This is my idea of an unauthorized view.'
-  >>> from grok.testing import grok_component
   >>> grok_component('MyUnauthorizedView', MyUnauthorizedView)
   True
 
@@ -71,8 +69,31 @@
   >>> print view()
   This is my idea of an unauthorized view.
 
+  >>> class WithTemplate(ExceptionView):
+  ...     grok.template('exceptionview_template')
+  >>> grok_component('WithTemplate', WithTemplate)
+  True
+
+  >>> view = getMultiAdapter((Exception(), TestRequest()), name='index.html')
+  >>> print view()
+  <html>
+  <body>
+  <h1>Something went wrong!</h1>
+  <p>Exception()</p>
+  </body>
+  </html>
+
 """
 import grok
 
 class MockPrincipal(object):
     id = 'mockprincipal'
+
+exceptionview_template = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Something went wrong!</h1>
+<p tal:content="python: repr(context)"/>
+</body>
+</html>
+""")



More information about the checkins mailing list