[gen] Added the possibility to display the content of indexes for a given object on its view layout (param 'indexed' in the request).

This commit is contained in:
Gaetan Delannay 2014-12-19 11:21:43 +01:00
parent 982ae08997
commit 06c656d278
8 changed files with 66 additions and 8 deletions

View file

@ -98,6 +98,23 @@ class ToolMixin(BaseMixin):
'''Returns the catalog object.'''
return self.getParentNode().catalog
def getCatalogValue(self, obj, indexName):
'''Get, for p_obj, the value stored in the catalog for the index
named p_indexName.'''
catalogBrain = self.getObject(obj.id, brain=True)
catalog = self.getApp().catalog
index = catalog.Indexes[indexName]
indexType = index.getTagName()
if indexType == 'ZCTextIndex':
# Zope bug: the lexicon can't be retrieved correctly
index._v_lexicon = getattr(catalog, index.lexicon_id)
res = index.getEntryForObject(catalogBrain.getRID())
if indexType == 'DateIndex':
# The index value is a number. Add a DateTime representation too.
from DateTime import DateTime
res = '%d (%s)' % (res, DateTime(res))
return res
def getApp(self):
'''Returns the root Zope object.'''
return self.getPhysicalRoot()

View file

@ -1730,4 +1730,18 @@ class BaseMixin:
method = self.REQUEST['method']
obj = self.appy()
return getattr(obj, method)()
def onReindex(self):
'''Called for reindexing an index or all indexes on the currently shown
object.'''
if not self.getTool().getUser().has_role('Manager'):
self.raiseUnauthorized()
rq = self.REQUEST
indexName = rq['indexName']
if indexName == '_all_':
self.reindex()
else:
self.reindex(indexes=(indexName,))
self.say(self.translate('action_done'))
self.goto(self.getUrl(rq['HTTP_REFERER']))
# ------------------------------------------------------------------------------