Back to index

plone3  3.1.7
events.py
Go to the documentation of this file.
00001 from Acquisition import aq_inner
00002 import zope.deprecation
00003 from zope.interface import implements
00004 
00005 from DateTime import DateTime
00006 from Products.Five import BrowserView
00007 from Products.CMFCore.utils import getToolByName
00008 from Products.CMFPlone.browser.interfaces import IEventsPortlet
00009 
00010 
00011 class EventsPortlet(BrowserView):
00012     implements(IEventsPortlet)
00013 
00014     def __init__(self, context, request, *args, **kw):
00015         super(EventsPortlet, self).__init__(context, request, *args, **kw)
00016         utool = getToolByName(context, 'portal_url')
00017         self.portal_url = utool()
00018         # this has a messed up context, but we don't care in this case
00019         self.portal = utool.getPortalObject()
00020         self.eventsFolder = 'events' in self.portal.objectIds()
00021 
00022     def published_events(self):
00023         context = aq_inner(self.context)
00024         portal_catalog = getToolByName(context, 'portal_catalog')
00025 
00026         return portal_catalog.searchResults(portal_type='Event',
00027                                             end={'query': DateTime(),
00028                                                  'range': 'min'},
00029                                             sort_on='start',
00030                                             sort_limit=5,
00031                                             review_state='published')[:5]
00032 
00033     def all_events_link(self):
00034         if self.eventsFolder:
00035             return '%s/events' % self.portal_url
00036         else:
00037             return '%s/events_listing' % self.portal_url
00038 
00039     def prev_events_link(self):
00040         if self.eventsFolder and 'previous' in self.portal.events.objectIds():
00041             return '%s/events/previous' % self.portal_url
00042         else:
00043             return None
00044 
00045 zope.deprecation.deprecated(
00046   ('EventsPortlet', ),
00047    "Plone's portlets are based on plone.app.portlets now. The old portlets "
00048    "will be removed in Plone 4.0."
00049   )