[Checkins] SVN: megrok.layout/trunk/ make the mixing of baseclass for the exception pages symetrical to those of normal view pages and form pages
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Wed Jul 13 05:28:26 EDT 2011
Log message for revision 122166:
make the mixing of baseclass for the exception pages symetrical to those of normal view pages and form pages
Changed:
U megrok.layout/trunk/CHANGES.txt
U megrok.layout/trunk/src/megrok/layout/README.txt
U megrok.layout/trunk/src/megrok/layout/__init__.py
U megrok.layout/trunk/src/megrok/layout/components.py
U megrok.layout/trunk/src/megrok/layout/tests/models/errorviews.py
-=-
Modified: megrok.layout/trunk/CHANGES.txt
===================================================================
--- megrok.layout/trunk/CHANGES.txt 2011-07-13 09:20:32 UTC (rev 122165)
+++ megrok.layout/trunk/CHANGES.txt 2011-07-13 09:28:26 UTC (rev 122166)
@@ -4,6 +4,9 @@
1.4 (unreleased)
----------------
+- Added ExceptionPage, NotFoundPage and UnauthorizedPage layout-aware
+ components.
+
- Fixed default template for megrok.layout.Form component.
1.3 (2011-01-12)
Modified: megrok.layout/trunk/src/megrok/layout/README.txt
===================================================================
--- megrok.layout/trunk/src/megrok/layout/README.txt 2011-07-13 09:20:32 UTC (rev 122165)
+++ megrok.layout/trunk/src/megrok/layout/README.txt 2011-07-13 09:28:26 UTC (rev 122166)
@@ -105,5 +105,5 @@
==================
Baseclasses for Form views (Form, AddForm, EditForm and DisplayForm) and Error
-views (NotFoundView, ExceptionView, UnauthorizedView) are available which are
+views (NotFoundPage, ExceptionPage, UnauthorizedPage) are available which are
all aware of Layout components like Page is.
Modified: megrok.layout/trunk/src/megrok/layout/__init__.py
===================================================================
--- megrok.layout/trunk/src/megrok/layout/__init__.py 2011-07-13 09:20:32 UTC (rev 122165)
+++ megrok.layout/trunk/src/megrok/layout/__init__.py 2011-07-13 09:28:26 UTC (rev 122166)
@@ -3,5 +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
+from megrok.layout.components import UnauthorizedPage, NotFoundPage
+from megrok.layout.components import ExceptionPage
Modified: megrok.layout/trunk/src/megrok/layout/components.py
===================================================================
--- megrok.layout/trunk/src/megrok/layout/components.py 2011-07-13 09:20:32 UTC (rev 122165)
+++ megrok.layout/trunk/src/megrok/layout/components.py 2011-07-13 09:28:26 UTC (rev 122166)
@@ -81,15 +81,12 @@
return self.render()
-class Page(grokcore.view.View, UtilityView):
- """A view class.
+class LayoutAware(UtilityView):
+ """A mixin to make views aware of layouts.
"""
grok.baseclass()
- grok.implements(IPage)
- def __init__(self, context, request):
- super(Page, self).__init__(context, request)
- self.layout = None
+ layout = None
def __call__(self):
mapply(self.update, (), self.request)
@@ -102,7 +99,7 @@
return self.layout(self)
def default_namespace(self):
- namespace = super(Page, self).default_namespace()
+ namespace = super(LayoutAware, self).default_namespace()
namespace['layout'] = self.layout
return namespace
@@ -113,25 +110,9 @@
return mapply(self.render, (), self.request)
-class LayoutAwareForm(UtilityView):
+class LayoutAwareForm(LayoutAware):
"""A mixin to make form aware of layouts.
"""
-
- def __init__(self, context, request):
- super(LayoutAwareForm, self).__init__(context, request)
- self.layout = None
-
- def default_namespace(self):
- namespace = super(LayoutAwareForm, self).default_namespace()
- namespace['layout'] = self.layout
- return namespace
-
- def content(self):
- template = getattr(self, 'template', None)
- if template is not None:
- return self._render_template()
- return mapply(self.render, (), self.request)
-
def __call__(self):
"""Calls update and returns the layout template which calls render.
"""
@@ -140,16 +121,50 @@
# A redirect was triggered somewhere in update(). Don't
# continue rendering the template or doing anything else.
return
-
+ # update_form() is what make a layout-aware form different from
+ # 'regular" layout-aware component.
self.update_form()
if self.request.response.getStatus() in (302, 303):
return
-
self.layout = zope.component.getMultiAdapter(
(self.request, self.context), ILayout)
return self.layout(self)
+class Page(LayoutAware, grokcore.view.View):
+ """A view class.
+ """
+ grok.baseclass()
+ grok.implements(IPage)
+
+
+class ExceptionPage(
+ LayoutAware,
+ zope.errorview.browser.ExceptionView,
+ grokcore.view.View
+ ):
+ grok.context(zope.interface.common.interfaces.IException)
+ grok.baseclass()
+
+
+class NotFoundPage(
+ LayoutAware,
+ zope.errorview.browser.NotFoundView,
+ grokcore.view.View
+ ):
+ grok.context(zope.publisher.interfaces.INotFound)
+ grok.baseclass()
+
+
+class UnauthorizedPage(
+ LayoutAware,
+ zope.errorview.browser.UnauthorizedView,
+ grokcore.view.View
+ ):
+ grok.context(zope.security.interfaces.IUnauthorized)
+ grok.baseclass()
+
+
# Default forms for form without the html and body tags
default_form_template = grokcore.view.PageTemplateFile(
os.path.join('templates', 'default_edit_form.pt'))
@@ -188,29 +203,3 @@
"""
grok.baseclass()
template = default_display_template
-
-
-class ExceptionView(zope.errorview.browser.ExceptionView, Page):
- grok.context(zope.interface.common.interfaces.IException)
- grok.baseclass()
-
- def __call__(self):
- # Make sure the __call__ handling of the Page component is
- # used, not that of any of the bases in the ExceptionView class
- # hierarchy.
- return Page.__call__(self)
-
-class NotFoundView(zope.errorview.browser.NotFoundView, Page):
- grok.context(zope.publisher.interfaces.INotFound)
- grok.baseclass()
-
- def __call__(self):
- return Page.__call__(self)
-
-
-class UnauthorizedView(zope.errorview.browser.UnauthorizedView, Page):
- grok.context(zope.security.interfaces.IUnauthorized)
- grok.baseclass()
-
- def __call__(self):
- return Page.__call__(self)
Modified: megrok.layout/trunk/src/megrok/layout/tests/models/errorviews.py
===================================================================
--- megrok.layout/trunk/src/megrok/layout/tests/models/errorviews.py 2011-07-13 09:20:32 UTC (rev 122165)
+++ megrok.layout/trunk/src/megrok/layout/tests/models/errorviews.py 2011-07-13 09:28:26 UTC (rev 122166)
@@ -3,7 +3,7 @@
>>> from zope.publisher.browser import TestRequest
>>> view = getMultiAdapter((Exception(), TestRequest()), name='index')
>>> import megrok.layout
- >>> isinstance(view, megrok.layout.ExceptionView)
+ >>> isinstance(view, megrok.layout.ExceptionPage)
True
>>> print view.render()
A system error occurred.
@@ -42,22 +42,19 @@
import grokcore.component as grok
from grokcore.view import templatedir
-from megrok.layout import Layout, ExceptionView, NotFoundView, UnauthorizedView
+from megrok.layout import Layout, ExceptionPage, NotFoundPage, UnauthorizedPage
-
templatedir('templates')
-
class Master(Layout):
grok.name('master')
grok.context(Exception)
-
-class MyExceptionView(ExceptionView):
+class MyExceptionPage(ExceptionPage):
grok.name('index')
-class MyUnauthorizedView(UnauthorizedView):
+class MyUnauthorizedPage(UnauthorizedPage):
grok.name('index')
-class MyNotFoundView(NotFoundView):
+class MyNotFoundPage(NotFoundPage):
grok.name('index')
More information about the checkins
mailing list