Changeset 1d5dc6 in indico
- Timestamp:
- 02/02/12 17:55:32 (16 months ago)
- Branches:
- master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
- Children:
- 2350f4
- Parents:
- 77384a
- git-author:
- Pedro Ferreira <jose.pedro.ferreira@…> (02/02/12 16:43:20)
- git-committer:
- Pedro Ferreira <jose.pedro.ferreira@…> (02/02/12 17:55:32)
- Location:
- indico
- Files:
-
- 4 edited
-
MaKaC/plugins/Collaboration/http_api.py (modified) (5 diffs)
-
MaKaC/plugins/Collaboration/indexes.py (modified) (4 diffs)
-
MaKaC/services/implementation/collaboration.py (modified) (2 diffs)
-
web/http_api/ical.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
indico/MaKaC/plugins/Collaboration/http_api.py
r77384a r1d5dc6 19 19 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 20 20 21 import icalendar as ical 22 21 23 from indico.web.http_api import HTTPAPIHook, DataFetcher 24 from indico.web.http_api.ical import ICalSerializer 22 25 from indico.web.http_api.util import get_query_parameter 23 26 from indico.web.http_api.responses import HTTPAPIError … … 25 28 from indico.util.fossilize import fossilize, IFossil 26 29 from indico.util.fossilize.conversion import Conversion 30 27 31 from MaKaC.webinterface.rh.collaboration import RCCollaborationAdmin 28 32 from MaKaC.common.indexes import IndexesHolder … … 35 39 36 40 globalHTTPAPIHooks = ['CollaborationAPIHook', 'CollaborationExportHook', 'VideoEventHook'] 41 42 43 def serialize_collaboration_alarm(fossil, now): 44 alarm = ical.Alarm() 45 trigger = "-PT" + str(fossil['alarm']) + "M" # iCalendar spec for pre-event trigger 46 alarm.set('trigger', trigger) 47 alarm.set('action', 'DISPLAY') 48 alarm.set('summary', "[" + fossil['type'] + "] " + fossil['status'] + " - " + fossil['title'].decode('utf-8')) 49 alarm.set('description', str(fossil['url'])) 50 return alarm 51 52 53 def serialize_collaboration(fossil, now): 54 event = ical.Event() 55 url = str(fossil['url']) 56 event.set('uid', 'indico-collaboration-%s@cern.ch' % fossil['uniqueId']) 57 event.set('dtstamp', now) 58 event.set('dtstart', fossil['startDate']) 59 event.set('dtend', fossil['endDate']) 60 event.set('url', url) 61 event.set('categories', "VideoService - " + fossil['type']) 62 event.set('summary', "[" + fossil['type'] + "] " + fossil['status'] + " - " + fossil['title'].decode('utf-8')) 63 event.set('description', url) 64 65 # If there is an alarm required, add a subcomponent to the Event 66 if fossil.has_key('alarm'): 67 event.add_component(serialize_collaboration_alarm(fossil, now)) 68 69 return event 70 71 72 # the iCal serializer needs some extra info on how to display things 73 ICalSerializer.register_mapper('collaborationMetadata', serialize_collaboration) 74 37 75 38 76 class CollaborationAPIHook(HTTPAPIHook): … … 105 143 106 144 107 """ This has been defined as a separate hook to CollaborationExportHook et al 145 class VideoEventHook(HTTPAPIHook): 146 """ 147 This has been defined as a separate hook to CollaborationExportHook et al 108 148 due to the different input expected for both. It would be beneficial to 109 149 find a way to amalgamate the two at a later date. 110 """111 class VideoEventHook(HTTPAPIHook): 150 """ 151 112 152 TYPES = ('video', ) 113 153 RE = r'(?P<idlist>\w+(?:-\w+)*)' … … 225 265 for booking in self._process(_iter_bookings(bookings), filter, iface): 226 266 yield booking 227 -
indico/MaKaC/plugins/Collaboration/indexes.py
rf66ec0 r1d5dc6 49 49 50 50 def getBookings(self, indexName, viewBy, orderBy, minKey, maxKey, 51 tz = 'UTC', onlyPending = False, conferenceId = None, categoryId = None, 52 pickle = False, dateFormat = None, page = None, resultsPerPage = None): 51 tz = 'UTC', onlyPending=False, conferenceId=None, categoryId=None, 52 pickle=False, dateFormat=None, page=None, resultsPerPage=None, 53 grouped=False): 53 54 54 55 # TODO: Use iterators instead of lists … … 70 71 elif viewBy == "conferenceStartDate": 71 72 items, nBookings = index.getBookingsByConfDate(minKey, maxKey, conferenceId, 72 categoryId, tz, dateFormat )73 categoryId, tz, dateFormat, grouped=grouped) 73 74 else: 74 75 items, nBookings = index.getBookingsByDate(viewBy, minKey, maxKey, tz, conferenceId, categoryId, dateFormat) … … 218 219 def getBookingsByConfDate(self, fromDate = None, toDate = None, 219 220 conferenceId = None, categoryId = None, 220 tz = None, dateFormat = None ):221 tz = None, dateFormat = None, grouped=True): 221 222 if fromDate: 222 223 minKey = str(datetimeToUnixTimeInt(fromDate)) … … 228 229 maxKey = None 229 230 230 return self._conferenceStartDateIndex._getBookingsGroupedByStartDate(minKey, maxKey, conferenceId, 231 categoryId, tz, dateFormat) 231 if grouped: 232 return self._conferenceStartDateIndex._getBookingsGroupedByStartDate(minKey, maxKey, conferenceId, 233 categoryId, tz, dateFormat) 234 else: 235 return self._conferenceStartDateIndex.getBookings(minKey, maxKey, conferenceId, dateFormat) 232 236 233 237 def dump(self): -
indico/MaKaC/services/implementation/collaboration.py
re9b1d7 r1d5dc6 304 304 maxKey = self._params['toTitle'].strip() 305 305 306 """ For relative dates, create a diff timedelta for resetting to 306 """ For relative dates, create a diff timedelta for resetting to 307 307 00:00 at the start of range and 23:59 at the end. 308 308 """ … … 358 358 dateFormat='%a %d %b %Y', 359 359 page = self._page, 360 resultsPerPage = self._resultsPerPage) 360 resultsPerPage = self._resultsPerPage, 361 grouped=True) 361 362 362 363 class CollaborationCustomPluginService(CollaborationBase): -
indico/web/http_api/ical.py
r77384a r1d5dc6 30 30 from MaKaC.rb_tools import weekNumber 31 31 32 32 33 WEEK_DAYS = 'MO TU WE TH FR SA SU'.split() 34 33 35 34 36 class vRecur(ical.vRecur): … … 46 48 result.append('%s=%s' % (key, vals)) 47 49 return ';'.join(result) 50 48 51 ical.cal.types_factory['recur'] = vRecur 52 53 54 @staticmethod 55 def serialize_conference(fossil, now): 56 event = ical.Event() 57 event.set('uid', 'indico-event-%s@cern.ch' % fossil['id']) 58 event.set('dtstamp', now) 59 event.set('dtstart', fossil['startDate']) 60 event.set('dtend', fossil['endDate']) 61 event.set('url', fossil['url']) 62 event['summary'] = fossil['title'] 63 loc = fossil['location'] or '' 64 if fossil['room']: 65 loc += ' ' + fossil['room'] 66 event['location'] = loc 67 if fossil['description']: 68 event['description'] = fossil['description'] + '\n' + fossil['url'] 69 else: 70 event['description'] = fossil['url'] 71 return event 72 73 74 @staticmethod 75 def serialize_repeatability(startDT, endDT, repType): 76 intervals = { RepeatabilityEnum.onceAWeek: 1, RepeatabilityEnum.onceEvery2Weeks: 2, RepeatabilityEnum.onceEvery3Weeks: 3 } 77 recur = ical.vRecur() 78 recur['until'] = endDT 79 if repType == RepeatabilityEnum.daily: 80 recur['freq'] = 'daily' 81 elif repType in intervals.keys(): 82 recur['freq'] = 'weekly' 83 recur['interval'] = intervals[repType] 84 elif repType == RepeatabilityEnum.onceAMonth: 85 recur['freq'] = 'monthly' 86 recur['byday'] = str(weekNumber(startDT)) + WEEK_DAYS[startDT.weekday()] 87 return recur 88 89 90 def serialize_reservation(fossil, now): 91 event = ical.Event() 92 event.set('uid', 'indico-resv-%s@cern.ch' % fossil['id']) 93 event.set('dtstamp', now) 94 event.set('dtstart', fossil['startDT']) 95 event.set('dtend', datetime.datetime.combine(fossil['startDT'].date(), fossil['endDT'].time())) 96 event.set('url', fossil['bookingUrl']) 97 event.set('summary', fossil['reason']) 98 event['location'] = fossil['location'] + ': ' + fossil['room']['fullName'] 99 event['description'] = fossil['reason'] + '\n' + fossil['bookingUrl'] 100 rrule = None 101 if fossil['repeatability'] is not None: 102 rrule = serialize_repeatability(fossil['startDT'], fossil['endDT'], RepeatabilityEnum.shortname2rep[fossil['repeatability']]) 103 if rrule: 104 event.set('rrule', rrule) 105 return event 106 49 107 50 108 class ICalSerializer(Serializer): … … 53 111 _mime = 'text/calendar' 54 112 55 def _serialize_conference(self, fossil, now): 56 event = ical.Event() 57 event.set('uid', 'indico-event-%s@cern.ch' % fossil['id']) 58 event.set('dtstamp', now) 59 event.set('dtstart', fossil['startDate']) 60 event.set('dtend', fossil['endDate']) 61 event.set('url', fossil['url']) 62 event['summary'] = fossil['title'] 63 loc = fossil['location'] or '' 64 if fossil['room']: 65 loc += ' ' + fossil['room'] 66 event['location'] = loc 67 if fossil['description']: 68 event['description'] = fossil['description'] + '\n' + fossil['url'] 69 else: 70 event['description'] = fossil['url'] 71 return event 113 _mappers = { 114 'conferenceMetadata': serialize_conference, 115 'reservationMetadata': serialize_reservation 116 } 72 117 73 def _serialize_repeatability(self, startDT, endDT, repType): 74 intervals = { RepeatabilityEnum.onceAWeek: 1, RepeatabilityEnum.onceEvery2Weeks: 2, RepeatabilityEnum.onceEvery3Weeks: 3 } 75 recur = ical.vRecur() 76 recur['until'] = endDT 77 if repType == RepeatabilityEnum.daily: 78 recur['freq'] = 'daily' 79 elif repType in intervals.keys(): 80 recur['freq'] = 'weekly' 81 recur['interval'] = intervals[repType] 82 elif repType == RepeatabilityEnum.onceAMonth: 83 recur['freq'] = 'monthly' 84 recur['byday'] = str(weekNumber(startDT)) + WEEK_DAYS[startDT.weekday()] 85 return recur 86 87 def _serialize_reservation(self, fossil, now): 88 event = ical.Event() 89 event.set('uid', 'indico-resv-%s@cern.ch' % fossil['id']) 90 event.set('dtstamp', now) 91 event.set('dtstart', fossil['startDT']) 92 event.set('dtend', datetime.datetime.combine(fossil['startDT'].date(), fossil['endDT'].time())) 93 event.set('url', fossil['bookingUrl']) 94 event.set('summary', fossil['reason']) 95 event['location'] = fossil['location'] + ': ' + fossil['room']['fullName'] 96 event['description'] = fossil['reason'] + '\n' + fossil['bookingUrl'] 97 rrule = None 98 if fossil['repeatability'] is not None: 99 rrule = self._serialize_repeatability(fossil['startDT'], fossil['endDT'], RepeatabilityEnum.shortname2rep[fossil['repeatability']]) 100 if rrule: 101 event.set('rrule', rrule) 102 return event 103 104 def _serialize_collaboration(self, fossil, now): 105 event = ical.Event() 106 url = str(fossil['url']) 107 event.set('uid', 'indico-collaboration-%s@cern.ch' % fossil['uniqueId']) 108 event.set('dtstamp', now) 109 event.set('dtstart', fossil['startDate']) 110 event.set('dtend', fossil['endDate']) 111 event.set('url', url) 112 event.set('categories', "VideoService - " + fossil['type']) 113 event['summary'] = "[" + fossil['type'] + "] " + fossil['status'] + " - " + fossil['title'] 114 event['description'] = url 115 116 # If there is an alarm required, add a subcomponent to the Event 117 if fossil.has_key('alarm'): 118 event.add_component(self._serialize_collaboration_alarm(fossil, now)) 119 120 return event 121 122 def _serialize_collaboration_alarm(self, fossil, now): 123 alarm = ical.Alarm() 124 trigger = "-PT" + str(fossil['alarm']) + "M" #iCalendar spec for pre-event trigger 125 alarm['trigger'] = trigger 126 alarm['action'] = 'DISPLAY' 127 alarm['summary'] = "[" + fossil['type'] + "] " + fossil['status'] + " - " + fossil['title'] 128 alarm['description'] = str(fossil['url']) 129 return alarm 118 @classmethod 119 def register_mapper(cls, fossil, func): 120 cls._mappers[fossil] = func 130 121 131 122 def __call__(self, fossils): … … 139 130 now = datetime.datetime.utcnow() 140 131 for fossil in results: 141 if fossil['_fossil'] == 'conferenceMetadata': 142 cal.add_component(self._serialize_conference(fossil, now)) 143 elif fossil['_fossil'] == 'reservationMetadata': 144 cal.add_component(self._serialize_reservation(fossil, now)) 145 elif fossil['_fossil'] == 'collaborationMetadata': 146 cal.add_component(self._serialize_collaboration(fossil, now)) 132 mapper = ICalSerializer.mappers.get(fossil['_fossil']) 133 if mapper: 134 cal.add_component(mapper(fossil, now)) 147 135 148 136 return str(cal)
Note: See TracChangeset
for help on using the changeset viewer.
