Hi,
What i want: i would like grouped Links in a view via releatedItems (e.g. all Galleries in Block, Videos, and so on). Galleries are Collection/Folders with an AlbumView, if i call obj.getLayout(). When i iterate over my related Items, then i wake up the Objects. But that does not make sense from my point of view.
Should i write an Indexer for the Catalog which holds the "Names" of Views or is caching of the Result enough. What are possible Mistakes when i write an Indexer for "IObjectEditedEvent". I think its a good Candidate for a default Index in a Plone Catalog.
My View:
class TestDefaultView(BrowserView):
_videos=[]
_galleries=[]
_documents=[]
def __init__(self, context, request):
super(POIDefaultView, self).__init__(context, request)
self.context = aq_inner(context)
self.request = request
self.response = request.response
def __call__(self):
super(POIDefaultView, self).__call__()
self._sort_relations()
return self.index()
@property
def videos(self):
return self._videos
@property
def documents(self):
return self._documents
@property
def galleries(self):
return self._galleries
# TODO Cache this
def _sort_relations(self):
results = []
catalog = api.portal.get_tool('portal_catalog')
if not IRelatedItems.providedBy(self.context):
return
for rel in self.context.relatedItems:
if rel.isBroken():
#skip broken relations
continue
# query by path so we don't have to wake up any objects
brains = catalog(path={'query': rel.to_path, 'depth': 0})
if brains:
brain = brains[0]
# check if folder or collection
if brain['Type'] in['Collection', 'Folder']:
obj = brain.getObject()
if obj.getLayout() == 'album_view':
self._galleries.append(brain)
# check if file
if 'File' == brain['Type']:
self._documents.append(brain)
# check if video
if 'Video' == brain['Type']:
self._videos.append(brain)
Update:
My indexer.zcml:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="test.training">
<adapter name="layout" factory=".indexers.LayoutIndexer" />
</configure>
indexers.py
# -*- coding: utf-8 -*-
from Products.CMFPlone.utils import safe_unicode
from plone.indexer.decorator import indexer
from plone.dexterity.interfaces import IDexterityContent
@indexer(IDexterityContent)
def LayoutIndexer(obj):
return safe_unicode(obj.getLayout())
subscriber.zcml
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="test.training">
<subscriber
for="plone.dexterity.interfaces.IDexterityContent
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".subscriber.onEventModified" />
</configure>
subscriber.py
# -*- coding: utf-8 -*-
def onEventModified(item, event):
item.reindexObject(idxs=['layout'])