Guest User

Untitled

a guest
Jun 14th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import datetime
  2. from zope import interface
  3. from zope import component
  4.  
  5. from Products.ZCatalog import CatalogBrains
  6. from p4a.calendar import interfaces
  7. from DateTime import DateTime
  8. from Products.CMFCore import utils as cmfutils
  9. from Products.Archetypes import atapi
  10. from Products.ATContentTypes.content import topic
  11.  
  12. def dt2DT(dt):
  13. s = "%04i-%02i-%02i %02i:%02i" % (dt.year, dt.month, dt.day,
  14. dt.hour, dt.minute)
  15. return DateTime(s)
  16.  
  17. def DT2dt(dt):
  18. return datetime.datetime(dt.year(), dt.month(), dt.day(),
  19. dt.hour(), dt.minute())
  20.  
  21.  
  22. def _make_zcatalog_query(start, stop, kw):
  23. """Takes a IEventProvider query and makes it a ZCaralog query"""
  24. if kw.has_key('title'):
  25. # The catalog calls this property "Title" with a
  26. # capital T.
  27. kw['Title'] = kw['title']
  28. del kw['title']
  29. if stop is not None:
  30. kw['start']={'query': dt2DT(stop), 'range': 'max'}
  31. if start is not None:
  32. kw['end']={'query': dt2DT(start), 'range': 'min'}
  33. return kw
  34.  
  35.  
  36.  
  37. class MLEventProvider(object):
  38. interface.implements(interfaces.IEventProvider)
  39. component.adapts(atapi.BaseObject)
  40.  
  41. def __init__(self, context):
  42. self.context = context
  43.  
  44. def gather_events(self, start=None, stop=None, **kw):
  45. catalog = cmfutils.getToolByName(self.context, 'portal_catalog')
  46. path = '/'.join(self.context.getPhysicalPath())
  47. kw = _make_zcatalog_query(start, stop, kw)
  48. event_brains = catalog(portal_type='YOURTYPE', path=path, **kw)
  49. return (interfaces.IEvent(x) for x in event_brains)
  50.  
  51. def all_events(self):
  52. catalog = cmfutils.getToolByName(self.context, 'portal_catalog')
  53. path = '/'.join(self.context.getPhysicalPath())
  54. event_brains = catalog(portal_type='YOURTYPE', path=path)
  55. return (interfaces.IEvent(x) for x in event_brains)
  56.  
  57. def event_creation_link(self, start=None, stop=None):
  58. if self.context.portal_membership.checkPermission(
  59. 'Add portal content',self.context):
  60. return self.context.absolute_url() + '/createObject?type_name=YOURTYPE'
  61. return ''
Add Comment
Please, Sign In to add comment