Skip to content

Commit

Permalink
Merge pull request #2 from plone/plonezope4
Browse files Browse the repository at this point in the history
Merge Zope 4 fixes
  • Loading branch information
esteele committed Oct 21, 2017
2 parents 07b8286 + 72bd2fe commit 1bf0486
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
6 changes: 6 additions & 0 deletions Products/CMFUid/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Products.CMFUid Changelog
2.3.0 (unreleased)
------------------

- Fix import for compatibility with Zope 4.

- Adapt tests to the new indexing operations queueing.
Part of PLIP 1343: https://github.com/plone/Products.CMFPlone/issues/1343
[gforcada]


2.3.0-beta (2012-03-21)
-----------------------
Expand Down
6 changes: 3 additions & 3 deletions Products/CMFUid/UniqueIdAnnotationTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
from zope.container.interfaces import IObjectAddedEvent
from zope.interface import implements

from Products.CMFCore.utils import getToolByName
from Products.CMFCore.utils import registerToolInterface
from Products.CMFCore.utils import UniqueObject
from Products.CMFUid.interfaces import IUniqueIdAnnotation
from Products.CMFUid.interfaces import IUniqueIdAnnotationManagement
from Products.CMFUid.interfaces import IUniqueIdHandler
from Products.CMFUid.interfaces import UniqueIdError


Expand Down Expand Up @@ -73,7 +73,7 @@ def handleUidAnnotationEvent(ob, event):
if IObjectAddedEvent.providedBy(event):
if event.newParent is not None:
anno_tool = queryUtility(IUniqueIdAnnotationManagement)
uidtool = queryUtility(IUniqueIdHandler)
uidtool = getToolByName(ob, 'portal_uidhandler', None)
if anno_tool is not None:
remove_on_add = anno_tool.getProperty('remove_on_add', False)
remove_on_clone = anno_tool.getProperty('remove_on_clone', False)
Expand All @@ -91,7 +91,7 @@ def handleUidAnnotationEvent(ob, event):

elif IObjectClonedEvent.providedBy(event):
anno_tool = queryUtility(IUniqueIdAnnotationManagement)
uidtool = queryUtility(IUniqueIdHandler)
uidtool = getToolByName(ob, 'portal_uidhandler', None)

if anno_tool is not None:
remove_on_clone = anno_tool.getProperty('remove_on_clone', False)
Expand Down
6 changes: 3 additions & 3 deletions Products/CMFUid/UniqueIdHandlerTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from zope.component import getUtility
from zope.interface import implements

from Products.CMFCore.interfaces import ICatalogTool
from Products.CMFCore.permissions import ManagePortal
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.utils import registerToolInterface
from Products.CMFCore.utils import UniqueObject
from Products.CMFUid.interfaces import IUniqueIdAnnotationManagement
Expand Down Expand Up @@ -70,7 +70,7 @@ class UniqueIdHandlerTool(UniqueObject, SimpleItem):
security = ClassSecurityInfo()

def _reindexObject(self, obj):
ctool = getUtility(ICatalogTool)
ctool = getToolByName(self, 'portal_catalog')
ctool.reindexObject(obj, idxs=[self.UID_ATTRIBUTE_NAME])

def _setUid(self, obj, uid):
Expand Down Expand Up @@ -167,7 +167,7 @@ def _queryBrain(self, uid, searchMethodName, default=None):
generator = getUtility(IUniqueIdGenerator)
uid = generator.convert(uid)

