| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## |
|---|
| 4 | ## This file is part of CDS Indico. |
|---|
| 5 | ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN. |
|---|
| 6 | ## |
|---|
| 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. |
|---|
| 11 | ## |
|---|
| 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. |
|---|
| 16 | ## |
|---|
| 17 | ## You should have received a copy of the GNU General Public License |
|---|
| 18 | ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., |
|---|
| 19 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 20 | |
|---|
| 21 | from MaKaC.webinterface.rh import base |
|---|
| 22 | from MaKaC.common import DBMgr, xmlGen |
|---|
| 23 | from MaKaC.common import indexes |
|---|
| 24 | from datetime import datetime |
|---|
| 25 | from MaKaC.errors import MaKaCError |
|---|
| 26 | from MaKaC import conference,webcast |
|---|
| 27 | from MaKaC.common.output import outputGenerator |
|---|
| 28 | from sets import Set |
|---|
| 29 | |
|---|
| 30 | from MaKaC.user import LoginInfo |
|---|
| 31 | from MaKaC.authentication import AuthenticatorMgr |
|---|
| 32 | from MaKaC.user import AvatarHolder |
|---|
| 33 | from MaKaC.webinterface import webFactoryRegistry |
|---|
| 34 | from MaKaC.conference import CategoryManager,Conference |
|---|
| 35 | from MaKaC import user |
|---|
| 36 | from MaKaC.i18n import _ |
|---|
| 37 | import MaKaC.common.info as info |
|---|
| 38 | from pytz import timezone |
|---|
| 39 | |
|---|
| 40 | import MaKaC.webinterface.materialFactories as materialFactories |
|---|
| 41 | from MaKaC.webinterface import locators |
|---|
| 42 | |
|---|
| 43 | class RHXMLHandlerBase ( base.RH ): |
|---|
| 44 | |
|---|
| 45 | def _genStatus (self, statusValue, message, XG): |
|---|
| 46 | XG.openTag("status") |
|---|
| 47 | XG.writeTag("value", statusValue) |
|---|
| 48 | XG.writeTag("message", message) |
|---|
| 49 | XG.closeTag("status") |
|---|
| 50 | |
|---|
| 51 | def _createResponse (self, statusValue, message): |
|---|
| 52 | XG = xmlGen.XMLGen() |
|---|
| 53 | XG.openTag("response") |
|---|
| 54 | self._genStatus(statusValue, message, XG) |
|---|
| 55 | XG.closeTag("response") |
|---|
| 56 | |
|---|
| 57 | self._req.content_type = "text/xml" |
|---|
| 58 | return XG.getXml() |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | class RHLoginStatus( RHXMLHandlerBase ): |
|---|
| 62 | def _process( self ): |
|---|
| 63 | XG = xmlGen.XMLGen() |
|---|
| 64 | XG.openTag("response") |
|---|
| 65 | self._genStatus("OK", "Request succesful", XG) |
|---|
| 66 | XG.openTag("login-status") |
|---|
| 67 | if self._getSession().getUser() != None: |
|---|
| 68 | XG.writeTag("user-id", self._getSession().getUser().getId()) |
|---|
| 69 | XG.closeTag("login-status") |
|---|
| 70 | XG.closeTag("response") |
|---|
| 71 | |
|---|
| 72 | self._req.content_type = "text/xml" |
|---|
| 73 | return XG.getXml() |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | class RHSignIn( RHXMLHandlerBase ): |
|---|
| 77 | |
|---|
| 78 | def _checkParams( self, params ): |
|---|
| 79 | |
|---|
| 80 | self._login = params.get( "login", "" ).strip() |
|---|
| 81 | self._password = params.get( "password", "" ).strip() |
|---|
| 82 | |
|---|
| 83 | def _process( self ): |
|---|
| 84 | |
|---|
| 85 | li = LoginInfo( self._login, self._password ) |
|---|
| 86 | auth = AuthenticatorMgr() |
|---|
| 87 | av = auth.getAvatar(li) |
|---|
| 88 | value = "OK" |
|---|
| 89 | message = "" |
|---|
| 90 | if not av: |
|---|
| 91 | value = "ERROR" |
|---|
| 92 | message = "Login failed" |
|---|
| 93 | elif not av.isActivated(): |
|---|
| 94 | if av.isDisabled(): |
|---|
| 95 | value = "ERROR" |
|---|
| 96 | message = "Acount is disabled" |
|---|
| 97 | else: |
|---|
| 98 | value = "ERROR" |
|---|
| 99 | message = "Acount is not activated" |
|---|
| 100 | else: |
|---|
| 101 | value = "OK" |
|---|
| 102 | message = "Login succesful" |
|---|
| 103 | self._getSession().setUser( av ) |
|---|
| 104 | |
|---|
| 105 | return self._createResponse(value, message) |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | class RHSignOut( RHXMLHandlerBase ): |
|---|
| 109 | |
|---|
| 110 | def _process( self ): |
|---|
| 111 | if self._getUser(): |
|---|
| 112 | self._getSession().setUser( None ) |
|---|
| 113 | self._setUser( None ) |
|---|
| 114 | |
|---|
| 115 | return self._createResponse("OK", "Logged out") |
|---|
| 116 | |
|---|
| 117 | class RHWebcastOnAir( RHXMLHandlerBase ): |
|---|
| 118 | |
|---|
| 119 | def _printWebcast(self, wc, XG): |
|---|
| 120 | XG.openTag("webcast") |
|---|
| 121 | XG.writeTag("title",wc.getTitle()) |
|---|
| 122 | XG.writeTag("startDate",wc.getStartDate()) |
|---|
| 123 | XG.writeTag("id",wc.getId()) |
|---|
| 124 | XG.writeTag("room",wc.getRoom()) |
|---|
| 125 | XG.closeTag("webcast") |
|---|
| 126 | |
|---|
| 127 | def _printStream( self, stream, XG ): |
|---|
| 128 | XG.openTag("stream") |
|---|
| 129 | XG.writeTag("format",stream.getFormat()) |
|---|
| 130 | XG.writeTag("url",stream.getURL()) |
|---|
| 131 | XG.closeTag("stream") |
|---|
| 132 | |
|---|
| 133 | def _printChannel(self, ch, XG): |
|---|
| 134 | XG.openTag("channel") |
|---|
| 135 | XG.writeTag("name",ch.getName()) |
|---|
| 136 | XG.writeTag("width",ch.getWidth()) |
|---|
| 137 | XG.writeTag("height",ch.getHeight()) |
|---|
| 138 | if ch.isOnAir(): |
|---|
| 139 | XG.writeTag("onair","True") |
|---|
| 140 | for stream in ch.getStreams(): |
|---|
| 141 | self._printStream(stream,XG) |
|---|
| 142 | wc = ch.whatsOnAir() |
|---|
| 143 | if wc: |
|---|
| 144 | self._printWebcast(wc,XG) |
|---|
| 145 | XG.closeTag("channel") |
|---|
| 146 | |
|---|
| 147 | def _process( self ): |
|---|
| 148 | wm = webcast.HelperWebcastManager.getWebcastManagerInstance() |
|---|
| 149 | XG = xmlGen.XMLGen() |
|---|
| 150 | XG.openTag("response") |
|---|
| 151 | XG.openTag("status") |
|---|
| 152 | XG.writeTag("value", "OK") |
|---|
| 153 | XG.writeTag("message", "Returning on air events on all channels") |
|---|
| 154 | XG.closeTag("status") |
|---|
| 155 | XG.openTag("channels") |
|---|
| 156 | for ch in wm.getChannels(): |
|---|
| 157 | self._printChannel(ch,XG) |
|---|
| 158 | XG.closeTag("channels") |
|---|
| 159 | XG.closeTag("response") |
|---|
| 160 | self._req.content_type = "text/xml" |
|---|
| 161 | return XG.getXml() |
|---|
| 162 | |
|---|
| 163 | class RHWebcastForthcomingEvents( RHXMLHandlerBase ): |
|---|
| 164 | |
|---|
| 165 | def _printWebcast(self, wc, XG): |
|---|
| 166 | XG.openTag("webcast") |
|---|
| 167 | XG.writeTag("title",wc.getTitle()) |
|---|
| 168 | XG.writeTag("id",wc.getId()) |
|---|
| 169 | XG.writeTag("startDate",wc.getStartDate()) |
|---|
| 170 | XG.writeTag("room",wc.getRoom()) |
|---|
| 171 | XG.closeTag("webcast") |
|---|
| 172 | |
|---|
| 173 | def _process( self ): |
|---|
| 174 | wm = webcast.HelperWebcastManager.getWebcastManagerInstance() |
|---|
| 175 | XG = xmlGen.XMLGen() |
|---|
| 176 | XG.openTag("response") |
|---|
| 177 | XG.openTag("status") |
|---|
| 178 | XG.writeTag("value", "OK") |
|---|
| 179 | XG.writeTag("message", "Returning all forthcoming webcasts") |
|---|
| 180 | XG.closeTag("status") |
|---|
| 181 | XG.openTag("webcasts") |
|---|
| 182 | webcasts = wm.getForthcomingWebcasts() |
|---|
| 183 | webcasts.sort(webcast.sortWebcastByDate) |
|---|
| 184 | for wc in webcasts: |
|---|
| 185 | if not wc in wm.whatsOnAir(): |
|---|
| 186 | if not wc.getEvent().isProtected(): |
|---|
| 187 | self._printWebcast(wc,XG) |
|---|
| 188 | XG.closeTag("webcasts") |
|---|
| 189 | XG.closeTag("response") |
|---|
| 190 | self._req.content_type = "text/xml" |
|---|
| 191 | return XG.getXml() |
|---|
| 192 | |
|---|
| 193 | class RHSearch ( base.RHProtected, RHXMLHandlerBase ): |
|---|
| 194 | |
|---|
| 195 | def _stringToDatetime(self, source): |
|---|
| 196 | """This method expects dates in the form "yyyy-mm-dd hh:mm" """ |
|---|
| 197 | |
|---|
| 198 | return datetime(int(source[0:4]), int(source[5:7]), int(source[8:10]), \ |
|---|
| 199 | int(source[11:13]), int(source[14:16]),tzinfo=timezone(info.HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone())) |
|---|
| 200 | |
|---|
| 201 | def _extractParam(self, params, paramName, attrName = None): |
|---|
| 202 | |
|---|
| 203 | if (attrName == None): |
|---|
| 204 | attrName = "_" + paramName |
|---|
| 205 | |
|---|
| 206 | if (params.has_key(paramName)): |
|---|
| 207 | setattr(self, attrName, params[paramName]) |
|---|
| 208 | return True |
|---|
| 209 | else: |
|---|
| 210 | setattr(self, attrName, None) |
|---|
| 211 | return False |
|---|
| 212 | |
|---|
| 213 | def _extractDateParam(self, params, paramName, attrName = None): |
|---|
| 214 | |
|---|
| 215 | if (attrName == None): |
|---|
| 216 | attrName = "_" + paramName |
|---|
| 217 | try: |
|---|
| 218 | if (self._extractParam(params, paramName, attrName)): |
|---|
| 219 | setattr(self, attrName, self._stringToDatetime(getattr(self, attrName))) |
|---|
| 220 | except: |
|---|
| 221 | raise MaKaCError( _("Invalid date format")) |
|---|
| 222 | |
|---|
| 223 | def _checkAuthor(self, conf, name): |
|---|
| 224 | # This checks whether an author is involved in a conference |
|---|
| 225 | idx1 = conf.getAuthorIndex() |
|---|
| 226 | idx2 = conf.getSpeakerIndex() |
|---|
| 227 | if idx1.match({"name": name}) or \ |
|---|
| 228 | idx1.match({"surName": name}) or \ |
|---|
| 229 | idx2.match({"name": name}) or \ |
|---|
| 230 | idx2.match({"surName": name}): |
|---|
| 231 | return True |
|---|
| 232 | else: |
|---|
| 233 | return False |
|---|
| 234 | |
|---|
| 235 | def _checkRoom(self, conf, room): |
|---|
| 236 | if conf.getRoom() != None and conf.getRoom().getName().lower().find(room.lower()) != -1: |
|---|
| 237 | return True |
|---|
| 238 | for i in conf.getSessionList(): |
|---|
| 239 | if i.getRoom() != None and i.getRoom().getName().lower().find(room.lower()) != -1: |
|---|
| 240 | return True |
|---|
| 241 | for i in conf.getContributionList(): |
|---|
| 242 | if i.getRoom() != None and i.getRoom().getName().lower().find(room.lower()) != -1: |
|---|
| 243 | return True |
|---|
| 244 | for j in i.getSubContributionList(): |
|---|
| 245 | if j.getRoom() != None and j.getRoom().getName().lower().find(room.lower()) != -1: |
|---|
| 246 | return True |
|---|
| 247 | return False |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | def _checkParams(self, params): |
|---|
| 252 | base.RHProtected._checkParams(self, params) |
|---|
| 253 | |
|---|
| 254 | self._statusValue = "OK" |
|---|
| 255 | self._message = "" |
|---|
| 256 | |
|---|
| 257 | try: |
|---|
| 258 | # extract interesting parameters from request |
|---|
| 259 | dateParams = [ "startDateAt", "endDateAt", "startDateFrom", \ |
|---|
| 260 | "startDateTo", "endDateFrom", "endDateTo", "date" ] |
|---|
| 261 | otherParams = [ "category", "room", "id", "author", "format" ] |
|---|
| 262 | for i in dateParams: |
|---|
| 263 | self._extractDateParam(params, i) |
|---|
| 264 | for i in otherParams: |
|---|
| 265 | self._extractParam(params, i) |
|---|
| 266 | |
|---|
| 267 | # sanity checks |
|---|
| 268 | # range boundaries must be given together |
|---|
| 269 | if (self._startDateFrom != None) != (self._startDateTo != None): |
|---|
| 270 | raise MaKaCError( _("Incomplete range")) |
|---|
| 271 | if (self._endDateFrom != None) != (self._endDateTo != None): |
|---|
| 272 | raise MaKaCError( _("Incomplete range")) |
|---|
| 273 | |
|---|
| 274 | # ensure that ranges are constructed correctly |
|---|
| 275 | if self._startDateFrom != None and \ |
|---|
| 276 | self._startDateFrom >= self._startDateTo: |
|---|
| 277 | raise MaKaCError( _("startDateTo must be greater than startDateFrom")) |
|---|
| 278 | if self._endDateFrom != None and \ |
|---|
| 279 | self._endDateFrom >= self._endDateTo: |
|---|
| 280 | raise MaKaCError( _("endDateTo must be greater than endDateFrom")) |
|---|
| 281 | |
|---|
| 282 | # dates must be specified either precisely or by a range, but not both |
|---|
| 283 | if self._startDateFrom != None and self._startDateAt != None: |
|---|
| 284 | raise MaKaCError( _("Use either startDateFrom/startDateTo or startDateAt")) |
|---|
| 285 | if self._endDateFrom != None and self._endDateAt != None: |
|---|
| 286 | raise MaKaCError( _("Use either endDateFrom/endDateTo or endDateAt")) |
|---|
| 287 | |
|---|
| 288 | # At least one date or one range of dates should be specified |
|---|
| 289 | if self._startDateFrom == None and self._startDateAt == None and \ |
|---|
| 290 | self._endDateFrom == None and self._endDateAt == None and self._id == None and self._date == None: |
|---|
| 291 | raise MaKaCError( _("At least one date/range of dates or a conference id must be specified")) |
|---|
| 292 | except MaKaCError, e: |
|---|
| 293 | self._statusValue = "ERROR" |
|---|
| 294 | self._message = e.getMsg() |
|---|
| 295 | except: |
|---|
| 296 | self._statusValue = "ERROR" |
|---|
| 297 | self._message = "Internal error" |
|---|
| 298 | |
|---|
| 299 | def _printSubContribution(self, s, XG): |
|---|
| 300 | if s.canAccess(self.getAW()): |
|---|
| 301 | XG.openTag("subcontribution") |
|---|
| 302 | XG.writeTag("id", s.getId()) |
|---|
| 303 | XG.writeTag("title", s.getTitle()) |
|---|
| 304 | XG.writeTag("startDate", s.getContribution().getStartDate()) |
|---|
| 305 | XG.writeTag("timezone", 'UTC') |
|---|
| 306 | if s.getRoom() != None: |
|---|
| 307 | XG.writeTag("room", s.getRoom().getName()) |
|---|
| 308 | else: |
|---|
| 309 | XG.writeTag("room", "") |
|---|
| 310 | XG.closeTag("subcontribution") |
|---|
| 311 | |
|---|
| 312 | def _printContribution(self, c, XG): |
|---|
| 313 | if c.canAccess(self.getAW()): |
|---|
| 314 | XG.openTag("contribution") |
|---|
| 315 | XG.writeTag("id", c.getId()) |
|---|
| 316 | XG.writeTag("title", c.getTitle()) |
|---|
| 317 | XG.writeTag("startDate", c.getStartDate()) |
|---|
| 318 | XG.writeTag("endDate", c.getEndDate()) |
|---|
| 319 | XG.writeTag("timezone", 'UTC') |
|---|
| 320 | if c.getRoom() != None: |
|---|
| 321 | XG.writeTag("room", c.getRoom().getName()) |
|---|
| 322 | else: |
|---|
| 323 | XG.writeTag("room", "") |
|---|
| 324 | for i in c.getSubContributionList(): |
|---|
| 325 | self._printSubContribution(i, XG) |
|---|
| 326 | XG.closeTag("contribution") |
|---|
| 327 | |
|---|
| 328 | def _printSession(self, s, XG): |
|---|
| 329 | if s.canAccess(self.getAW()): |
|---|
| 330 | XG.openTag("session") |
|---|
| 331 | XG.writeTag("id", s.getId()) |
|---|
| 332 | XG.writeTag("title", s.getTitle()) |
|---|
| 333 | XG.writeTag("startDate", s.getStartDate()) |
|---|
| 334 | XG.writeTag("endDate", s.getEndDate()) |
|---|
| 335 | XG.writeTag("timezone", 'UTC') |
|---|
| 336 | if s.getRoom() != None: |
|---|
| 337 | XG.writeTag("room", s.getRoom().getName()) |
|---|
| 338 | else: |
|---|
| 339 | XG.writeTag("room", "") |
|---|
| 340 | for i in s.getContributionList(): |
|---|
| 341 | if i.isScheduled(): |
|---|
| 342 | self._printContribution(i, XG) |
|---|
| 343 | XG.closeTag("session") |
|---|
| 344 | |
|---|
| 345 | def _printConference(self, c, XG): |
|---|
| 346 | if c.canAccess(self.getAW()): |
|---|
| 347 | XG.openTag("event") |
|---|
| 348 | XG.writeTag("id", c.getId()) |
|---|
| 349 | XG.writeTag("title", c.getTitle()) |
|---|
| 350 | XG.writeTag("startDate", c.getStartDate()) |
|---|
| 351 | XG.writeTag("endDate", c.getEndDate()) |
|---|
| 352 | XG.writeTag("timezone", 'UTC') |
|---|
| 353 | XG.writeTag("eventTimezone", c.getTimezone()) |
|---|
| 354 | if c.getRoom() != None: |
|---|
| 355 | XG.writeTag("room", c.getRoom().getName()) |
|---|
| 356 | else: |
|---|
| 357 | XG.writeTag("room", "") |
|---|
| 358 | for i in c.getChairList(): |
|---|
| 359 | XG.writeTag("chairman", i.getFullName()) |
|---|
| 360 | if c.getChairmanText() != "": |
|---|
| 361 | XG.writeTag("chairmanText", c.getChairmanText()) |
|---|
| 362 | for i in c.getSessionListSorted(): |
|---|
| 363 | if self._dateFit(i): |
|---|
| 364 | self._printSession(i, XG) |
|---|
| 365 | for i in c.getContributionList(): |
|---|
| 366 | # list only 'orphaned' contributions |
|---|
| 367 | if i.getSession() == None: |
|---|
| 368 | if i.isScheduled() and self._dateFit(i): |
|---|
| 369 | self._printContribution(i, XG) |
|---|
| 370 | XG.closeTag("event") |
|---|
| 371 | |
|---|
| 372 | def _dateFit(self, item): |
|---|
| 373 | if self._date != None: |
|---|
| 374 | if item.getStartDate().date() <= self._date.date() and item.getEndDate().date() >= self._date.date(): |
|---|
| 375 | return True |
|---|
| 376 | else: |
|---|
| 377 | return False |
|---|
| 378 | return True |
|---|
| 379 | |
|---|
| 380 | def _process(self): |
|---|
| 381 | if self._statusValue != "OK": |
|---|
| 382 | return self._createResponse(self._statusValue, self._message) |
|---|
| 383 | |
|---|
| 384 | ih = indexes.IndexesHolder() |
|---|
| 385 | calIdx = ih.getIndex("calendar") |
|---|
| 386 | catIdx = ih.getIndex("category") |
|---|
| 387 | ch = conference.ConferenceHolder() |
|---|
| 388 | |
|---|
| 389 | # A *preliminary* set of conference id's is created here |
|---|
| 390 | # This set is constructed using indexes, without getting the Conference |
|---|
| 391 | # objects from the DB. |
|---|
| 392 | |
|---|
| 393 | listOfSets = [] |
|---|
| 394 | |
|---|
| 395 | if self._startDateAt != None: |
|---|
| 396 | listOfSets.append(calIdx.getObjectsStartingInDay(self._startDateAt)) |
|---|
| 397 | |
|---|
| 398 | if self._startDateFrom != None: |
|---|
| 399 | listOfSets.append(calIdx.getObjectsStartingIn(self._startDateFrom,self._startDateTo)) |
|---|
| 400 | |
|---|
| 401 | if self._endDateAt != None: |
|---|
| 402 | listOfSets.append(calIdx.getObjectsEndingInDay(self._endDateAt)) |
|---|
| 403 | |
|---|
| 404 | if self._endDateFrom != None: |
|---|
| 405 | listOfSets.append(calIdx.getObjectsEndingIn(self._endDateFrom,self._endDateTo)) |
|---|
| 406 | |
|---|
| 407 | if self._date != None: |
|---|
| 408 | listOfSets.append(calIdx.getObjectsIn(self._date, self._date)) |
|---|
| 409 | |
|---|
| 410 | if self._category != None: |
|---|
| 411 | resultSet = Set() |
|---|
| 412 | if type(self._category) is list: |
|---|
| 413 | for i in self._category: |
|---|
| 414 | resultSet.union_update(catIdx.getItems(i)) |
|---|
| 415 | else: |
|---|
| 416 | resultSet.union_update(catIdx.getItems(self._category)) |
|---|
| 417 | |
|---|
| 418 | listOfSets.append(resultSet) |
|---|
| 419 | |
|---|
| 420 | if self._id != None: |
|---|
| 421 | resultSet = Set() |
|---|
| 422 | if type(self._id) is list: |
|---|
| 423 | listOfSets.append(Set(self._id)) |
|---|
| 424 | else: |
|---|
| 425 | listOfSets.append(Set([self._id])) |
|---|
| 426 | |
|---|
| 427 | prelimResult = listOfSets[0] |
|---|
| 428 | for i in range(1, len(listOfSets)): |
|---|
| 429 | prelimResult.intersection_update(listOfSets[i]) |
|---|
| 430 | |
|---|
| 431 | result = Set() |
|---|
| 432 | |
|---|
| 433 | XG = xmlGen.XMLGen() |
|---|
| 434 | XG.openTag("response") |
|---|
| 435 | XG.openTag("status") |
|---|
| 436 | XG.writeTag("value", "OK") |
|---|
| 437 | XG.writeTag("message", "Returning search results") |
|---|
| 438 | XG.closeTag("status") |
|---|
| 439 | XG.openTag("event-list") |
|---|
| 440 | for i in prelimResult: |
|---|
| 441 | try: |
|---|
| 442 | try: |
|---|
| 443 | c = ch.getById(i) |
|---|
| 444 | except: |
|---|
| 445 | continue |
|---|
| 446 | if self._author != None and not self._checkAuthor(c, self._author): |
|---|
| 447 | continue |
|---|
| 448 | if self._room != None and not self._checkRoom(c, self._room): |
|---|
| 449 | continue |
|---|
| 450 | if self._startDateFrom != None: |
|---|
| 451 | if c.getStartDate() < self._startDateFrom or \ |
|---|
| 452 | c.getStartDate() > self._startDateTo: |
|---|
| 453 | continue |
|---|
| 454 | if self._startDateAt != None: |
|---|
| 455 | if c.getStartDate() != self._startDateAt: |
|---|
| 456 | continue |
|---|
| 457 | if self._endDateFrom != None: |
|---|
| 458 | if c.getEndDate() < self._endDateFrom or \ |
|---|
| 459 | c.getEndDate() > self._endDateTo: |
|---|
| 460 | continue |
|---|
| 461 | if self._endDateAt != None: |
|---|
| 462 | if c.getEndDate() != self._endDateAt: |
|---|
| 463 | continue |
|---|
| 464 | result.add(i) |
|---|
| 465 | if self._format != "full": |
|---|
| 466 | self._printConference(c, XG) |
|---|
| 467 | else: |
|---|
| 468 | XG.openTag("event") |
|---|
| 469 | og = outputGenerator(self.getAW(), XG) |
|---|
| 470 | og._confToXML(c,{}) |
|---|
| 471 | XG.closeTag("event") |
|---|
| 472 | |
|---|
| 473 | except KeyError: |
|---|
| 474 | continue |
|---|
| 475 | |
|---|
| 476 | XG.closeTag("event-list") |
|---|
| 477 | XG.closeTag("response") |
|---|
| 478 | self._req.content_type = "text/xml" |
|---|
| 479 | |
|---|
| 480 | return XG.getXml() |
|---|
| 481 | |
|---|
| 482 | class RHAddMaterialBase ( base.RHModificationBaseProtected, RHXMLHandlerBase ): |
|---|
| 483 | |
|---|
| 484 | def _checkParams(self, params): |
|---|
| 485 | base.RHModificationBaseProtected._checkParams(self, params) |
|---|
| 486 | self._title = params.get('title', 'video') |
|---|
| 487 | self._value = params.get('value', '') |
|---|
| 488 | |
|---|
| 489 | def _process(self): |
|---|
| 490 | try: |
|---|
| 491 | try: |
|---|
| 492 | m = self._target.getMaterialById(self._title) |
|---|
| 493 | except: |
|---|
| 494 | m = None |
|---|
| 495 | if m == None: |
|---|
| 496 | m = conference.Material() |
|---|
| 497 | self._target.addMaterial( m ) |
|---|
| 498 | params = { "title":self._title } |
|---|
| 499 | m.setValues(params) |
|---|
| 500 | l = conference.Link() |
|---|
| 501 | l.setURL(self._value) |
|---|
| 502 | m.addResource(l) |
|---|
| 503 | m.setMainResource(l) |
|---|
| 504 | except MaKaCError, e: |
|---|
| 505 | return self._createResponse("ERROR", e.getMsg()) |
|---|
| 506 | except Exception, e: |
|---|
| 507 | return self._createResponse("ERROR", "internal error: %s" % e) |
|---|
| 508 | return self._createResponse("OK", "Material added") |
|---|
| 509 | |
|---|
| 510 | class RHAddMaterialToConference (RHAddMaterialBase): |
|---|
| 511 | |
|---|
| 512 | def _checkParams(self, params): |
|---|
| 513 | l = locators.WebLocator() |
|---|
| 514 | l.setConference( params ) |
|---|
| 515 | self._target = l.getObject() |
|---|
| 516 | RHAddMaterialBase._checkParams(self, params) |
|---|
| 517 | |
|---|
| 518 | class RHAddMaterialToSession (RHAddMaterialBase): |
|---|
| 519 | |
|---|
| 520 | def _checkParams(self, params): |
|---|
| 521 | l = locators.WebLocator() |
|---|
| 522 | l.setSession( params ) |
|---|
| 523 | self._target = l.getObject() |
|---|
| 524 | RHAddMaterialBase._checkParams(self, params) |
|---|
| 525 | |
|---|
| 526 | class RHAddMaterialToContribution (RHAddMaterialBase): |
|---|
| 527 | |
|---|
| 528 | def _checkParams(self, params): |
|---|
| 529 | l = locators.WebLocator() |
|---|
| 530 | l.setContribution( params ) |
|---|
| 531 | self._target = l.getObject() |
|---|
| 532 | RHAddMaterialBase._checkParams(self, params) |
|---|
| 533 | |
|---|
| 534 | class RHAddMaterialToSubContribution (RHAddMaterialBase): |
|---|
| 535 | |
|---|
| 536 | def _checkParams(self, params): |
|---|
| 537 | l = locators.WebLocator() |
|---|
| 538 | l.setSubContribution( params ) |
|---|
| 539 | self._target = l.getObject() |
|---|
| 540 | RHAddMaterialBase._checkParams(self, params) |
|---|
| 541 | |
|---|
| 542 | class RHCreateEventBase ( base.RHProtected, RHXMLHandlerBase ): |
|---|
| 543 | |
|---|
| 544 | def _checkParams(self, params): |
|---|
| 545 | |
|---|
| 546 | base.RHProtected._checkParams(self, params) |
|---|
| 547 | self._statusValue = "OK" |
|---|
| 548 | self._message = "" |
|---|
| 549 | try: |
|---|
| 550 | self._title = params.get( "title", "" ).strip() |
|---|
| 551 | self._startdate = params.get( "startdate", "" ).strip() |
|---|
| 552 | self._enddate = params.get( "enddate", "" ).strip() |
|---|
| 553 | self._place = params.get( "place", "" ).strip() |
|---|
| 554 | self._room = params.get( "room", "" ).strip() |
|---|
| 555 | self._accessPassword = params.get( "an", "" ).strip() |
|---|
| 556 | self._modifyPassword = params.get( "mp", "" ).strip() |
|---|
| 557 | self._style = params.get( "style", "" ).strip() |
|---|
| 558 | self._fid = params.get( "fid", "" ).strip() |
|---|
| 559 | self._description = params.get( "description", "" ).strip() |
|---|
| 560 | self._stime = params.get( "stime", "" ).strip() |
|---|
| 561 | self._etime = params.get( "etime", "" ).strip() |
|---|
| 562 | self._speaker = params.get( "speaker", "" ).strip() |
|---|
| 563 | self._speakeremail = params.get( "email", "" ).strip() |
|---|
| 564 | self._speakeraffiliation = params.get( "affiliation", "" ).strip() |
|---|
| 565 | if not self._title or not self._startdate or not self._enddate or not self._fid or not self._stime or not self._etime: |
|---|
| 566 | raise MaKaCError( _("mandatory parameter missing")) |
|---|
| 567 | ch = CategoryManager() |
|---|
| 568 | try: |
|---|
| 569 | self._cat = ch.getById(self._fid) |
|---|
| 570 | except: |
|---|
| 571 | raise MaKaCError( _("unknown category")) |
|---|
| 572 | except MaKaCError, e: |
|---|
| 573 | self._statusValue = "ERROR" |
|---|
| 574 | self._message = e.getMsg() |
|---|
| 575 | except: |
|---|
| 576 | self._statusValue = "ERROR" |
|---|
| 577 | self._message = "Internal error" |
|---|
| 578 | |
|---|
| 579 | def _process(self): |
|---|
| 580 | try: |
|---|
| 581 | ah = user.AvatarHolder() |
|---|
| 582 | us = ah.match({'email':'cds.support@cern.ch'})[0] |
|---|
| 583 | self._event = self._cat.newConference(us) |
|---|
| 584 | self._event.setTitle(self._title) |
|---|
| 585 | self._event.setDescription(self._description) |
|---|
| 586 | sd = self._startdate.split("/") |
|---|
| 587 | st = self._stime.split(":") |
|---|
| 588 | sdate = datetime(int(sd[2]),int(sd[1]),int(sd[0]),int(st[0]),int(st[1])) |
|---|
| 589 | ed = self._enddate.split("/") |
|---|
| 590 | et = self._etime.split(":") |
|---|
| 591 | edate = datetime(int(ed[2]),int(ed[1]),int(ed[0]),int(et[0]),int(et[1])) |
|---|
| 592 | self._event.setDates(sdate,edate) |
|---|
| 593 | chair = conference.ConferenceChair() |
|---|
| 594 | chair.setFamilyName(self._speaker) |
|---|
| 595 | chair.setEmail(self._speakeremail) |
|---|
| 596 | self._event.addChair(chair) |
|---|
| 597 | self._event.setAccessKey(self._accessPassword) |
|---|
| 598 | self._event.setModifKey(self._modifyPassword) |
|---|
| 599 | except MaKaCError, e: |
|---|
| 600 | self._statusValue = "ERROR" |
|---|
| 601 | self._message = e.getMsg() |
|---|
| 602 | except: |
|---|
| 603 | self._statusValue = "ERROR" |
|---|
| 604 | self._message = "Internal error" |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | class RHCreateLecture ( RHCreateEventBase ): |
|---|
| 608 | |
|---|
| 609 | def _process(self): |
|---|
| 610 | if self._statusValue != "OK": |
|---|
| 611 | return self._createResponse(self._statusValue, self._message) |
|---|
| 612 | RHCreateEventBase._process( self ) |
|---|
| 613 | if self._statusValue != "OK": |
|---|
| 614 | return self._createResponse(self._statusValue, self._message) |
|---|
| 615 | wr = webFactoryRegistry.WebFactoryRegistry() |
|---|
| 616 | fact = wr.getFactoryById('simple_event') |
|---|
| 617 | wr.registerFactory(self._event, fact) |
|---|
| 618 | return self._createResponse("OK", "Lecture %s added" % self._event.getId()) |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | class RHCategInfo( RHXMLHandlerBase ): |
|---|
| 622 | |
|---|
| 623 | def _checkParams( self, params ): |
|---|
| 624 | self._id = params.get( "id", "" ).strip() |
|---|
| 625 | self._fp = params.get( "fp", "no" ).strip() |
|---|
| 626 | |
|---|
| 627 | def _getHeader( self, XG ): |
|---|
| 628 | XG.openTag("response") |
|---|
| 629 | XG.openTag("status") |
|---|
| 630 | XG.writeTag("value", "OK") |
|---|
| 631 | XG.writeTag("message", "Returning category info") |
|---|
| 632 | XG.closeTag("status") |
|---|
| 633 | |
|---|
| 634 | def _getFooter( self, XG ): |
|---|
| 635 | XG.closeTag("response") |
|---|
| 636 | |
|---|
| 637 | def _getCategXML( self, cat, XG, fp="no" ): |
|---|
| 638 | XG.openTag("categInfo") |
|---|
| 639 | XG.writeTag("title",cat.getTitle()) |
|---|
| 640 | XG.writeTag("id",cat.getId()) |
|---|
| 641 | if fp == "yes": |
|---|
| 642 | XG.openTag("father") |
|---|
| 643 | if cat.getOwner(): |
|---|
| 644 | self._getCategXML(cat.getOwner(),XG,fp) |
|---|
| 645 | fatherid = cat.getOwner().getId() |
|---|
| 646 | XG.closeTag("father") |
|---|
| 647 | XG.closeTag("categInfo") |
|---|
| 648 | return XG.getXml() |
|---|
| 649 | |
|---|
| 650 | def _process( self ): |
|---|
| 651 | self._req.content_type = "text/xml" |
|---|
| 652 | cm = CategoryManager() |
|---|
| 653 | try: |
|---|
| 654 | XG = xmlGen.XMLGen() |
|---|
| 655 | cat = cm.getById(self._id) |
|---|
| 656 | self._getHeader(XG) |
|---|
| 657 | self._getCategXML(cat, XG, self._fp) |
|---|
| 658 | self._getFooter(XG) |
|---|
| 659 | return XG.getXml() |
|---|
| 660 | except: |
|---|
| 661 | value = "ERROR" |
|---|
| 662 | message = "Category does not exist" |
|---|
| 663 | if value != "OK": |
|---|
| 664 | return self._createResponse(value, message) |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | class RHStatsRoomBooking( base.RoomBookingDBMixin, RHXMLHandlerBase ): |
|---|
| 668 | |
|---|
| 669 | def _createIndicator( self, XG, name, fullname, value ): |
|---|
| 670 | XG.openTag("indicator") |
|---|
| 671 | XG.writeTag("name", name) |
|---|
| 672 | XG.writeTag("fullname", fullname) |
|---|
| 673 | XG.writeTag("value", value) |
|---|
| 674 | XG.closeTag("indicator") |
|---|
| 675 | |
|---|
| 676 | def _process( self ): |
|---|
| 677 | from MaKaC.rb_room import RoomBase |
|---|
| 678 | from datetime import datetime,timedelta |
|---|
| 679 | from MaKaC.rb_reservation import ReservationBase |
|---|
| 680 | |
|---|
| 681 | startdt = enddt = datetime.now() |
|---|
| 682 | today = startdt.date() |
|---|
| 683 | startdt.replace( hour = 0, minute = 0) |
|---|
| 684 | enddt.replace( hour = 23, minute = 59) |
|---|
| 685 | |
|---|
| 686 | self._req.content_type = "text/xml" |
|---|
| 687 | XG = xmlGen.XMLGen() |
|---|
| 688 | XG.openTag("response") |
|---|
| 689 | |
|---|
| 690 | rooms = RoomBase.getRooms() |
|---|
| 691 | nbRooms = len(rooms) |
|---|
| 692 | nbPublicRooms = nbPrivateRooms = nbSemiPrivateRooms = 0 |
|---|
| 693 | for r in rooms: |
|---|
| 694 | if not r.isReservable: |
|---|
| 695 | nbPrivateRooms += 1 |
|---|
| 696 | elif not r.resvsNeedConfirmation: |
|---|
| 697 | nbPublicRooms += 1 |
|---|
| 698 | else: |
|---|
| 699 | nbSemiPrivateRooms += 1 |
|---|
| 700 | |
|---|
| 701 | self._createIndicator(XG, "total", "total number of managed rooms", nbRooms) |
|---|
| 702 | self._createIndicator(XG, "public", "number of public rooms", nbPublicRooms) |
|---|
| 703 | self._createIndicator(XG, "semiprivate", "number of semi-private rooms", nbSemiPrivateRooms) |
|---|
| 704 | self._createIndicator(XG, "private", "number of private rooms", nbPrivateRooms) |
|---|
| 705 | |
|---|
| 706 | resvex = ReservationBase() |
|---|
| 707 | resvex.isConfirmed = True |
|---|
| 708 | resvex.isCancelled = False |
|---|
| 709 | nbResvs = len(ReservationBase.getReservations( resvExample = resvex, days = [ startdt.date() ] )) |
|---|
| 710 | resvex.usesAVC = True |
|---|
| 711 | nbAVResvs = len(ReservationBase.getReservations( resvExample = resvex, days = [ startdt.date() ] )) |
|---|
| 712 | resvex.needsAVCSupport = True |
|---|
| 713 | nbAVResvsWithSupport = len(ReservationBase.getReservations( resvExample = resvex, days = [ startdt.date() ] )) |
|---|
| 714 | |
|---|
| 715 | self._createIndicator(XG, "nbbookings", "total number of bookings for today", nbResvs) |
|---|
| 716 | self._createIndicator(XG, "nbvc", "number of remote collaboration bookings (video or phone conference)", nbAVResvs) |
|---|
| 717 | self._createIndicator(XG, "nbvcsupport", "number of remote collaboration bookings with planned IT support", nbAVResvsWithSupport) |
|---|
| 718 | |
|---|
| 719 | XG.closeTag("response") |
|---|
| 720 | return XG.getXml() |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | class RHStatsIndico( RHXMLHandlerBase ): |
|---|
| 724 | |
|---|
| 725 | def _createIndicator( self, XG, name, fullname, value ): |
|---|
| 726 | XG.openTag("indicator") |
|---|
| 727 | XG.writeTag("name", name) |
|---|
| 728 | XG.writeTag("fullname", fullname) |
|---|
| 729 | XG.writeTag("value", value) |
|---|
| 730 | XG.closeTag("indicator") |
|---|
| 731 | |
|---|
| 732 | def _process( self ): |
|---|
| 733 | from datetime import datetime,timedelta |
|---|
| 734 | from MaKaC.common.indexes import IndexesHolder |
|---|
| 735 | |
|---|
| 736 | self._req.content_type = "text/xml" |
|---|
| 737 | XG = xmlGen.XMLGen() |
|---|
| 738 | XG.openTag("response") |
|---|
| 739 | |
|---|
| 740 | now = startdt = enddt = datetime.now() |
|---|
| 741 | today = startdt.date() |
|---|
| 742 | startdt.replace( hour = 0, minute = 0) |
|---|
| 743 | enddt.replace( hour = 23, minute = 59) |
|---|
| 744 | |
|---|
| 745 | calIdx = IndexesHolder().getById("calendar") |
|---|
| 746 | |
|---|
| 747 | nbEvtsToday = len(calIdx.getObjectsInDay(now)) |
|---|
| 748 | nbOngoingEvts = len(calIdx.getObjectsIn(now,now)) |
|---|
| 749 | |
|---|
| 750 | self._createIndicator(XG, "nbEventsToday", "total number of events for today", nbEvtsToday) |
|---|
| 751 | self._createIndicator(XG, "nbOngoingEvents", "total number of ongoing events", nbOngoingEvts) |
|---|
| 752 | XG.closeTag("response") |
|---|
| 753 | return XG.getXml() |
|---|