Commit bc7b5674 authored by Lorenzo Gil Sanchez's avatar Lorenzo Gil Sanchez

Substitute zope.app.zapi by direct calls to its wrapped apis. See bug 219302....

Substitute zope.app.zapi by direct calls to its wrapped apis. See bug 219302. Also added a test for the CheckDependency function
parent 843cc998
...@@ -19,6 +19,7 @@ __docformat__ = 'restructuredtext' ...@@ -19,6 +19,7 @@ __docformat__ = 'restructuredtext'
import urllib import urllib
from zope.component import queryMultiAdapter
from zope.event import notify from zope.event import notify
from zope.exceptions.interfaces import UserError from zope.exceptions.interfaces import UserError
from zope.security.interfaces import Unauthorized from zope.security.interfaces import Unauthorized
...@@ -33,8 +34,8 @@ from zope.copypastemove.interfaces import IObjectCopier, IObjectMover ...@@ -33,8 +34,8 @@ from zope.copypastemove.interfaces import IObjectCopier, IObjectMover
from zope.copypastemove.interfaces import IContainerItemRenamer from zope.copypastemove.interfaces import IContainerItemRenamer
from zope.annotation.interfaces import IAnnotations from zope.annotation.interfaces import IAnnotations
from zope.lifecycleevent import ObjectModifiedEvent, Attributes from zope.lifecycleevent import ObjectModifiedEvent, Attributes
from zope.traversing.api import getName, getPath, joinPath, traverse
from zope.app import zapi
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.container.i18n import ZopeMessageFactory as _ from zope.app.container.i18n import ZopeMessageFactory as _
...@@ -158,7 +159,7 @@ class Contents(BrowserView): ...@@ -158,7 +159,7 @@ class Contents(BrowserView):
info['retitle'] = id == retitle_id info['retitle'] = id == retitle_id
zmi_icon = zapi.queryMultiAdapter((obj, self.request), name='zmi_icon') zmi_icon = queryMultiAdapter((obj, self.request), name='zmi_icon')
if zmi_icon is None: if zmi_icon is None:
info['icon'] = None info['icon'] = None
else: else:
...@@ -221,10 +222,10 @@ class Contents(BrowserView): ...@@ -221,10 +222,10 @@ class Contents(BrowserView):
dc = IDCDescriptiveProperties(item) dc = IDCDescriptiveProperties(item)
dc.title = new dc.title = new
notify(ObjectModifiedEvent(item, Attributes(IZopeDublinCore, 'title'))) notify(ObjectModifiedEvent(item, Attributes(IZopeDublinCore, 'title')))
def hasAdding(self): def hasAdding(self):
"""Returns true if an adding view is available.""" """Returns true if an adding view is available."""
adding = zapi.queryMultiAdapter((self.context, self.request), name="+") adding = queryMultiAdapter((self.context, self.request), name="+")
return (adding is not None) return (adding is not None)
def addObject(self): def addObject(self):
...@@ -234,7 +235,7 @@ class Contents(BrowserView): ...@@ -234,7 +235,7 @@ class Contents(BrowserView):
else: else:
new = request["new_value"] new = request["new_value"]
adding = zapi.queryMultiAdapter((self.context, self.request), name="+") adding = queryMultiAdapter((self.context, self.request), name="+")
if adding is None: if adding is None:
adding = Adding(self.context, request) adding = Adding(self.context, request)
else: else:
...@@ -267,7 +268,7 @@ class Contents(BrowserView): ...@@ -267,7 +268,7 @@ class Contents(BrowserView):
self.error = _("You didn't specify any ids to copy.") self.error = _("You didn't specify any ids to copy.")
return return
container_path = zapi.getPath(self.context) container_path = getPath(self.context)
# For each item, check that it can be copied; if so, save the # For each item, check that it can be copied; if so, save the
# path of the object for later copying when a destination has # path of the object for later copying when a destination has
...@@ -289,7 +290,7 @@ class Contents(BrowserView): ...@@ -289,7 +290,7 @@ class Contents(BrowserView):
self.error = _("Object '${name}' cannot be copied", self.error = _("Object '${name}' cannot be copied",
mapping=m) mapping=m)
return return
items.append(zapi.joinPath(container_path, id)) items.append(joinPath(container_path, id))
# store the requested operation in the principal annotations: # store the requested operation in the principal annotations:
clipboard = getPrincipalClipboard(self.request) clipboard = getPrincipalClipboard(self.request)
...@@ -304,7 +305,7 @@ class Contents(BrowserView): ...@@ -304,7 +305,7 @@ class Contents(BrowserView):
self.error = _("You didn't specify any ids to cut.") self.error = _("You didn't specify any ids to cut.")
return return
container_path = zapi.getPath(self.context) container_path = getPath(self.context)
# For each item, check that it can be moved; if so, save the # For each item, check that it can be moved; if so, save the
# path of the object for later moving when a destination has # path of the object for later moving when a destination has
...@@ -326,7 +327,7 @@ class Contents(BrowserView): ...@@ -326,7 +327,7 @@ class Contents(BrowserView):
self.error = _("Object '${name}' cannot be moved", self.error = _("Object '${name}' cannot be moved",
mapping=m) mapping=m)
return return
items.append(zapi.joinPath(container_path, id)) items.append(joinPath(container_path, id))
# store the requested operation in the principal annotations: # store the requested operation in the principal annotations:
clipboard = getPrincipalClipboard(self.request) clipboard = getPrincipalClipboard(self.request)
...@@ -342,7 +343,7 @@ class Contents(BrowserView): ...@@ -342,7 +343,7 @@ class Contents(BrowserView):
items = clipboard.getContents() items = clipboard.getContents()
for item in items: for item in items:
try: try:
obj = zapi.traverse(target, item['target']) obj = traverse(target, item['target'])
except TraversalError: except TraversalError:
pass pass
else: else:
...@@ -373,7 +374,7 @@ class Contents(BrowserView): ...@@ -373,7 +374,7 @@ class Contents(BrowserView):
for item in items: for item in items:
duplicated_id = False duplicated_id = False
try: try:
obj = zapi.traverse(target, item['target']) obj = traverse(target, item['target'])
except TraversalError: except TraversalError:
pass pass
else: else:
...@@ -394,7 +395,7 @@ class Contents(BrowserView): ...@@ -394,7 +395,7 @@ class Contents(BrowserView):
raise raise
if duplicated_id: if duplicated_id:
not_pasteable_ids.append(zapi.getName(obj)) not_pasteable_ids.append(getName(obj))
if moved: if moved:
# Clear the clipboard if we do a move, but not if we only do a copy # Clear the clipboard if we do a move, but not if we only do a copy
...@@ -421,7 +422,7 @@ class Contents(BrowserView): ...@@ -421,7 +422,7 @@ class Contents(BrowserView):
items = clipboard.getContents() items = clipboard.getContents()
for item in items: for item in items:
try: try:
zapi.traverse(self.context, item['target']) traverse(self.context, item['target'])
except TraversalError: except TraversalError:
pass pass
else: else:
......
...@@ -28,11 +28,12 @@ from zope.publisher.browser import BrowserView ...@@ -28,11 +28,12 @@ from zope.publisher.browser import BrowserView
from zope.security.interfaces import ForbiddenAttribute from zope.security.interfaces import ForbiddenAttribute
from zope.testing.doctestunit import DocTestSuite from zope.testing.doctestunit import DocTestSuite
from zope.exceptions.interfaces import UserError from zope.exceptions.interfaces import UserError
from zope.traversing.api import getParent
from zope.traversing.browser import AbsoluteURL from zope.traversing.browser import AbsoluteURL
from zope.traversing.browser.absoluteurl import absoluteURL
from zope.traversing.browser.interfaces import IAbsoluteURL from zope.traversing.browser.interfaces import IAbsoluteURL
from zope.traversing.interfaces import IContainmentRoot from zope.traversing.interfaces import IContainmentRoot
from zope.app import zapi
from zope.app.testing import ztapi from zope.app.testing import ztapi
from zope.app.testing.placelesssetup import PlacelessSetup, setUp, tearDown from zope.app.testing.placelesssetup import PlacelessSetup, setUp, tearDown
from zope.app.publisher.interfaces.browser import AddMenu from zope.app.publisher.interfaces.browser import AddMenu
...@@ -83,7 +84,7 @@ class AbsoluteURL(BrowserView): ...@@ -83,7 +84,7 @@ class AbsoluteURL(BrowserView):
if IContainmentRoot.providedBy(self.context): if IContainmentRoot.providedBy(self.context):
return '' return ''
name = self.context.__name__ name = self.context.__name__
url = zapi.absoluteURL(zapi.getParent(self.context), self.request) url = absoluteURL(getParent(self.context), self.request)
url += '/' + name url += '/' + name
return url return url
......
...@@ -20,10 +20,10 @@ $Id$ ...@@ -20,10 +20,10 @@ $Id$
""" """
__docformat__ = 'restructuredtext' __docformat__ = 'restructuredtext'
from zope.app import zapi
from zope.i18nmessageid import Message from zope.i18nmessageid import Message
from zope.app.container.i18n import ZopeMessageFactory as _ from zope.app.container.i18n import ZopeMessageFactory as _
from zope.app.dependable.interfaces import IDependable, DependencyError from zope.app.dependable.interfaces import IDependable, DependencyError
from zope.traversing.api import getPath
exception_msg = _(""" exception_msg = _("""
Removal of object (${object}) which has dependents (${dependents}) Removal of object (${object}) which has dependents (${dependents})
...@@ -39,7 +39,7 @@ def CheckDependency(event): ...@@ -39,7 +39,7 @@ def CheckDependency(event):
dependents = dependency.dependents() dependents = dependency.dependents()
if dependents: if dependents:
mapping = { mapping = {
"object": zapi.getPath(object), "object": getPath(object),
"dependents": ", ".join(dependents) "dependents": ", ".join(dependents)
} }
raise DependencyError(Message(exception_msg, mapping=mapping)) raise DependencyError(Message(exception_msg, mapping=mapping))
##############################################################################
#
# Copyright (c) 2008 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test the CheckDependency event subscriber.
$Id$
"""
import unittest
from zope.interface import implements
from zope.app.dependable.interfaces import IDependable, DependencyError
from zope.app.container.contained import ObjectRemovedEvent
from zope.app.container.dependency import CheckDependency
from zope.traversing.interfaces import IPhysicallyLocatable
class DummyObject(object):
implements(IDependable, IPhysicallyLocatable)
def dependents(self):
return ['dependency1', 'dependency2']
def getPath(self):
return '/dummy-object'
class Test(unittest.TestCase):
def testCheckDependency(self):
obj = DummyObject()
parent = object()
event = ObjectRemovedEvent(obj, parent, 'oldName')
self.assertRaises(DependencyError, CheckDependency, event)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test),
))
if __name__=='__main__':
unittest.main()
...@@ -24,9 +24,9 @@ from zope.publisher.interfaces.browser import IBrowserPublisher ...@@ -24,9 +24,9 @@ from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.interfaces import NotFound from zope.publisher.interfaces import NotFound
from zope.app import zapi
from zope.app.container.interfaces import ISimpleReadContainer, IItemContainer from zope.app.container.interfaces import ISimpleReadContainer, IItemContainer
from zope.app.container.interfaces import IReadContainer from zope.app.container.interfaces import IReadContainer
from zope.app.publisher.browser import getDefaultViewName
# Note that the next two classes are included here because they # Note that the next two classes are included here because they
# can be used for multiple view types. # can be used for multiple view types.
...@@ -55,7 +55,7 @@ class ContainerTraverser(object): ...@@ -55,7 +55,7 @@ class ContainerTraverser(object):
def browserDefault(self, request): def browserDefault(self, request):
"""See zope.publisher.browser.interfaces.IBrowserPublisher""" """See zope.publisher.browser.interfaces.IBrowserPublisher"""
view_name = zapi.getDefaultViewName(self.context, request) view_name = getDefaultViewName(self.context, request)
view_uri = "@@%s" %view_name view_uri = "@@%s" %view_name
return self.context, (view_uri,) return self.context, (view_uri,)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment