[Checkins] SVN: grokcore.layout/trunk/ Add a test and update CHANGES for last change.

Sylvain Viollow cvs-admin at zope.org
Mon Apr 30 09:04:52 UTC 2012


Log message for revision 125432:
  Add a test and update CHANGES for last change.
  

Changed:
  U   grokcore.layout/trunk/CHANGES.txt
  A   grokcore.layout/trunk/src/grokcore/layout/tests/layout/selectlayout.py

-=-
Modified: grokcore.layout/trunk/CHANGES.txt
===================================================================
--- grokcore.layout/trunk/CHANGES.txt	2012-04-30 08:55:52 UTC (rev 125431)
+++ grokcore.layout/trunk/CHANGES.txt	2012-04-30 09:04:49 UTC (rev 125432)
@@ -4,6 +4,11 @@
 1.5 (unreleased)
 ----------------
 
+- Add a directive ``layout`` to select a different type of layout. A layout
+  type is defined on a ``Layout`` component with the help of the
+  ``grokcore.component.provides`` directive. It defaults to ``ILayout``
+  for compatibility.
+
 - Change how the static resources are associated to a ``Layout``,
   using the new name ``__static_name__`` set by the template grokker.
 

Added: grokcore.layout/trunk/src/grokcore/layout/tests/layout/selectlayout.py
===================================================================
--- grokcore.layout/trunk/src/grokcore/layout/tests/layout/selectlayout.py	                        (rev 0)
+++ grokcore.layout/trunk/src/grokcore/layout/tests/layout/selectlayout.py	2012-04-30 09:04:49 UTC (rev 125432)
@@ -0,0 +1,64 @@
+"""
+  >>> one = One()
+
+  >>> from zope.publisher.browser import TestRequest
+  >>> from zope.component import getMultiAdapter
+
+  >>> request = TestRequest()
+
+We test that we can retrieve the default layout for the page that
+doesn't select any specific layout::
+
+  >>> view = getMultiAdapter((one, request), name="viewone")
+  >>> print view()
+  Layout One
+
+We test that we can retrieve the default layout for the page that
+select a specific layout::
+
+  >>> view = getMultiAdapter((one, request), name="viewtwo")
+  >>> print view()
+  Layout Two
+
+"""
+import grokcore.view as grok
+from zope.interface import Interface
+from grokcore.layout import Layout, Page, ILayout, layout
+
+
+class One(grok.Context):
+    pass
+
+
+class LayoutOne(Layout):
+    grok.context(One)
+
+    def render(self):
+        return "Layout One"
+
+
+class ILayoutTwo(ILayout):
+    pass
+
+
+class LayoutTwo(Layout):
+    grok.context(One)
+    grok.provides(ILayoutTwo)
+
+    def render(self):
+        return "Layout Two"
+
+
+class ViewOne(Page):
+    grok.context(Interface)
+
+    def render(self):
+        return "MyView on regular layout"
+
+
+class ViewTwo(Page):
+    grok.context(Interface)
+    layout(ILayoutTwo)
+
+    def render(self):
+        return "MyView on layout two"



More information about the checkins mailing list