I'm working on a view that will be email weekly with all the events starting within the next 7 days (as well as news items published in the last 7 days). I had created the view as a pt thru the browser but because of recurrence I had to rewrite it as a view.
New View- York Weekly
old zpt- York Weekly
the problem I have is that I want to show the leadimage of the events that have one, but I can figure out how to check if the event has one in expand_events. when I was calling the catalog directly I was using the hasImage meta as a condition to display the img tag, but that does not work with the plone.app.event.base.
class WeeklyUpdate(BrowserView):
def events(self):
portal_catalog = api.portal.get_tool('portal_catalog')
# current_path = "/".join(self.context.getPhysicalPath())
brains = portal_catalog(portal_type=('Event', 'ATEvent'),
sort_on='start',
expires={'query': localized_now(), 'range': 'min'},
effective={'query': localized_now(), 'range': 'max'},
start={'query': (datetime.today(), datetime.today() + timedelta(days=7)),
'range': 'min:max'},
review_state='published')
result = []
for acc in expand_events(brains,
RET_MODE_ACCESSORS,
start=datetime.today(),
end=datetime.today() + timedelta(7),
sort='start',
):
start_long = self.context.toLocalizedTime(acc.start, long_format=1)
start_short = self.context.toLocalizedTime(acc.start, long_format=0)
end_long = self.context.toLocalizedTime(acc.end, long_format=1)
end_short = self.context.toLocalizedTime(acc.end, long_format=0)
if start_long.endswith('12:00 AM'):
start = start_short
else:
start = start_long
if end_long.endswith('12:00 AM'):
end = end_short
else:
end = end_long
if start_short == end_short:
start = start
else:
start = start + ' - ' + end
image = acc.url + '/@@images/image/mini'
result.append({
'url': acc.url,
'title': acc.title,
'description': acc.description,
'location': acc.location,
'image': image,
'start': start, })
return result