1 # -*- coding: utf-8 -*-
4 ## This file is part of CDS Indico.
5 ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
7 ## CDS Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 2 of the
10 ## License, or (at your option) any later version.
12 ## CDS Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ## General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
19 ## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
20 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24 from MaKaC
.common
.utils
import *
25 from MaKaC
.conference
import Conference
, Contribution
26 from MaKaC
.rb_location
import IIndexableByManagerIds
27 from MaKaC
.plugins
.Collaboration
.collaborationTools
import CollaborationTools
28 from MaKaC
.plugins
.Collaboration
.indexes
import CSBookingInstanceWrapper
29 from MaKaC
.common
.logger
import Logger
30 from MaKaC
.common
.indexes
import IndexesHolder
33 from indico
.util
.event
import uid_to_obj
34 from indico
.core
.index
import OOIndex
, Index
35 from indico
.core
.index
.adapter
import IIndexableByStartDateTime
36 from indico
.core
.extpoint
import Component
, IListener
37 from indico
.core
.extpoint
.events
import IObjectLifeCycleListener
, ITimeActionListener
, \
38 IMetadataChangeListener
39 from indico
.core
.extpoint
.location
import ILocationActionListener
40 from indico
.core
.extpoint
.index
import ICatalogIndexProvider
41 from indico
.core
.index
import Catalog
43 class CSBookingInstanceIndexCatalog(Index
):
48 def __getitem__(self
, key
):
49 return self
._container
[key
]
51 def __setitem__(self
, key
, value
):
52 self
._container
[key
] = value
54 def initialize(self
, dbi
=None):
55 for index
in ['WebcastRequest', 'RecordingRequest', 'All Requests']:
56 idx
= CSBookingInstanceIndex(index
)
58 self
._container
[index
] = idx
61 return self
._container
.values()
64 class CSBookingInstanceIndex(OOIndex
):
66 def __init__(self
, index_name
):
67 super(CSBookingInstanceIndex
, self
).__init
__(IIndexableByStartDateTime
)
68 self
.index_name
= index_name
70 def initialize(self
, dbi
=None):
74 idx
= IndexesHolder().getById('collaboration')
76 for conf
, bks
in idx
.getBookings(self
.index_name
, 'conferenceStartDate', None, None, None).getResults():
78 self
.index_booking(bk
)
80 def index_booking(self
, bk
):
81 conf
= bk
.getConference()
82 contribs
= bk
.getTalkSelectionList()
83 choose
= bk
.isChooseTalkSelected()
86 for contrib_id
in contribs
:
87 if CollaborationTools
.isAbleToBeWebcastOrRecorded(conf
.getContributionById(contrib_id
), bk
.getType()):
88 self
.index_obj(CSBookingInstanceWrapper(bk
, conf
.getContributionById(contrib_id
)))
89 # We need to check if it is a lecture with a correct room
90 elif CollaborationTools
.isAbleToBeWebcastOrRecorded(conf
, bk
.getType()) or conf
.getType() !="simple_event":
91 for day
in daysBetween(conf
.getStartDate(), conf
.getEndDate()):
92 bkw
= CSBookingInstanceWrapper(bk
, conf
,
93 day
.replace(hour
=0, minute
=0, second
=0),
94 day
.replace(hour
=23, minute
=59, second
=59))
97 def iter_bookings(self
, fromDT
, toDT
):
99 added_whole_events
= set()
101 for dt
, bkw
in self
.iteritems(fromDT
, toDT
):
102 evt
= bkw
.getOriginalBooking().getConference()
103 entries
= evt
.getSchedule().getEntriesOnDay(dt
)
105 if bkw
.getObject() == evt
:
106 # this means the booking relates to an event
107 if evt
in added_whole_events
:
110 if not evt
.getSchedule().getEntries():
111 yield dt
, CSBookingInstanceWrapper(bkw
.getOriginalBooking(),
113 # mark whole event as "added"
114 added_whole_events
.add(evt
)
118 if self
.index_name
== 'All Requests':
119 talks
= set(CollaborationTools
.getCommonTalkInformation(evt
, 'RecordingRequest', 'recordingCapableRooms')[3]) | \
120 set(CollaborationTools
.getCommonTalkInformation(evt
, 'WebcastRequest', 'webcastCapableRooms')[3])
122 var
= 'recordingCapableRooms' if self
.index_name
== 'RecordingRequest' else 'webcastCapableRooms'
123 talks
= CollaborationTools
.getCommonTalkInformation(evt
, self
.index_name
, var
)[3]
125 # add contribs that concern this day
126 for contrib
in talks
:
127 if contrib
.isScheduled() and contrib
.getStartDate().date() == dt
.date():
128 yield dt
, CSBookingInstanceWrapper(bkw
.getOriginalBooking(),
133 def unindex_booking(self
, bk
, fromDT
=None, toDT
=None):
135 # go over possible wrappers
136 conf
= bk
.getConference()
138 for dt
, bkw
in self
.iteritems((fromDT
or conf
.getStartDate()).replace(hour
=0, minute
=0, second
=0),
139 (toDT
or conf
.getEndDate()).replace(hour
=23, minute
=59, second
=59)):
140 if bkw
.getOriginalBooking() == bk
:
143 for bkw
in to_unindex
:
144 self
.unindex_obj(bkw
)
146 def unindex_talk(self
, bk
, talk
):
148 bookingList
= self
.get(talk
.getStartDate(), [])
149 for bkw
in bookingList
:
150 if bkw
.getObject() == talk
:
152 for bkw
in to_unindex
:
153 self
.unindex_obj(bkw
)
155 def index_talk(self
, bk
, talk
):
156 self
.index_obj(CSBookingInstanceWrapper(bk
, talk
))
158 class CatalogIndexProvider(Component
):
159 zope
.interface
.implements(ICatalogIndexProvider
)
161 def catalogIndexProvider(self
, obj
):
162 return [('cs_booking_instance', CSBookingInstanceIndexCatalog
)]
165 class EventCollaborationListener(Component
):
167 zope
.interface
.implements(IObjectLifeCycleListener
,
169 ILocationActionListener
,
170 IMetadataChangeListener
)
172 """In this case, obj is a conference object. Since all we
173 need is already programmed in CSBookingManager, we get the
174 object of this class and we call the appropiate method"""
176 def dateChanged(cls
, obj
, params
={}):
177 obj
= obj
.getCSBookingManager()
179 obj
.notifyEventDateChanges(params
['oldStartDate'], params
['newStartDate'], params
['oldEndDate'], params
['newEndDate'])
181 Logger
.get('PluginNotifier').error("Exception while trying to access to the date parameters when changing an event date" + str(e
))
184 def startDateChanged(cls
, obj
, params
={}):
185 obj
= obj
.getCSBookingManager()
187 obj
.notifyEventDateChanges(params
['oldDate'], params
['newDate'], None, None)
189 Logger
.get('PluginNotifier').error("Exception while trying to access to the date parameters when changing an event date" + str(e
))
192 def startTimeChanged(self
, obj
, sdate
):
193 """ No one is calling this method in the class Conference. Probably this is completely unnecessary"""
194 bookingManager
= obj
.getCSBookingManager()
195 bookingManager
.notifyEventDateChanges(sdate
, obj
.startDate
, None, None)
198 def endTimeChanged(self
, obj
, edate
):
199 """ No one is calling this method in the class Conference. Probably this is completely unnecessary"""
200 bookingManager
= obj
.getCSBookingManager()
201 bookingManager
.notifyEventDateChanges(None, None, edate
, obj
.endDate
)
204 def timezoneChanged(self
, obj
, oldTimezone
):
205 bookingManager
= obj
.getCSBookingManager()
206 #ATTENTION! At this moment this method notifyTimezoneChange in the class CSBookingManager
207 #just returns [], so if you're expecting it to do something just implement whatever you
209 bookingManager
.notifyTimezoneChange(oldTimezone
, obj
.timezone
)
212 def endDateChanged(cls
, obj
, params
={}):
213 obj
= obj
.getCSBookingManager()
215 obj
.notifyEventDateChanges(None, None, params
['oldDate'], params
['newDate'])
217 Logger
.get('PluginNotifier').error("Exception while trying to access to the date parameters when changing an event date" + str(e
))
220 def eventDatesChanged(cls
, obj
, oldStartDate
, oldEndDate
,
221 newStartDate
, newEndDate
):
222 obj
= obj
.getCSBookingManager()
224 obj
.notifyEventDateChanges(oldStartDate
, newStartDate
,
225 oldEndDate
, newEndDate
)
227 Logger
.get('PluginNotifier').error("Exception while trying to access to the date parameters when changing an event date" + str(e
))
230 def contributionUnscheduled(self
, contrib
):
231 if contrib
.getStartDate() is not None:
232 csBookingManager
= contrib
.getCSBookingManager()
233 for booking
in csBookingManager
.getBookingList():
234 booking
.unindex_talk(contrib
)
237 def contributionScheduled(self
, contrib
):
238 csBookingManager
= contrib
.getCSBookingManager()
239 for booking
in csBookingManager
.getBookingList():
240 booking
.index_talk(contrib
)
243 def eventTitleChanged(cls
, obj
, oldTitle
, newTitle
):
245 obj
= obj
.getCSBookingManager()
247 obj
.notifyTitleChange(oldTitle
, newTitle
)
249 Logger
.get('PluginNotifier').error("Exception while trying to access to the title parameters when changing an event title" + str(e
))
252 def infoChanged(cls
, obj
):
253 #Update Speaker Wrapper only if obj is a Conference
254 if isinstance(obj
, Conference
) or isinstance(obj
, Contribution
):
255 bookingManager
= obj
.getCSBookingManager()
258 bookingManager
.notifyInfoChange()
260 Logger
.get('PluginNotifier').error("Exception while trying to access the info changes " + str(e
))
264 def deleted(cls
, obj
, params
={}):
265 if obj
.__class
__ == Conference
:
266 obj
= obj
.getCSBookingManager()
268 elif obj
.__class
__ == Contribution
:
269 csBookingManager
= obj
.getCSBookingManager()
270 for booking
in csBookingManager
.getBookingList():
271 booking
.unindex_talk(obj
)
273 # ILocationActionListener
275 def placeChanged(cls
, obj
):
276 obj
= obj
.getCSBookingManager()
277 obj
.notifyLocationChange()
280 def locationChanged(cls
, obj
, oldLocation
, newLocation
):
281 csBookingManager
= obj
.getCSBookingManager()
282 for booking
in csBookingManager
.getBookingList():
283 booking
.unindex_talk(obj
)
284 booking
.index_talk(obj
)
287 def roomChanged(cls
, obj
, oldLocation
, newLocation
):
288 csBookingManager
= obj
.getCSBookingManager()
289 for booking
in csBookingManager
.getBookingList():
290 booking
.unindex_talk(obj
)
291 booking
.index_talk(obj
)