I have a Dexterity folderish type which contains standard ATImages. I'd like it to display the first of its contained images when it is listed in a folder or collection Summary View. I tried setting an image property on the view but that wasn't even consulted when I try to access its URL: http://site/my-dex/image
That is the code I used:
class View(grok.View):
grok.context(IMyDex)
grok.require('zope2.View')
@memoize
def photos(self):
"""Return a catalog search result of photos to show
"""
context = aq_inner(self.context)
catalog = getToolByName(context, 'portal_catalog')
folder_path = '/'.join(context.getPhysicalPath())
results = catalog(path=folder_path,
portal_type='Image',
sort_on='getObjPositionInParent')
return results
@property
def image(self):
try:
first_img = self.photos[0].getObject()
except IndexError:
first_img = None
return first_img
What should I be doing instead?