[Zope3-checkins] SVN: Zope3/branches/roger-contentprovider/src/zope/portlet/meta Added portletManagerDirective

Roger Ineichen roger at projekt01.ch
Sat Oct 8 08:55:12 EDT 2005


Log message for revision 38943:
  Added portletManagerDirective
  --> work in progress

Changed:
  U   Zope3/branches/roger-contentprovider/src/zope/portlet/meta.zcml
  U   Zope3/branches/roger-contentprovider/src/zope/portlet/metaconfigure.py

-=-
Modified: Zope3/branches/roger-contentprovider/src/zope/portlet/meta.zcml
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/portlet/meta.zcml	2005-10-08 12:54:06 UTC (rev 38942)
+++ Zope3/branches/roger-contentprovider/src/zope/portlet/meta.zcml	2005-10-08 12:55:12 UTC (rev 38943)
@@ -4,6 +4,12 @@
   <meta:directives namespace="http://namespaces.zope.org/browser">
 
     <meta:directive
+        name="portletManager"
+        schema=".metadirectives.IPortletManagerDirective"
+        handler=".metaconfigure.portletManagerDirective"
+        />
+
+    <meta:directive
         name="portlet"
         schema=".metadirectives.IPortletDirective"
         handler=".metaconfigure.portletDirective"

Modified: Zope3/branches/roger-contentprovider/src/zope/portlet/metaconfigure.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/portlet/metaconfigure.py	2005-10-08 12:54:06 UTC (rev 38942)
+++ Zope3/branches/roger-contentprovider/src/zope/portlet/metaconfigure.py	2005-10-08 12:55:12 UTC (rev 38943)
@@ -35,6 +35,100 @@
 from zope.portlet import interfaces
 
 
+def portletManagerDirective(_context, name, permission, portletType,
+                     for_=Interface, layer=IDefaultBrowserLayer,
+                     class_=None, template=None, boxTemplate=None
+                     allowed_interface=None, allowed_attributes=None):
+
+    required = {}
+
+    # Get the permission; mainly to correctly handle CheckerPublic.
+    permission = viewmeta._handle_permission(_context, permission)
+
+    # Either the class or template must be specified.
+    if not (class_ or template):
+        raise ConfigurationError("Must specify a class or template")
+
+    # Make sure that all the non-default attribute specifications are correct.
+    if attribute != '__call__':
+        if template:
+            raise ConfigurationError(
+                "Attribute and template cannot be used together.")
+
+        # Note: The previous logic forbids this condition to evere occur.
+        if not class_:
+            raise ConfigurationError(
+                "A class must be provided if attribute is used")
+
+    # Make sure that the template exists and that all low-level API methods
+    # have the right permission.
+    if template:
+        template = os.path.abspath(str(_context.path(template)))
+        if not os.path.isfile(template):
+            raise ConfigurationError("No such file", template)
+        required['__getitem__'] = permission
+
+    # Make sure the has the right form, if specified.
+    if class_:
+        if attribute != '__call__':
+            if not hasattr(class_, attribute):
+                raise ConfigurationError(
+                    "The provided class doesn't have the specified attribute "
+                    )
+        if template:
+            # Create a new class for the portlet template and class.
+            new_class = portlet.SimplePortletClass(
+                template, bases=(class_, ), weight=weight)
+        else:
+            if not hasattr(class_, 'browserDefault'):
+                cdict = {
+                    'browserDefault':
+                    lambda self, request: (getattr(self, attribute), ())
+                    }
+            else:
+                cdict = {}
+
+            cdict['_weight'] = weight
+            cdict['__name__'] = name
+            cdict['__page_attribute__'] = attribute
+            new_class = type(class_.__name__,
+                             (class_, portlet.SimpleAttributePortlet), cdict)
+
+        if hasattr(class_, '__implements__'):
+            classImplements(new_class, IBrowserPublisher)
+
+    else:
+        # Create a new class for the portlet template alone.
+        new_class = portlet.SimplePortletClass(
+            template, name=name, weight=weight)
+
+    # Make sure the new class implements the type
+    classImplements(new_class, viewletType)
+
+    for attr_name in (attribute, 'browserDefault', '__call__',
+                      'publishTraverse', 'weight'):
+        required[attr_name] = permission
+
+    viewmeta._handle_allowed_interface(
+        _context, allowed_interface, permission, required)
+    viewmeta._handle_allowed_attributes(
+        _context, allowed_interface, permission, required)
+
+    viewmeta._handle_for(_context, for_)
+    metaconfigure.interface(_context, view)
+#    metaconfigure.interface(_context, type, IRegion)
+
+    checker.defineChecker(new_class, checker.Checker(required))
+
+    # register portlet
+    _context.action(
+        discriminator = ('portlet', for_, layer, view, viewletType, name),
+        callable = metaconfigure.handler,
+        args = ('provideAdapter',
+                (for_, layer, view), viewletType, name, new_class,
+                 _context.info),)
+
+
 def portletDirective(_context, name, permission, viewletType,
                      for_=Interface, layer=IDefaultBrowserLayer,
                      view=IBrowserView,
@@ -128,3 +222,4 @@
         args = ('provideAdapter',
                 (for_, layer, view), viewletType, name, new_class,
                  _context.info),)
+



More information about the Zope3-Checkins mailing list