[Checkins] SVN: z3ext.layout/trunk/ Pagelet without name is not allowed

Nikolay Kim fafhrd at datacom.kz
Mon Dec 22 07:29:13 EST 2008


Log message for revision 94241:
  Pagelet without name is not allowed

Changed:
  U   z3ext.layout/trunk/CHANGES.txt
  U   z3ext.layout/trunk/src/z3ext/layout/configure.zcml
  U   z3ext.layout/trunk/src/z3ext/layout/pagelet.py
  U   z3ext.layout/trunk/src/z3ext/layout/pagelet.txt
  U   z3ext.layout/trunk/src/z3ext/layout/zcml.py

-=-
Modified: z3ext.layout/trunk/CHANGES.txt
===================================================================
--- z3ext.layout/trunk/CHANGES.txt	2008-12-22 09:46:20 UTC (rev 94240)
+++ z3ext.layout/trunk/CHANGES.txt	2008-12-22 12:29:12 UTC (rev 94241)
@@ -5,8 +5,10 @@
 2.0.0 (2008-12-22)
 ------------------
 
-- Added 'type' attribute to 'z3ext:pagelet' 
+- Pagelet without name is not allowed
 
+- Added 'type' attribute to 'z3ext:pagelet'
+
 - Added 'z3ext:pageletType' directive for registering new pagelet types
 
 - multiple params is allowed for 'for' attribute

Modified: z3ext.layout/trunk/src/z3ext/layout/configure.zcml
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/configure.zcml	2008-12-22 09:46:20 UTC (rev 94240)
+++ z3ext.layout/trunk/src/z3ext/layout/configure.zcml	2008-12-22 12:29:12 UTC (rev 94241)
@@ -9,7 +9,7 @@
 
   <z3ext:pageletType
      name="pagelet"
-     interface="z3ext.layout.interfaces.IPageletType" />
+     interface="z3ext.layout.interfaces.IPagelet" />
 
   <!-- adapter provides IPagelet for (context, request) -->
   <adapter factory=".pagelet.queryPagelet" />

Modified: z3ext.layout/trunk/src/z3ext/layout/pagelet.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/pagelet.py	2008-12-22 09:46:20 UTC (rev 94240)
+++ z3ext.layout/trunk/src/z3ext/layout/pagelet.py	2008-12-22 12:29:12 UTC (rev 94241)
@@ -80,7 +80,7 @@
                 return template.render()
             raise LookupError("Can't find IPagelet for this pagelet.")
 
-    def __call__(self):
+    def __call__(self, *args, **kw):
         self.update()
 
         if self.isRedirected or self.request.response.getStatus() in (302, 303):

Modified: z3ext.layout/trunk/src/z3ext/layout/pagelet.txt
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/pagelet.txt	2008-12-22 09:46:20 UTC (rev 94240)
+++ z3ext.layout/trunk/src/z3ext/layout/pagelet.txt	2008-12-22 12:29:12 UTC (rev 94241)
@@ -331,7 +331,7 @@
   <div>My pagelet</div>
 
 We should use page template as template for pagelet or we should
-provide IPageTemplate adapter for pagelet
+provide IPagelet adapter for pagelet
 
   >>> pagelet = component.queryMultiAdapter((object(), TestRequest()), 
   ...     name='noclass.html')
@@ -350,7 +350,10 @@
 
   >>> context = xmlconfig.string("""
   ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:pageletType name="pagelet"
+  ...       interface="z3ext.layout.interfaces.IPagelet" />
   ...   <z3ext:pagelet
+  ...       type="pagelet"
   ...       for="z3ext.layout.TESTS.pageletClass"
   ...       template="%s"
   ...       permission="zope.Public" />
@@ -388,6 +391,25 @@
   u'index.html'
 
 
+Pagelte Type
+
+pagelet type can't be IPublishTraverse
+
+  >>> from zope.publisher.interfaces import IPublishTraverse
+
+  >>> class IMyPageletType(IPublishTraverse):
+  ...     pass
+
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+  ...   <z3ext:pageletType name="pagelet"
+  ...       interface="z3ext.layout.TESTS.IMyPageletType" />
+  ... </configure>""", context)
+  Traceback (most recent call last):
+  ...
+  ZopeXMLConfigurationError:...ConfigurationError: Can't use IPublishTraverse as base for pagelet type
+
+
 Typed pagelets
 
   >>> class IMyPagelet2(interface.Interface):
