[Checkins] SVN: z3ext.layout/trunk/ Added LayoutNotFound exception

Nikolay Kim fafhrd at datacom.kz
Wed May 21 15:43:52 EDT 2008


Log message for revision 86884:
  Added LayoutNotFound exception

Changed:
  U   z3ext.layout/trunk/CHANGES.txt
  U   z3ext.layout/trunk/setup.py
  U   z3ext.layout/trunk/src/z3ext/layout/README.txt
  U   z3ext.layout/trunk/src/z3ext/layout/interfaces.py
  U   z3ext.layout/trunk/src/z3ext/layout/layout.py
  U   z3ext.layout/trunk/src/z3ext/layout/tests.py
  A   z3ext.layout/trunk/src/z3ext/layout/zcml.txt

-=-
Modified: z3ext.layout/trunk/CHANGES.txt
===================================================================
--- z3ext.layout/trunk/CHANGES.txt	2008-05-21 17:15:05 UTC (rev 86883)
+++ z3ext.layout/trunk/CHANGES.txt	2008-05-21 19:43:51 UTC (rev 86884)
@@ -2,6 +2,12 @@
 CHANGES
 =======
 
+1.4.3 (2008-05-22)
+------------------
+
+- Added LayoutNotFound exception
+
+
 1.4.2 (2008-05-14)
 ------------------
 

Modified: z3ext.layout/trunk/setup.py
===================================================================
--- z3ext.layout/trunk/setup.py	2008-05-21 17:15:05 UTC (rev 86883)
+++ z3ext.layout/trunk/setup.py	2008-05-21 19:43:51 UTC (rev 86884)
@@ -64,8 +64,7 @@
 			  'zope.app.component',
 			  'zope.app.publisher',
 			  'zope.app.pagetemplate',
-                          'z3c.autoinclude>=0.2',
-			  'z3ext.statusmessage',
+                          'z3c.autoinclude',
                           ],
       extras_require = dict(test=['zope.app.container',
                                   'zope.app.testing',

Modified: z3ext.layout/trunk/src/z3ext/layout/README.txt
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/README.txt	2008-05-21 17:15:05 UTC (rev 86883)
+++ z3ext.layout/trunk/src/z3ext/layout/README.txt	2008-05-21 19:43:51 UTC (rev 86884)
@@ -21,11 +21,12 @@
 
   >>> temp_dir = tempfile.mkdtemp()
   >>> layoutportal = os.path.join(temp_dir, 'layoutportal.pt')
-  >>> open(layoutportal, 'w').write('''<html>
-  ... <head><title>My portal</title></head>
-  ...   <body><div id="portal" tal:content="structure view/render">
-  ...   </div>
-  ... </body>
+  >>> open(layoutportal, 'w').write(
+  ... '''<html>
+  ...   <body>
+  ...      <div id="portal" tal:content="structure view/render">
+  ...      </div>
+  ...   </body>
   ... </html>''')
 
 Let's define 'portal' layout
@@ -72,7 +73,7 @@
   >>> request = TestRequest()
   >>> view = MyView(root, request)
 
-It return context __name__
+It returns context __name__
 
   >>> view.__call__()
   'root'
@@ -94,15 +95,14 @@
 
   >>> print view()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <div id="workspace">
-  <div id="content">root</div>
-  </div>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <div id="workspace">
+          <div id="content">root</div>
+        </div>
+      </div>
+    </body>
   </html>
-  <BLANKLINE>
 
 All 3 our layout rendered. view rendered inside nameless layout then in
 -> 'workspace' layout -> 'portal' layout
@@ -114,15 +114,14 @@
 
   >>> print MyView(folder1, request)()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <div id="workspace">
-  <div id="content">folder1</div>
-  </div>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <div id="workspace">
+          <div id="content">folder1</div>
+        </div>
+      </div>
+    </body>
   </html>
-  <BLANKLINE>
 
 And another one.
 
@@ -134,15 +133,14 @@
 
   >>> print MyView(folder1_1_1, request)()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <div id="workspace">
-  <div id="content">folder1_1_1</div>
-  </div>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <div id="workspace">
+          <div id="content">folder1_1_1</div>
+        </div>
+      </div>
+    </body>
   </html>
-  <BLANKLINE>
 
 This is all quite easy. Let's use more complex example. For example 
 later other developers decide change how portal looks for folder1 object
@@ -176,60 +174,59 @@
 
   >>> print MyView(folder1, request)()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <table id="columns">
-    <tr>
-      <td id="column1">Column1</td>
-      <td id="column2">
-  <div id="content">folder1</div>
-  </td>
-      <td id="column3">Column3</td>
-    </tr>
-  </table>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <table id="columns">
+          <tr>
+            <td id="column1">Column1</td>
+            <td id="column2">
+              <div id="content">folder1</div>
+            </td>
+            <td id="column3">Column3</td>
+          </tr>
+        </table>
+      </div>
+    </body>
   </html>
-  <BLANKLINE>
 
 folder1 uses new 'workspace' layout, but what about other folders
 
   >>> print MyView(folder1_1, request)()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <table id="columns">
-    <tr>
-      <td id="column1">Column1</td>
-      <td id="column2">
-  <div id="content">folder1_1</div>
-  </td>
-      <td id="column3">Column3</td>
-    </tr>
-  </table>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <table id="columns">
+          <tr>
+            <td id="column1">Column1</td>
+            <td id="column2">
+              <div id="content">folder1_1</div>
+            </td>
+            <td id="column3">Column3</td>
+          </tr>
+        </table>
+      </div>
+    </body>
   </html>
-  <BLANKLINE>
 
+
   >>> print MyView(folder1_1_1, request)()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <table id="columns">
-    <tr>
-      <td id="column1">Column1</td>
-      <td id="column2">
-  <div id="content">folder1_1_1</div>
-  </td>
-      <td id="column3">Column3</td>
-    </tr>
-  </table>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <table id="columns">
+          <tr>
+            <td id="column1">Column1</td>
+            <td id="column2">
+              <div id="content">folder1_1_1</div>
+            </td>
+            <td id="column3">Column3</td>
+          </tr>
+        </table>
+      </div>
+    </body>
   </html>
-  <BLANKLINE>
 
+
 Now we also change how folder1_1 looks, we can replace nameless layout.
 Also we can use nameless layout as parent with layout="."
 
@@ -252,26 +249,25 @@
   
   >>> print MyView(folder1_1, request)()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <table id="columns">
-    <tr>
-      <td id="column1">Column1</td>
-      <td id="column2">
-  <div id="content">
-  <div id="content1_1">
-    <h1>Folder1_1</h1>
-    <div>folder1_1</div>
-  </div>
-  </div>
-  </td>
-      <td id="column3">Column3</td>
-    </tr>
-  </table>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <table id="columns">
+          <tr>
+            <td id="column1">Column1</td>
+            <td id="column2">
+              <div id="content">
+                <div id="content1_1">
+                  <h1>Folder1_1</h1>
+                  <div>folder1_1</div>
+                </div>
+              </div>
+            </td>
+            <td id="column3">Column3</td>
+          </tr>
+        </table>
+      </div>
+     </body>
   </html>
-  <BLANKLINE>
 
 It still uses nameless layout that we defined for 'root'. 
 
@@ -296,99 +292,27 @@
 
   >>> print MyView(folder1_1_1, request)()
   <html>
-  <head><title>My portal</title></head>
-    <body><div id="portal">
-  <table id="columns">
-    <tr>
-      <td id="column1">Column1</td>
-      <td id="column2">
-  <div id="content">
-  <div id="content1_1">
-    <h1>Folder1_1</h1>
-    <div>
-  <div id="content1_1_1">
-    <h1>Folder1_1_1</h1>
-    <div>folder1_1_1</div>
-  </div>
-  </div>
-  </div>
-  </div>
-  </td>
-      <td id="column3">Column3</td>
-    </tr>
-  </table>
-  </div>
-  </body>
+    <body>
+      <div id="portal">
+        <table id="columns">
+          <tr>
+            <td id="column1">Column1</td>
+            <td id="column2">
+              <div id="content">
+                <div id="content1_1">
+                  <h1>Folder1_1</h1>
+                  <div>
+                    <div id="content1_1_1">
+                      <h1>Folder1_1_1</h1>
+                      <div>folder1_1_1</div>
+                    </div>
+                  </div>
+                </div>
+              </div>
+            </td>
+            <td id="column3">Column3</td>
+          </tr>
+        </table>
+      </div>
+    </body>
   </html>
-  <BLANKLINE>
-
-Just tests
-
-We should provide template 
-
-  >>> context = xmlconfig.string("""
-  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
-  ...   <z3ext:layout
-  ...     layout="."
-  ...     template="unknown.pt" />
-  ... </configure>""", context)
-  Traceback (most recent call last):
-  ...
-  ZopeXMLConfigurationError: ...
-  ... ConfigurationError: ('No such file', ...unknown.pt')
-
-We can register layout for context or for view
-
-  >>> context = xmlconfig.string("""
-  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
-  ...   <z3ext:layout
-  ...     layout="."
-  ...     template="%s" />
-  ... </configure>"""%layoutcontent1_1_1, context)
-  Traceback (most recent call last):
-  ...
-  ZopeXMLConfigurationError: ...
-  ... ConfigurationError: FOR or VIEW are required.
-
-We can register layout for view
-
-  >>> context = xmlconfig.string("""
-  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
-  ...   <z3ext:layout
-  ...     layout="."
-  ...     view="z3ext.layout.tests.IFolder1_1_1"
-  ...     template="%s" />
-  ... </configure>"""%layoutcontent1_1_1, context)
-
-  >>> context = xmlconfig.string("""
-  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
-  ...   <z3ext:layout
-  ...     name="layout1"
-  ...     layout="."
-  ...     view="z3ext.layout.tests.IFolder1_1_1"
-  ...     template="%s" />
-  ... </configure>"""%layoutcontent1_1_1, context)
-
-We can add custom marker interface for layout
-
-  >>> context = xmlconfig.string("""
-  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
-  ...   <z3ext:layout
-  ...     name="layout2"
-  ...     layout="."
-  ...     view="z3ext.layout.tests.IFolder1_1_1"
-  ...     provides="z3ext.layout.tests.IFolder1"
-  ...     template="%s" />
-  ... </configure>"""%layoutcontent1_1_1, context)
-
-We can use custom layout class
-
-  >>> context = xmlconfig.string("""
-  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
-  ...   <z3ext:layout
-  ...     name="layout3"
-  ...     layout="."
-  ...     view="z3ext.layout.tests.IFolder1_1_1"
-  ...     class="z3ext.layout.tests.MyLayout"
-  ...     template="%s" />
-  ... </configure>"""%layoutcontent1_1_1, context)

Modified: z3ext.layout/trunk/src/z3ext/layout/interfaces.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/interfaces.py	2008-05-21 17:15:05 UTC (rev 86883)
+++ z3ext.layout/trunk/src/z3ext/layout/interfaces.py	2008-05-21 19:43:51 UTC (rev 86884)
@@ -19,6 +19,10 @@
 from zope.publisher.interfaces.browser import IBrowserPage
 
 
+class LayoutNotFound(LookupError):
+    """ Layout not found exception """
+
+
 class IPagelet(IBrowserPage):
     """ pagelet """
 

Modified: z3ext.layout/trunk/src/z3ext/layout/layout.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/layout.py	2008-05-21 17:15:05 UTC (rev 86883)
+++ z3ext.layout/trunk/src/z3ext/layout/layout.py	2008-05-21 19:43:51 UTC (rev 86884)
@@ -23,7 +23,7 @@
 from zope.pagetemplate.pagetemplatefile import PageTemplateFile
 
 from z3ext.layout.pagelet import queryLayout
-from z3ext.layout.interfaces import ILayout, ILayoutTemplateFile
+from z3ext.layout.interfaces import LayoutNotFound, ILayout, ILayoutTemplateFile
 
 
 class ViewMapper(object):
@@ -115,5 +115,8 @@
             if layout is not None:
                 return layout(view=view, *args, **kw)
 
-        layout = queryLayout(self.context, self.request, name=self.layout)
-        return layout(maincontext=maincontext, *args, **kw)
+        layout = queryLayout(self.view, self.context, self.request, name=self.layout)
+        if layout is not None:
+            return layout(*args, **kw)
+
+        raise LayoutNotFound(self.layout)

Modified: z3ext.layout/trunk/src/z3ext/layout/tests.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/tests.py	2008-05-21 17:15:05 UTC (rev 86883)
+++ z3ext.layout/trunk/src/z3ext/layout/tests.py	2008-05-21 19:43:51 UTC (rev 86884)
@@ -58,14 +58,19 @@
 
 def test_suite():
     return unittest.TestSuite((
-            doctest.DocFileSuite(
-                'README.txt',
-                setUp=setUp, tearDown=tearDown,
-                optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
-                ),
-            doctest.DocFileSuite(
-                'pagelet.txt',
+        doctest.DocFileSuite(
+            'README.txt',
             setUp=setUp, tearDown=tearDown,
-                optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
-                ),
-            ))
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+            ),
+        doctest.DocFileSuite(
+            'pagelet.txt',
+            setUp=setUp, tearDown=tearDown,
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+            ),
+        doctest.DocFileSuite(
+            'zcml.txt',
+            setUp=setUp, tearDown=tearDown,
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+            ),
+        ))

Added: z3ext.layout/trunk/src/z3ext/layout/zcml.txt
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/zcml.txt	                        (rev 0)
+++ z3ext.layout/trunk/src/z3ext/layout/zcml.txt	2008-05-21 19:43:51 UTC (rev 86884)
@@ -0,0 +1,86 @@
+
+Just tests
+
+  >>> import tempfile, os.path
+  >>> import z3ext.layout
+  >>> from zope.configuration import xmlconfig
+  >>> context = xmlconfig.file('meta.zcml', z3ext.layout)
+
+  >>> temp_dir = tempfile.mkdtemp()
+  >>> layoutportal = os.path.join(temp_dir, 'layoutportal.pt')
+  >>> open(layoutportal, 'w').write(
+  ... '''<html>
+  ...   <body>
+  ...      <div id="portal" tal:content="structure view/render">
+  ...      </div>
+  ...   </body>
+  ... </html>''')
+
+We should provide template 
+
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:layout
+  ...     layout="."
+  ...     template="unknown.pt" />
+  ... </configure>""", context)
+  Traceback (most recent call last):
+  ...
+  ZopeXMLConfigurationError: ...
+  ... ConfigurationError: ('No such file', ...unknown.pt')
+
+We can register layout for context or for view
+
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:layout
+  ...     layout="."
+  ...     template="%s" />
+  ... </configure>"""%layoutportal, context)
+  Traceback (most recent call last):
+  ...
+  ZopeXMLConfigurationError: ...
+  ... ConfigurationError: FOR or VIEW are required.
+
+We can register layout for view
+
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:layout
+  ...     layout="."
+  ...     view="z3ext.layout.tests.IFolder1_1_1"
+  ...     template="%s" />
+  ... </configure>"""%layoutportal, context)
+
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:layout
+  ...     name="layout1"
+  ...     layout="."
+  ...     view="z3ext.layout.tests.IFolder1_1_1"
+  ...     template="%s" />
+  ... </configure>"""%layoutportal, context)
+
+We can add custom marker interface for layout
+
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:layout
+  ...     name="layout2"
+  ...     layout="."
+  ...     view="z3ext.layout.tests.IFolder1_1_1"
+  ...     provides="z3ext.layout.tests.IFolder1"
+  ...     template="%s" />
+  ... </configure>"""%layoutportal, context)
+
+We can use custom layout class
+
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:layout
+  ...     name="layout3"
+  ...     layout="."
+  ...     view="z3ext.layout.tests.IFolder1_1_1"
+  ...     class="z3ext.layout.tests.MyLayout"
+  ...     template="%s" />
+  ... </configure>"""%layoutportal, context)



More information about the Checkins mailing list