[Checkins] SVN: zope.app.container/trunk/ Filter the "add" menu item if there's nothing to add.

Dan Korostelev nadako at gmail.com
Tue Feb 24 02:50:59 EST 2009


Log message for revision 97197:
  Filter the "add" menu item if there's nothing to add.

Changed:
  U   zope.app.container/trunk/CHANGES.txt
  U   zope.app.container/trunk/src/zope/app/container/browser/metaconfigure.py

-=-
Modified: zope.app.container/trunk/CHANGES.txt
===================================================================
--- zope.app.container/trunk/CHANGES.txt	2009-02-24 07:47:18 UTC (rev 97196)
+++ zope.app.container/trunk/CHANGES.txt	2009-02-24 07:50:58 UTC (rev 97197)
@@ -8,6 +8,8 @@
 - Show a "nothing to add" message instead of empty list in the
   adding view, if there's nothing to add.
 
+- Don't show the "Add" menu item if there's nothing to add.
+
 3.7.1 (2009-02-05)
 -------------------
 

Modified: zope.app.container/trunk/src/zope/app/container/browser/metaconfigure.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/browser/metaconfigure.py	2009-02-24 07:47:18 UTC (rev 97196)
+++ zope.app.container/trunk/src/zope/app/container/browser/metaconfigure.py	2009-02-24 07:50:58 UTC (rev 97197)
@@ -19,11 +19,13 @@
 __docformat__ = 'restructuredtext'
 
 from zope.interface import Interface
+from zope.component import queryMultiAdapter
 from zope.configuration.fields import GlobalObject, GlobalInterface
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.schema import Id
 from zope.security.zcml import Permission
 from zope.app.publisher.browser.viewmeta import page, view
+from zope.app.publisher.browser.menumeta import menuItemDirective
 from zope.app.container.browser.contents import Contents
 from zope.app.container.browser.adding import Adding
 from zope.app.container.i18n import ZopeMessageFactory as _
@@ -80,9 +82,21 @@
 
     if add is not None:
         from zope.app.menus import zmi_actions
-        viewObj = view(_context, name='+', layer=layer, menu=zmi_actions,
-                       title=_('Add'), for_=for_, permission=add,
-                       class_=Adding)
+        viewObj = view(_context, name='+', layer=layer, for_=for_,
+                       permission=add, class_=Adding)
+        menuItemDirective(
+            _context, zmi_actions, for_, '+', _('Add'), permission=add, layer=layer,
+            filter='python:modules["zope.app.container.browser.metaconfigure"].menuFilter(context, request)')
         viewObj.page(_context, name='index.html', attribute='index')
         viewObj.page(_context, name='action.html', attribute='action')
         viewObj()
+
+def menuFilter(context, request):
+    '''This is a function that filters the "Add" menu item'''
+    adding = queryMultiAdapter((context, request), name="+")
+    if adding is None:
+        adding = Adding(context, request)
+    adding.__parent__ = context
+    adding.__name__ = '+'
+    info = adding.addingInfo()
+    return bool(info)



More information about the Checkins mailing list