[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/schemacontent/
Remove handling of local browser menu entries for
schema-based content. This
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Sep 23 10:47:30 EDT 2004
Log message for revision 27649:
Remove handling of local browser menu entries for schema-based content. This
really cipples this code, but we can only add the menu code back, once we
have a solid local adapter service.
Changed:
U Zope3/trunk/src/zope/app/schemacontent/browser/configure.zcml
U Zope3/trunk/src/zope/app/schemacontent/configure.zcml
U Zope3/trunk/src/zope/app/schemacontent/content.py
U Zope3/trunk/src/zope/app/schemacontent/tests/test_content.py
-=-
Modified: Zope3/trunk/src/zope/app/schemacontent/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/schemacontent/browser/configure.zcml 2004-09-23 05:42:21 UTC (rev 27648)
+++ Zope3/trunk/src/zope/app/schemacontent/browser/configure.zcml 2004-09-23 14:47:30 UTC (rev 27649)
@@ -62,15 +62,6 @@
menu="zmi_views" title="Define Permissions"
permission="zope.ManageContent"/>
- <editform
- for="zope.app.schemacontent.interfaces.IContentComponentDefinition"
- schema="zope.app.schemacontent.interfaces.IContentComponentMenuItem"
- name="menuItem.html"
- menu="zmi_views" title="Menu Item"
- fields="menuId interface create title description permission
- filter_string"
- permission="zope.ManageContent"/>
-
<defaultView
for="zope.app.schemacontent.interfaces.IContentComponentDefinition"
name="edit.html" />
Modified: Zope3/trunk/src/zope/app/schemacontent/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/schemacontent/configure.zcml 2004-09-23 05:42:21 UTC (rev 27648)
+++ Zope3/trunk/src/zope/app/schemacontent/configure.zcml 2004-09-23 14:47:30 UTC (rev 27649)
@@ -33,23 +33,6 @@
/>
</content>
-
-<!-- Content Component Menu Item -->
-
- <content class=".content.ContentComponentDefinitionMenuItem">
-
- <require
- permission="zope.ManageServices"
- interface=".interfaces.IContentComponentMenuItem"
- set_schema=".interfaces.IContentComponentMenuItem" />
-
- </content>
-
- <adapter
- for=".interfaces.IContentComponentDefinition"
- provides=".interfaces.IContentComponentMenuItem"
- factory=".content.ContentComponentDefinitionMenuItem" />
-
<!-- Content Component Instance -->
<content class=".content.ContentComponentInstance">
Modified: Zope3/trunk/src/zope/app/schemacontent/content.py
===================================================================
--- Zope3/trunk/src/zope/app/schemacontent/content.py 2004-09-23 05:42:21 UTC (rev 27648)
+++ Zope3/trunk/src/zope/app/schemacontent/content.py 2004-09-23 14:47:30 UTC (rev 27649)
@@ -21,13 +21,9 @@
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.annotation.interfaces import IAnnotations
from zope.app.container.interfaces import IAdding
-from zope.app.menu.interfaces import ILocalBrowserMenu, ILocalBrowserMenuService
from zope.app.registration.interfaces import ActiveStatus
from zope.app.container.contained import Contained
-from zope.app.menu import \
- LocalBrowserMenuService, LocalBrowserMenu, LocalBrowserMenuItem
from zope.app.site.service import ServiceRegistration
-from zope.app.servicenames import BrowserMenu
from zope.app.utility import UtilityRegistration
from zope.component.exceptions import ComponentLookupError
from zope.interface import directlyProvides, implements
@@ -35,13 +31,10 @@
from zope.security.checker import CheckerPublic, Checker, defineChecker
from zope.security.proxy import removeSecurityProxy
-from interfaces import IContentComponentDefinition, IContentComponentMenuItem
+from interfaces import IContentComponentDefinition
from interfaces import IContentComponentInstance
-MenuItemKey = 'http://www.zope.org/utilities/content/menuitem'
-
-
class ContentComponentDefinition(Persistent, Contained):
implements(IContentComponentDefinition)
@@ -51,234 +44,20 @@
self.schema = schema
self.copySchema = copySchema
self.permissions = PersistentDict()
-## # This will set up the menu item entry.
-## IContentComponentMenuItem(self)
-
-class ContentComponentDefinitionMenuItem(object):
- """An adapter that takes a Content Component Defintion and provides all
- necessary information to create a menu item for the content component."""
-
- implements(IContentComponentMenuItem)
- __used_for__ = IContentComponentDefinition
-
- def __init__(self, context):
- self.context = context
- ann = IAnnotations(context)
- if not ann.has_key(MenuItemKey):
- ann[MenuItemKey] = PersistentDict(
- {'interface': IAdding,
- 'title': self.context.name,
- 'description': '',
- 'permission': 'zope.ManageContent',
- 'filter_string': '',
- 'menuId': 'add_content',
- 'create': True,
- # This is not part of the interface, but we need to store
- # that information.
- 'menuItemId': None,
- 'menu': None}
- )
- self._data = ann[MenuItemKey]
- self._menu = self._data['menu']
- if self._menu:
- self._menuItem = self._data['menu'][self._data['menuItemId']]
- else:
- self._menuItem = None
-
-
- def _createMenuService(self):
- """Create a browser menu service for the menu item."""
- # Get the local service manager; not that we know it must exist,
- # otherwise this object would not be called.
- sm = zapi.getServices(self.context)
- # Get the default package and add a menu service called 'Menus-1'
- default = zapi.traverse(sm, 'default')
- default['Menus-1'] = LocalBrowserMenuService()
- # Register the service and set it to active
- path = "%s/default/%s" % (zapi.getPath(sm), 'Menus-1')
- reg = ServiceRegistration(BrowserMenu, path, sm)
- key = default.getRegistrationManager().addRegistration(reg)
- reg = zapi.traverse(default.getRegistrationManager(), key)
- reg.status = ActiveStatus
- return zapi.traverse(default, 'Menus-1')
-
-
- def _createMenu(self):
- """Create a menu."""
- # Create a menu and add it to the default package
- menu = LocalBrowserMenu()
- sm = zapi.getServices(self.context)
- default = zapi.traverse(sm, 'default')
- default[self.menuId] = menu
- # Register th emenu as a utility and activate it.
- path = "%s/default/%s" % (zapi.getPath(sm), self.menuId)
- reg = UtilityRegistration(self.menuId, ILocalBrowserMenu, path)
- key = default.getRegistrationManager().addRegistration(reg)
- reg = zapi.traverse(default.getRegistrationManager(), key)
- reg.status = ActiveStatus
- return zapi.traverse(default, self.menuId)
-
-
- def createMenuItem(self):
- "See .interfaces.IContentComponentMenuItem"
- # If 'create' is set to true, we must generate the necessary objects
- # locally
- if self.create:
- # Get the servicem manager and the default package
- sm = zapi.getServices(self.context)
- default = zapi.traverse(sm, 'default')
- try:
- service = sm.getService(BrowserMenu)
- except ComponentLookupError:
- service = None
- # Check whether the service really exists locally; if not, create
- # one for this service manager
- if (service is None or
- not ILocalBrowserMenuService.providedBy(service) or
- not zapi.name(service) in default):
-
- service = self._createMenuService()
-
- # Check whether the menu exists locally; if not create one.
- menu = service.queryInheritedMenu(self.menuId, True)
- if (menu is None or
- not ILocalBrowserMenu.providedBy(menu) or
- not zapi.name(menu) in default):
-
- menu = self._createMenu()
-
- else:
- # Find a browser menu service and make sure it is a local one.
- service = zapi.getService(BrowserMenu, self)
- if not ILocalBrowserMenuService.providedBy(service):
- raise ComponentLookupError, \
- _('No local/peristent Browser Menu Service found.')
- # Find the browser menu and make sure it is a local one
- menu = service.queryInheritedMenu(self.menuId, True)
- if menu is None or not ILocalBrowserMenu.providedBy(menu):
- error = _('No local Browser Menu called "${name}" found.')
- error.mapping = {'name': self.menuId}
- raise ComponentLookupError, error
-
- self._data['menu'] = menu
- # Creating the menu item
- item = LocalBrowserMenuItem()
- for name in ('interface', 'action', 'title', 'description',
- 'permission', 'filter_string'):
- setattr(item, name, getattr(self, name))
- self._data['menuItemId'] = menu.addItem(item)
-
-
- def removeMenuItem(self):
- "See .interfaces.IContentComponentMenuItem"
- self._data['menu'].__delitem__(self._data['menuItemId'])
- self._data['menu'] = None
- self._data['menuItemId'] = None
-
-
- def _setMenuId(self, value):
- if self._data['menuId'] != value:
- self._data['menuId'] = value
- # This is the path of least reistence
- self.removeMenuItem()
- self.createMenuItem()
-
- menuId = property(lambda self: self._data['menuId'], _setMenuId)
-
-
- def _setInterface(self, value):
- if self._data['interface'] != value:
- self._data['interface'] = value
- # If a menu item exists, make sure it gets updated.
- if self._menuItem is not None:
- self._menuItem.interface = value
-
- interface = property(lambda self: self._data['interface'], _setInterface)
-
-
- def _getAction(self):
- return 'AddContentComponent/' + self.context.name
-
- action = property(_getAction)
-
-
- def _getTitle(self):
- return self._data['title'] or self.context.name
-
- def _setTitle(self, value):
- if self._data['title'] != value:
- self._data['title'] = value
- # If a menu item exists, make sure it gets updated.
- if self._menuItem is not None:
- self._menuItem.title = value
-
- title = property(_getTitle, _setTitle)
-
-
- def _setDescription(self, value):
- if self._data['description'] != value:
- self._data['description'] = value
- # If a menu item exists, make sure it gets updated.
- if self._menuItem is not None:
- self._menuItem.description = value
-
- description = property(lambda self: self._data['description'],
- _setDescription)
-
- def _setPermission(self, value):
- if self._data['permission'] != value:
- self._data['permission'] = value
- # If a menu item exists, make sure it gets updated.
- if self._menuItem is not None:
- self._menuItem.permission = value
-
- permission = property(lambda self: self._data['permission'],
- _setPermission)
-
-
- def _setFilterString(self, value):
- if self._data['filter_string'] != value:
- self._data['filter_string'] = value
- # If a menu item exists, make sure it gets updated.
- if self._menuItem is not None:
- self._menuItem.filter = value
-
- filter_string = property(lambda self: self._data['filter_string'],
- _setFilterString)
-
-
- def _setCreate(self, value):
- if self._data['create'] != value:
- self.removeMenuItem()
- self._data['create'] = value
- self.createMenuItem()
-
- create = property(lambda self: self._data['create'],
- _setCreate)
-
-
-
class ContentComponentDefinitionRegistration(UtilityRegistration):
"""Content Component Registration"""
def activated(self):
- """Once activated, we have to register the new Content Object with the
- appropriate menu.
- """
component = self.getComponent()
component = removeSecurityProxy(component)
component.name = self.name
- IContentComponentMenuItem(component).createMenuItem()
def deactivated(self):
- """Once activated, we have to unregister the new Content Object with
- the appropriate menu."""
component = self.getComponent()
component = removeSecurityProxy(component)
component.name = None
- IContentComponentMenuItem(component).removeMenuItem()
class ContentComponentInstance(Persistent):
Modified: Zope3/trunk/src/zope/app/schemacontent/tests/test_content.py
===================================================================
--- Zope3/trunk/src/zope/app/schemacontent/tests/test_content.py 2004-09-23 05:42:21 UTC (rev 27648)
+++ Zope3/trunk/src/zope/app/schemacontent/tests/test_content.py 2004-09-23 14:47:30 UTC (rev 27649)
@@ -20,20 +20,14 @@
from zope.app import zapi
from zope.app.annotation.interfaces import IAttributeAnnotatable
from zope.app.container.interfaces import IAdding
-from zope.app.publisher.interfaces.browser import IBrowserMenuService
from zope.app.utility.interfaces import ILocalUtility
-from zope.app.schemacontent.interfaces import \
- IContentComponentDefinition, IContentComponentMenuItem
-from zope.app.publisher.browser.globalbrowsermenuservice import \
- GlobalBrowserMenuService
-from zope.app.menu import LocalBrowserMenuService, LocalBrowserMenu
-from zope.app.menu.tests import addMenu
-from zope.app.servicenames import BrowserMenu, Utilities
+from zope.app.schemacontent.interfaces import IContentComponentDefinition
+from zope.app.servicenames import Utilities
from zope.app.utility import LocalUtilityService
from zope.app.tests import setup
from zope.app.schemacontent.content import \
ContentComponentDefinition, ContentComponentDefinitionRegistration, \
- ContentComponentDefinitionMenuItem, ContentComponentInstance
+ ContentComponentInstance
from zope.component import getGlobalServices
from zope.app.tests import ztapi
from zope.component.exceptions import ComponentLookupError
@@ -54,27 +48,11 @@
setup.placefulSetUp()
self.rootFolder = setup.buildSampleFolderTree()
- # Define Menu Item Adapter
- ztapi.provideAdapter(IContentComponentDefinition,
- IContentComponentMenuItem,
- ContentComponentDefinitionMenuItem)
-
- # Define Menu Service
- sm = getGlobalServices()
- sm.defineService(BrowserMenu, IBrowserMenuService)
- sm.provideService(BrowserMenu, GlobalBrowserMenuService())
- classImplements(LocalBrowserMenu, ILocalUtility)
- classImplements(LocalBrowserMenu, IAttributeAnnotatable)
mgr = setup.createServiceManager(self.rootFolder)
- self.root_ms = setup.addService(mgr, BrowserMenu,
- LocalBrowserMenuService())
# Setup Utility Service
setup.addService(mgr, Utilities, LocalUtilityService())
- # Define a Menu
- addMenu(mgr, 'add_content', 'Add Content', True)
-
# Setup Definition
classImplements(ContentComponentDefinition, ILocalUtility)
classImplements(ContentComponentDefinition, IAttributeAnnotatable)
@@ -94,108 +72,13 @@
def test_activated(self):
self.reg.activated()
self.assertEqual(self.reg.getComponent().name, 'TestDoc')
- service = zapi.getService(BrowserMenu, self.rootFolder)
- menu = service.getLocalMenu('add_content')
- self.assertEqual('TestDoc', menu['1'].title)
- mi = IContentComponentMenuItem(self.reg.getComponent())
- self.assert_(mi._menuItem != None)
- self.assertEqual(mi._menu, menu)
def test_deactivated(self):
self.test_activated()
self.reg.deactivated()
- mi = IContentComponentMenuItem(self.reg.getComponent())
- self.assertEqual(mi._menuItem, None)
- self.assertEqual(mi._menu, None)
self.assertEqual(self.reg.getComponent().name, None)
-class ContentComponentDefinitionMenuItemTests(unittest.TestCase):
-
- def setUp(self):
- setup.placefulSetUp()
- classImplements(ContentComponentDefinition, ILocalUtility)
- classImplements(ContentComponentDefinition, IAttributeAnnotatable)
- ztapi.provideAdapter(IContentComponentDefinition,
- IContentComponentMenuItem,
- ContentComponentDefinitionMenuItem)
-
- sm = getGlobalServices()
- sm.defineService(BrowserMenu, IBrowserMenuService)
- sm.provideService(BrowserMenu, GlobalBrowserMenuService())
-
- self.rootFolder = setup.buildSampleFolderTree()
- self.mgr = setup.createServiceManager(self.rootFolder)
-
- setup.addService(self.mgr, Utilities, LocalUtilityService())
- ccd = ContentComponentDefinition('TestDoc', IDocument)
- self.default = zapi.traverse(self.mgr, 'default')
- self.default['Document'] = ccd
- ccd = zapi.traverse(self.default, 'Document')
-
- self.mi = ContentComponentDefinitionMenuItem(ccd)
-
- def tearDown(self):
- setup.placefulTearDown()
-
- def test_interface(self):
- self.assertEqual(self.mi.interface, IAdding)
- self.mi.interface = Interface
- self.assertEqual(self.mi.interface, Interface)
-
- def test_action(self):
- self.assertEqual(self.mi.action, 'AddContentComponent/TestDoc')
- self.mi.context.name = 'Document'
- self.assertEqual(self.mi.action, 'AddContentComponent/Document')
-
- def test_title(self):
- self.assertEqual(self.mi.title, 'TestDoc')
- self.mi.title = 'Test Document'
- self.assertEqual(self.mi.title, 'Test Document')
-
- def test_description(self):
- self.assertEqual(self.mi.description, '')
- self.mi.description = 'Test Document Description'
- self.assertEqual(self.mi.description, 'Test Document Description')
-
- def test_permission(self):
- self.assertEqual(self.mi.permission, 'zope.ManageContent')
- self.mi.permission = 'zope.View'
- self.assertEqual(self.mi.permission, 'zope.View')
-
- def test_filter_string(self):
- self.assertEqual(self.mi.filter_string, '')
- self.mi.filter_string = 'not: context'
- self.assertEqual(self.mi.filter_string, 'not: context')
-
- def test_createMenuService(self):
- menus = self.mi._createMenuService()
- self.assertEqual(zapi.name(menus), 'Menus-1')
- self.assert_('Menus-1' in zapi.getParent(menus))
-
- def test_createMenu(self):
- menu = self.mi._createMenu()
- self.assertEqual(zapi.name(menu), 'add_content')
- self.assert_('add_content' in zapi.getParent(menu))
-
- def test_createMenuItem(self):
- self.mi.createMenuItem()
- self.assert_('Menus-1' in self.default)
- self.assert_('add_content' in self.default)
- menu = zapi.traverse(self.default, 'add_content')
- item = menu.values()[0]
- self.assertEqual(item.action, 'AddContentComponent/TestDoc')
-
- def test_create(self):
- # This tests also createMenuItem and removeMenuItem
- self.assertEqual(self.mi.create, True)
- self.mi.createMenuItem()
- self.assertRaises(ComponentLookupError, self.mi.__setattr__,
- 'create', False)
- self.mi._data['create'] = False
- self.assertEqual(self.mi.create, False)
-
-
class ContentComponentInstanceTests(unittest.TestCase):
def test_getattr(self):
@@ -223,9 +106,8 @@
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ContentComponentDefinitionRegistrationTests),
- unittest.makeSuite(ContentComponentDefinitionMenuItemTests),
unittest.makeSuite(ContentComponentInstanceTests),
))
if __name__ == '__main__':
- unittest.main()
+ unittest.main(defaultTest='test_suite')
More information about the Zope3-Checkins
mailing list