Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from zope import interface
- from zope import component
- from Products.ZCatalog import CatalogBrains
- from p4a.calendar import interfaces
- from DateTime import DateTime
- from Products.CMFCore import utils as cmfutils
- from Products.Archetypes import atapi
- from Products.ATContentTypes.content import topic
- def dt2DT(dt):
- s = "%04i-%02i-%02i %02i:%02i" % (dt.year, dt.month, dt.day,
- dt.hour, dt.minute)
- return DateTime(s)
- def DT2dt(dt):
- return datetime.datetime(dt.year(), dt.month(), dt.day(),
- dt.hour(), dt.minute())
- def _make_zcatalog_query(start, stop, kw):
- """Takes a IEventProvider query and makes it a ZCaralog query"""
- if kw.has_key('title'):
- # The catalog calls this property "Title" with a
- # capital T.
- kw['Title'] = kw['title']
- del kw['title']
- if stop is not None:
- kw['start']={'query': dt2DT(stop), 'range': 'max'}
- if start is not None:
- kw['end']={'query': dt2DT(start), 'range': 'min'}
- return kw
- class MLEventProvider(object):
- interface.implements(interfaces.IEventProvider)
- component.adapts(atapi.BaseObject)
- def __init__(self, context):
- self.context = context
- def gather_events(self, start=None, stop=None, **kw):
- catalog = cmfutils.getToolByName(self.context, 'portal_catalog')
- path = '/'.join(self.context.getPhysicalPath())
- kw = _make_zcatalog_query(start, stop, kw)
- event_brains = catalog(portal_type='YOURTYPE', path=path, **kw)
- return (interfaces.IEvent(x) for x in event_brains)
- def all_events(self):
- catalog = cmfutils.getToolByName(self.context, 'portal_catalog')
- path = '/'.join(self.context.getPhysicalPath())
- event_brains = catalog(portal_type='YOURTYPE', path=path)
- return (interfaces.IEvent(x) for x in event_brains)
- def event_creation_link(self, start=None, stop=None):
- if self.context.portal_membership.checkPermission(
- 'Add portal content',self.context):
- return self.context.absolute_url() + '/createObject?type_name=YOURTYPE'
- return ''
Add Comment
Please, Sign In to add comment