From b94b558bff8165eea749f822da5d9875797517cb Mon Sep 17 00:00:00 2001 From: Jan Mevissen Date: Fri, 18 May 2018 14:11:56 +0200 Subject: [PATCH] move gopipindex from plone.app.folder to plone.folder https://github.com/plone/Products.CMFPlone/issues/2422 --- src/plone/app/folder/__init__.py | 10 -- src/plone/app/folder/dtml/addGopipIndex.dtml | 44 ------- src/plone/app/folder/nogopip.py | 123 ------------------ .../app/folder/tests/test_integration.py | 11 -- src/plone/app/folder/tests/test_nogopip.py | 63 --------- 5 files changed, 251 deletions(-) delete mode 100644 src/plone/app/folder/dtml/addGopipIndex.dtml delete mode 100644 src/plone/app/folder/nogopip.py delete mode 100644 src/plone/app/folder/tests/test_nogopip.py diff --git a/src/plone/app/folder/__init__.py b/src/plone/app/folder/__init__.py index 6dd9f26..f595d2a 100644 --- a/src/plone/app/folder/__init__.py +++ b/src/plone/app/folder/__init__.py @@ -36,13 +36,3 @@ def initialize(context): extra_constructors = (constructor,), fti = (fti,), ).initialize(context) - - from plone.app.folder import nogopip - - context.registerClass( - nogopip.GopipIndex, - permission='Add Pluggable Index', - constructors=(nogopip.manage_addGopipForm, - nogopip.manage_addGopipIndex), - icon='www/index.gif', - visibility=None) diff --git a/src/plone/app/folder/dtml/addGopipIndex.dtml b/src/plone/app/folder/dtml/addGopipIndex.dtml deleted file mode 100644 index 154f03d..0000000 --- a/src/plone/app/folder/dtml/addGopipIndex.dtml +++ /dev/null @@ -1,44 +0,0 @@ - - - -

- A GopipIndex fakes the formerly used "getObjPositionInParent" index - by retrieving the necessary information directly from the search results' - containers. It works as a drop-in replacement and makes expensive indexing - of each item's position unnecessary. -

