[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - add.py:1.11

Jim Fulton jim@zope.com
Sat, 22 Mar 2003 14:11:25 -0500


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

Modified Files:
	add.py 
Log Message:
Add support for the menu and title attributes in the addform directive.


=== Zope3/src/zope/app/browser/form/add.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/browser/form/add.py:1.10	Fri Mar 21 15:57:11 2003
+++ Zope3/src/zope/app/browser/form/add.py	Sat Mar 22 14:11:24 2003
@@ -31,6 +31,8 @@
 from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
 from zope.app.browser.form.submit import Update
 from zope.app.browser.form.editview import EditView, _normalize
+from zope.app.publisher.browser.globalbrowsermenuservice \
+     import menuItemDirective
 
 class AddView(EditView):
     """Simple edit-view base class.
@@ -154,7 +156,22 @@
         class_ = None, for_ = 'zope.app.interfaces.container.IAdding',
         template = None, omit=None, fields=None,
         arguments='', keyword_arguments='',
-        set_before_add='', set_after_add=''):
+        set_before_add='', set_after_add='',
+        menu=None, title=None,
+        ):
+
+    # Handle menu attrs. We do this now to rather than later becaise
+    # menuItemDirective expects a dotted name for for_. 
+    if menu or title:
+        if (not menu) or (not title):
+            raise ValueError("If either menu or title are specified, "
+                             "they must both be specified")
+        actions = menuItemDirective(
+            _context, menu, for_, '@@' + name, title,
+            permission=permission)
+    else:
+        actions = []
+
 
     content_factory = _context.resolve(content_factory)
 
@@ -206,7 +223,9 @@
 
         set_after_add = leftover
 
-    return [
+        
+
+    actions += [
         Action(
         discriminator = ('view', for_, name, IBrowserPresentation, layer),
         callable = AddViewFactory,
@@ -215,3 +234,5 @@
                 keyword_arguments, set_before_add, set_after_add),
         )
         ]
+
+    return actions