add utility functions for reindexing of objects

This commit is contained in:
Helmut Merz 2017-08-10 10:37:25 +02:00
parent 7a3cfbc175
commit f8bca9e7d6

18
util.py
View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de # Copyright (c) 2017 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@ Utility functions.
import os import os
from zope import component from zope import component
from zope.catalog.interfaces import ICatalog
from zope.interface import directlyProvides, directlyProvidedBy from zope.interface import directlyProvides, directlyProvidedBy
from zope.intid.interfaces import IIntIds from zope.intid.interfaces import IIntIds
from zope.i18nmessageid import MessageFactory from zope.i18nmessageid import MessageFactory
@ -84,6 +85,21 @@ def toUnicode(value, encoding='UTF-8'):
return value return value
def getCatalog(context):
from loops.common import baseObject
context = baseObject(context)
for cat in component.getAllUtilitiesRegisteredFor(ICatalog, context=context):
return cat
def reindex(obj, catalog=None):
from loops.common import baseObject
obj = baseObject(obj)
if catalog is None:
catalog = getCatalog(obj)
if catalog is not None:
catalog.index_doc(int(getUidForObject(obj)), obj)
def getObjectForUid(uid, intIds=None): def getObjectForUid(uid, intIds=None):
if uid == '*': # wild card if uid == '*': # wild card
return '*' return '*'