@@ -402,8 +424,6 @@
 
   >>> context = xmlconfig.string("""
   ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
-  ...   <z3ext:pageletType name="pagelet"
-  ...       interface="z3ext.layout.interfaces.IPagelet" />
   ...   <z3ext:pageletType name="myPagelet1"
   ...       interface="z3ext.layout.tests.ITestPagelet" />
   ...   <z3ext:pageletType name="myPagelet2"
@@ -556,9 +576,8 @@
   <div>My pagelet5</div>
 
 
-We can register nameless pagelet only if provided interface is not
-inherited from IBrowserPublisher, because we can override
-IBrowserPublisher for content.
+We can't register nameless pagelet, we can register only typed pagelet
+without name
 
   >>> class IWrongPageletInterface(IPagelet):
   ...     pass
@@ -568,23 +587,22 @@
   ...   <z3ext:pagelet
   ...       for="*"
   ...       template="%s"
-  ...       provides="z3ext.layout.TESTS.IWrongPageletInterface"
   ...       permission="zope.Public" />
   ... </configure>
   ... """%template, context)
   Traceback (most recent call last):
   ...
   ZopeXMLConfigurationError:...
-      ConfigurationError: You can't register nameless pagelet...
+      ConfigurationError: Can't create pagelet without name.
 
 If we still need nameless adapter we can use IPagelet interface
 
   >>> context = xmlconfig.string("""
   ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
   ...   <z3ext:pagelet
+  ...       type="pagelet"
   ...       for="z3ext.layout.TESTS.IContent"
   ...       template="%s"
-  ...       provides="z3ext.layout.interfaces.IPagelet"
   ...       permission="zope.Public" />
   ... </configure>
   ... """%template, context)

Modified: z3ext.layout/trunk/src/z3ext/layout/zcml.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/zcml.py	2008-12-22 09:46:20 UTC (rev 94240)
+++ z3ext.layout/trunk/src/z3ext/layout/zcml.py	2008-12-22 12:29:12 UTC (rev 94241)
@@ -24,6 +24,7 @@
 from zope.security.checker import defineChecker, Checker, CheckerPublic
 from zope.configuration.fields import Path, Tokens, GlobalObject, GlobalInterface
 from zope.configuration.exceptions import ConfigurationError
+from zope.publisher.interfaces import IPublishTraverse
 from zope.publisher.interfaces.browser import IBrowserPublisher
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.app.component.metadirectives import IBasicViewInformation
@@ -187,6 +188,9 @@
 
 
 def pageletTypeDirective(_context, name, interface):
+    if interface is not IPagelet and interface.isOrExtends(IPublishTraverse):
+        raise ConfigurationError("Can't use IPublishTraverse as base for pagelet type")
+
     provideInterface(name, interface, IPageletType)
 
 
@@ -313,6 +317,11 @@
                      allowed_interface=[], allowed_attributes=[],
                      template=u'', layout=u'', permission='zope.Public', **kwargs):
 
+    # Check paeglet name
+    if not name and not type:
+        raise ConfigurationError("Can't create pagelet without name.")
+
+    # Add IPagelet to provides
     provides = list(provides)
     if IPagelet not in provides:
         provides.append(IPagelet)
@@ -370,18 +379,6 @@
                 if not hasattr(new_class, fname):
                     setattr(new_class, fname, field.default)
 
-    # check name
-    if not name:
-        for iface in provides:
-            # allow register nameless pagelet as IPagelet
-            if iface is IPagelet:
-                continue
-
-            if iface.isOrExtends(IBrowserPublisher):
-                raise ConfigurationError(
-                    "You can't register nameless pagelet, "\
-                    "interface '%s' is or extends IBrowserPublisher"%iface)
-
     # add IPagelet to provides
     if name:
         inProvides = False



More information about the Checkins mailing list