ctool = getUtility(ICatalogTool)
ctool = getToolByName(self, 'portal_catalog')
searchMethod = getattr(ctool, searchMethodName)
result = searchMethod({self.UID_ATTRIBUTE_NAME: uid})
len_result = len(result)
Expand Down
11 changes: 6 additions & 5 deletions Products/CMFUid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""Unique id generation and handling.
"""


def initialize(context):

from Products.CMFCore import utils
Expand All @@ -21,14 +22,14 @@ def initialize(context):
import UniqueIdGeneratorTool
import UniqueIdHandlerTool


tools = (
UniqueIdAnnotationTool.UniqueIdAnnotationTool,
UniqueIdGeneratorTool.UniqueIdGeneratorTool,
UniqueIdHandlerTool.UniqueIdHandlerTool,
)

utils.ToolInit( 'CMF Unique Id Tool'
, tools=tools
, icon='tool.gif'
).initialize(context)
utils.ToolInit(
'CMF Unique Id Tool',
tools=tools,
icon='tool.gif'
).initialize(context)
3 changes: 2 additions & 1 deletion Products/CMFUid/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class UidEventZCMLLayer(ZopeLite):
@classmethod
def testSetUp(cls):
import Products
import OFS

zcml.load_config('meta.zcml', Products.Five)
zcml.load_config('event.zcml', Products.Five)
zcml.load_config('event.zcml', OFS)
zcml.load_config('event.zcml', Products.CMFUid)
setHooks()

Expand Down
32 changes: 16 additions & 16 deletions Products/CMFUid/tests/test_uidhandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
"""Test the unique id handling.
"""

import unittest
import Testing

from zope.component import getSiteManager
from zope.interface.verify import verifyClass
from zope.testing.cleanup import cleanUp

from Products.CMFCore.interfaces import ICatalogTool
from Products.CMFCore.tests.base.dummy import DummyContent
from Products.CMFCore.tests.base.dummy import DummyFolder
from Products.CMFCore.tests.base.testcase import SecurityTest
from Products.CMFUid.interfaces import IUniqueIdAnnotationManagement
from Products.CMFUid.interfaces import IUniqueIdGenerator
from Testing import ZopeTestCase
from zope.component import getSiteManager
from zope.interface.verify import verifyClass
from zope.testing.cleanup import cleanUp


ZopeTestCase.installProduct('PluginIndexes')

from Products.CMFCore.indexing import PortalCatalogProcessor
from Products.CMFCore.interfaces import IPortalCatalogQueueProcessor


class DummyUid:
Expand All @@ -36,7 +39,7 @@ class DummyUid:

class DummyContent(DummyContent):
"""Objects may return non-ASCII when converted to str.
Think File and Image.
"""
def __str__(self):
Expand All @@ -55,11 +58,12 @@ def _makeOne(self, *args, **kw):

def setUp(self):
from Products.CMFCore.CatalogTool import CatalogTool
from Products.CMFCore.utils import registerToolInterface
from Products.CMFUid.interfaces import IUniqueIdHandler
from Products.CMFUid.UniqueIdAnnotationTool \
import UniqueIdAnnotationTool
import UniqueIdAnnotationTool
from Products.CMFUid.UniqueIdGeneratorTool \
import UniqueIdGeneratorTool
import UniqueIdGeneratorTool

SecurityTest.setUp(self)
self.app._setObject('dummy', DummyContent(id='dummy'))
Expand All @@ -68,10 +72,12 @@ def setUp(self):
self.uidhandler = self._makeOne()
sm = getSiteManager()
sm.registerUtility(self.ctool, ICatalogTool)
registerToolInterface('portal_catalog', ICatalogTool)
sm.registerUtility(self.uidhandler, IUniqueIdHandler)
sm.registerUtility(UniqueIdAnnotationTool(),
IUniqueIdAnnotationManagement)
sm.registerUtility(UniqueIdGeneratorTool(), IUniqueIdGenerator)
sm.registerUtility(provided=IPortalCatalogQueueProcessor, factory=PortalCatalogProcessor)

# Make sure we have our indices/columns
uid_name = self.uidhandler.UID_ATTRIBUTE_NAME
Expand Down Expand Up @@ -287,9 +293,3 @@ def test_UidCatalogingDoesNotCatalogPortalRoot(self):
uid = handler.register(dummy)
brains = catalog(cmf_uid=uid)
self.assertEqual(len(brains), 0)


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(UniqueIdHandlerTests),
))
2 changes: 1 addition & 1 deletion Products/CMFUid/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0dev
2.3.0.dev0

0 comments on commit 1bf0486

Please sign in to comment.