- -
- - - - - - - - - - - - - -
-
- Id -
-
- -
-
- Type -
-
- GopipIndex -
-
- -
-
-
- - diff --git a/src/plone/app/folder/nogopip.py b/src/plone/app/folder/nogopip.py deleted file mode 100644 index 6affabf..0000000 --- a/src/plone/app/folder/nogopip.py +++ /dev/null @@ -1,123 +0,0 @@ -# -*- coding: utf-8 -*- -from Acquisition import aq_base -from App.special_dtml import DTMLFile -from OFS.SimpleItem import SimpleItem -from Products.CMFCore.interfaces import ISiteRoot -from Products.PluginIndexes.interfaces import IPluggableIndex, ISortIndex -from inspect import currentframe -from logging import getLogger -from zope.component import getUtility -from zope.interface import implementer - -logger = getLogger(__name__) - - -@implementer(IPluggableIndex) -class StubIndex(SimpleItem): - """ stub catalog index doing nothing """ - - def __init__(self, id, *args, **kw): - self.id = id - - def getId(self): - return self.id - - def getEntryForObject(self, *args, **kw): - return [] - - def getIndexSourceNames(self): - return [self.id] - - def index_object(self, *args, **kw): - return 0 - - def unindex_object(self, *args, **kw): - pass - - def _apply_index(self, *args, **kw): - return None - - def numObjects(self): - return 0 - - def clear(self): - pass - - -@implementer(ISortIndex) -class GopipIndex(StubIndex): - """ fake index for sorting against `getObjPositionInParent` """ - - meta_type = 'GopipIndex' - manage_options = dict(label='Settings', action='manage_main'), - - keyForDocument = 42 - - def __init__(self, id, extra=None, caller=None): - super(GopipIndex, self).__init__(id) - self.catalog = aq_base(caller._catalog) - - def __len__(self): - # with python 2.4 returning `sys.maxint` gives: - # OverflowError: __len__() should return 0 <= outcome < 2**31 - # so... - return 2**31 - 1 - - def documentToKeyMap(self): - # we need to get the containers in order to get the respective - # positions of the search results, but before that we need those - # results themselves. luckily this is only ever called from - # `sortResults`, so we can get it form there. oh, and lurker - # says this won't work in jython, though! :) - rs = currentframe().f_back.f_locals['rs'] - rids = {} - items = [] - containers = {} - getpath = self.catalog.paths.get - traverse = getUtility(ISiteRoot).unrestrictedTraverse - for rid in rs: - path = getpath(rid) - parent, id = path.rsplit('/', 1) - container = containers.get(parent) - if container is None: - containers[parent] = container = traverse(parent) - rids[id] = rid # remember in case of single folder - items.append((rid, container, id)) # or else for deferred lookup - pos = {} - if len(containers) == 1: - # the usual "all from one folder" case can be optimized - folder = list(containers.values())[0] - if getattr(aq_base(folder), 'getOrdering', None): - ids = folder.getOrdering().idsInOrder() - else: - # site root or old folders - ids = folder.objectIds() - for idx, id in enumerate(ids): - rid = rids.get(id) - if rid: - pos[rid] = idx - return pos - else: - # otherwise the entire map needs to be constructed... - for rid, container, id in items: - if getattr(aq_base(container), 'getObjectPosition', None): - pos[rid] = container.getObjectPosition(id) - else: - # fallback for unordered folders - pos[rid] = 0 - return pos - - -manage_addGopipForm = DTMLFile('dtml/addGopipIndex', globals()) - - -def manage_addGopipIndex(self, identifier, REQUEST=None, RESPONSE=None, - URL3=None): - """ add a fake gopip index """ - return self.manage_addIndex( - identifier, - 'GopipIndex', - REQUEST=REQUEST, - RESPONSE=RESPONSE, - URL1=URL3 - ) diff --git a/src/plone/app/folder/tests/test_integration.py b/src/plone/app/folder/tests/test_integration.py index cba64d1..ee74f27 100644 --- a/src/plone/app/folder/tests/test_integration.py +++ b/src/plone/app/folder/tests/test_integration.py @@ -17,14 +17,3 @@ def testCreateFolder(self): self.assertEqual(self.folder['foo'].getPortalTypeName(), 'Folder') from plone.app.folder.base import BaseBTreeFolder self.failUnless(isinstance(self.folder['foo'], BaseBTreeFolder)) - - def testGetObjPositionInParentIndex(self): - from plone.app.folder.nogopip import GopipIndex - catalog = self.portal.portal_catalog - self.failUnless('getObjPositionInParent' in catalog.indexes()) - self.failUnless( - isinstance( - catalog.Indexes['getObjPositionInParent'], - GopipIndex - ) - ) diff --git a/src/plone/app/folder/tests/test_nogopip.py b/src/plone/app/folder/tests/test_nogopip.py deleted file mode 100644 index 6be64c5..0000000 --- a/src/plone/app/folder/tests/test_nogopip.py +++ /dev/null @@ -1,63 +0,0 @@ -from plone.app.folder.tests.base import IntegrationTestCase -from plone.app.folder.tests.content import UnorderedFolder -from plone.app.folder.tests.layer import IntegrationLayer - - -class NoGopipTests(IntegrationTestCase): - - layer = IntegrationLayer - - def afterSetUp(self): - self.setRoles(['Manager']) - folder = self.portal[self.portal.invokeFactory('Folder', 'foo')] - subfolder = folder[folder.invokeFactory('Folder', 'sub')] - folder.invokeFactory('Document', id='bar2') - folder.invokeFactory('Document', id='bar1') - folder.invokeFactory('Document', id='bar3') - folder.invokeFactory('Document', id='bar4') - subfolder.invokeFactory('Document', id='bar5') - - def query(self, **kw): - return [brain.getId for brain in self.portal.portal_catalog( - sort_on='getObjPositionInParent', **kw)] - - def testSearchOneFolder(self): - ids = self.query(path=dict(query='/plone/foo', depth=1)) - self.assertEqual(ids, ['sub', 'bar2', 'bar1', 'bar3', 'bar4']) - - def testSortDocumentsInFolder(self): - ids = self.query(path=dict(query='/plone/foo', depth=1), Type='Page') - self.assertEqual(ids, ['bar2', 'bar1', 'bar3', 'bar4']) - - def testSortDocumentsInTree(self): - ids = self.query(path='/plone/foo', Type='Page') - self.assertEqual(ids, ['bar5', 'bar2', 'bar1', 'bar3', 'bar4']) - - def testSearchUnorderedFolder(self): - self.portal['foo1'] = UnorderedFolder('foo1') - base = self.portal.foo1 - base.reindexObject(idxs=['path', 'getObjPositionInParent']) - base.invokeFactory('Document', id='bar2') - base.invokeFactory('Document', id='bar1') - ids = self.query(path=dict(query='/plone/foo1', depth=1)) - self.assertEqual(ids, ['bar2', 'bar1']) - - def testSearchUnorderedFolderInFolder(self): - self.portal['foo']['foo1'] = UnorderedFolder('foo1') - base = self.portal.foo.foo1 - base.reindexObject(idxs=['path', 'getObjPositionInParent']) - base.invokeFactory('Document', id='bar7') - base.invokeFactory('Document', id='bar6') - ids = self.query(path=dict(query='/plone/foo/foo1', depth=1)) - self.assertEqual(ids, ['bar7', 'bar6']) - - def testSortUnorderedFolderInTree(self): - self.portal.foo['foo1'] = UnorderedFolder('foo1') - base = self.portal.foo.foo1 - base.reindexObject(idxs=['path', 'getObjPositionInParent']) - base.invokeFactory('Document', id='bar7') - base.invokeFactory('Document', id='bar6') - ids = self.query(path='/plone/foo', Type='Page') - self.assertEqual(ids, - ['bar5', 'bar7', 'bar6', 'bar2', 'bar1', 'bar3', 'bar4']) -