-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from collective/thet-uuidindexing
Upgrade to UUID based indexing
- Loading branch information
Showing
8 changed files
with
86 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from Products.CMFCore.utils import getToolByName | ||
import logging | ||
|
||
logger = logging.getLogger('lineage.index') | ||
|
||
|
||
def upgrade_uuid(context): | ||
"""Reindex the childsite index to use UUID instead of id values. This makes | ||
it possible to have multiple childsites with the same id in different | ||
paths. | ||
""" | ||
index_id = 'childsite' | ||
cat = getToolByName(context, 'portal_catalog') | ||
cat.delColumn(index_id) | ||
cat.addColumn(index_id) | ||
res = (it.getObject() for it in cat.searchResults()) # generator expr. | ||
for cnt, ob in enumerate(res): | ||
ob.reindexObject(idxs=(index_id,)) | ||
if cnt % 100 == 0: | ||
# 100-batch | ||
logger.info("Reindex next batch, starting with {0}".format(cnt)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
from Acquisition import aq_parent | ||
from Products.CMFCore.utils import getToolByName | ||
from Products.Five.browser import BrowserView | ||
from plone.memoize.view import memoize_contextless | ||
from plone.uuid.interfaces import IUUID | ||
from zope.component import getUtility | ||
from zope.schema.interfaces import IVocabularyFactory | ||
import plone.api | ||
|
||
|
||
# Special cases | ||
try: | ||
from plone.event.interfaces import IOccurrence | ||
except ImportError: | ||
IOccurrence = None | ||
|
||
|
||
class ChildsiteView(BrowserView): | ||
|
||
@memoize_contextless | ||
def titleForKey(self, key): | ||
"""returns the childsite's title for their vocabulary value. | ||
"""Returns the childsite's title for their vocabulary value. | ||
""" | ||
util = getUtility(IVocabularyFactory, 'lineage.childsites') | ||
vocab = util(self.context) | ||
try: | ||
return vocab.getTerm(key).title | ||
except LookupError: | ||
return key | ||
|
||
def childsiteForContext(self, item): | ||
"""Returns the childsite UUID for a context object by looking up it's | ||
brain in the catalog. | ||
""" | ||
childsite = '' | ||
if IOccurrence and IOccurrence.providedBy(item): | ||
item = aq_parent(item) | ||
portal = plone.api.portal.get() | ||
cat = getToolByName(self.context, 'portal_catalog') | ||
res = cat(UID=IUUID(item, None), path=portal.getPhysicalPath()) | ||
if res: | ||
childsite = res[0].childsite | ||
return childsite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters