[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser - meta.zcml:1.15 metaconfigure.py:1.15 metadirectives.py:1.9

Jim Fulton cvs-admin at zope.org
Wed Dec 3 00:40:30 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/publisher/browser
In directory cvs.zope.org:/tmp/cvs-serv18863/src/zope/app/publisher/browser

Modified Files:
	meta.zcml metaconfigure.py metadirectives.py 
Log Message:
Added a new directive for simplifying creation of add-menu entries.


=== Zope3/src/zope/app/publisher/browser/meta.zcml 1.14 => 1.15 ===
--- Zope3/src/zope/app/publisher/browser/meta.zcml:1.14	Fri Nov 21 12:10:25 2003
+++ Zope3/src/zope/app/publisher/browser/meta.zcml	Wed Dec  3 00:40:29 2003
@@ -146,6 +146,12 @@
         handler=".icon.IconDirective"
         />
 
+    <meta:directive
+        name="addMenuItem"
+        schema=".metadirectives.IAddMenuItem"
+        handler=".metaconfigure.addMenuItem"
+        />
+
   </meta:directives>
 
 </configure>


=== Zope3/src/zope/app/publisher/browser/metaconfigure.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/publisher/browser/metaconfigure.py:1.14	Fri Nov 21 12:10:27 2003
+++ Zope3/src/zope/app/publisher/browser/metaconfigure.py	Wed Dec  3 00:40:29 2003
@@ -22,6 +22,10 @@
 
 from zope.app.component.metaconfigure import skin, layer
 from zope.app.component.metaconfigure import handler
+from zope.app.interfaces.container import IAdding
+from zope.app.publisher.browser.globalbrowsermenuservice \
+     import menuItemDirective
+from zope.app.component.contentdirective import ContentDirective
 
 # referred to through ZCML
 from zope.app.publisher.browser.resourcemeta import resource, \
@@ -52,3 +56,45 @@
                     for_.__module__+'.'+for_.getName(),
                     for_)
             )
+
+_next_id = 0
+def addMenuItem(_context, title, class_=None, factory=None, description='',
+                permission=None, filter=None, view=None):
+    """Create an add menu item for a given class or factory
+
+    As a convenience, a class can be provided, in which case, a factory is
+    automatically defined baded on the class.
+    """
+    if class_ is None:
+        if factory is None:
+            raise ValueError("Must specify either class or factory")
+    else:
+        if factory is not None:
+            raise ValueError("Can't specify both class and factory")
+        if permission is None:
+            raise ValueError(
+                "A permission must be specified when a class is used")
+        global _next_id
+        _next_id += 1
+        factory = "zope.app.browser.add.%s.f%s" % (
+            class_.__name__, _next_id) 
+        ContentDirective(_context, class_).factory(
+            _context,
+            permission=permission,
+            id = factory)
+
+    extra = {'factory': factory}
+
+    if view:
+        action = view
+    else:
+        action = factory
+
+    menuItemDirective(_context, 'zope.app.container.add', IAdding,
+                      action, title, description, filter,
+                      permission, extra)
+
+
+def test_reset():
+    global _next_id
+    _next_id = 0


=== Zope3/src/zope/app/publisher/browser/metadirectives.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/publisher/browser/metadirectives.py:1.8	Fri Nov 21 12:10:27 2003
+++ Zope3/src/zope/app/publisher/browser/metadirectives.py	Wed Dec  3 00:40:29 2003
@@ -20,7 +20,7 @@
 from zope.interface import Interface
 from zope.configuration.fields import GlobalObject, Tokens, Path, \
      PythonIdentifier, MessageID
-from zope.schema import TextLine, Id
+from zope.schema import TextLine, Text, Id
 
 from zope.app.component.metadirectives import IBasicViewInformation
 
@@ -546,4 +546,70 @@
         For information on layers, see the documentation for the skin
         directive. Defaults to "default".""",
         required=False
+        )
+
+class IAddMenuItem(Interface):
+    """Define an add-menu item
+    """
+
+    class_ = GlobalObject(
+        __doc__ = """Class
+
+                 A class to be used as a factory for creating new objects
+                 """,
+        required = False,
+        )
+
+    factory = GlobalObject(
+        __doc__ = """Factory
+
+                 A factory for creating new objects
+                 """,
+        required = False,
+        )
+
+    title = TextLine(
+        __doc__ = """Title
+
+                  A one-line description of the objects to be added
+                  """,
+        required = True,
+        )
+
+    description = Text(
+        __doc__ = """Text
+
+                  A multi-line description of the objects to be added
+                  """,
+        required = False,
+        )
+
+    permission = Id(
+        title=u"The permission needed to add an object.",
+        required=False,
+        )
+
+    filter = TextLine(
+        title=u"A condition for displaying the menu item",
+        description=u"""
+        The condition is given as a TALES expression. The expression
+        has access to the variables:
+
+        context -- The object the menu is being displayed for
+
+        request -- The browser request
+
+        nothing -- None
+
+        The menu item will not be displayed if there is a filter and
+        the filter evaluates to a false value.""",
+        required=False
+        )
+
+    view = TextLine(
+        __doc__ = """Custom view name
+
+                  The name of a custom add view
+                  """,
+        required = False,
         )




More information about the Zope3-Checkins mailing list