| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## $Id: collaboration.py,v 1.20 2009/05/27 08:52:22 jose Exp $ |
|---|
| 4 | ## |
|---|
| 5 | ## This file is part of CDS Indico. |
|---|
| 6 | ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN. |
|---|
| 7 | ## |
|---|
| 8 | ## CDS Indico is free software; you can redistribute it and/or |
|---|
| 9 | ## modify it under the terms of the GNU General Public License as |
|---|
| 10 | ## published by the Free Software Foundation; either version 2 of the |
|---|
| 11 | ## License, or (at your option) any later version. |
|---|
| 12 | ## |
|---|
| 13 | ## CDS Indico is distributed in the hope that it will be useful, but |
|---|
| 14 | ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | ## General Public License for more details. |
|---|
| 17 | ## |
|---|
| 18 | ## 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. |
|---|
| 21 | |
|---|
| 22 | from datetime import timedelta |
|---|
| 23 | from MaKaC.webinterface import wcomponents, urlHandlers |
|---|
| 24 | from MaKaC.webinterface.pages.conferences import WPConferenceModifBase,\ |
|---|
| 25 | WPConferenceDefaultDisplayBase |
|---|
| 26 | from MaKaC.plugins.Collaboration.collaborationTools import CollaborationTools |
|---|
| 27 | from MaKaC.common.timezoneUtils import nowutc, setAdjustedDate, DisplayTZ |
|---|
| 28 | from MaKaC.common.utils import formatDateTime, parseDateTime |
|---|
| 29 | from MaKaC.common.timezoneUtils import getAdjustedDate |
|---|
| 30 | from MaKaC.i18n import _ |
|---|
| 31 | from MaKaC.common.PickleJar import DictPickler |
|---|
| 32 | from MaKaC.webinterface.rh.admins import RCAdmin |
|---|
| 33 | from MaKaC.webinterface.pages.main import WPMainBase |
|---|
| 34 | from MaKaC.common.indexes import IndexesHolder |
|---|
| 35 | from MaKaC.plugins.Collaboration.base import CollaborationException |
|---|
| 36 | |
|---|
| 37 | ################################################### Server Wide pages ######################################### |
|---|
| 38 | |
|---|
| 39 | class WPAdminCollaboration(WPMainBase): |
|---|
| 40 | |
|---|
| 41 | def __init__(self, rh, queryParams): |
|---|
| 42 | WPMainBase.__init__(self, rh) |
|---|
| 43 | self._queryParams = queryParams |
|---|
| 44 | self._pluginsWithIndexing = CollaborationTools.pluginsWithIndexing() # list of names |
|---|
| 45 | self._buildExtraJS() |
|---|
| 46 | |
|---|
| 47 | def getJSFiles(self): |
|---|
| 48 | return WPMainBase.getJSFiles(self) + self._includeJSPackage('Collaboration') |
|---|
| 49 | |
|---|
| 50 | def _getHeader( self ): |
|---|
| 51 | wc = wcomponents.WHeader( self._getAW() ) |
|---|
| 52 | return wc.getHTML( { "subArea": _("Video Services Administration"), \ |
|---|
| 53 | "loginURL": self._escapeChars(str(self.getLoginURL())),\ |
|---|
| 54 | "logoutURL": self._escapeChars(str(self.getLogoutURL())), \ |
|---|
| 55 | "tabControl": self._getTabControl(), \ |
|---|
| 56 | "loginAsURL": self.getLoginAsURL() } ) |
|---|
| 57 | |
|---|
| 58 | def _getBody( self, params ): |
|---|
| 59 | return WAdminCollaboration(self._queryParams, self._pluginsWithIndexing).getHTML() |
|---|
| 60 | |
|---|
| 61 | def _getNavigationDrawer(self): |
|---|
| 62 | return wcomponents.WSimpleNavigationDrawer("Video Services Admin", urlHandlers.UHAdminCollaboration.getURL ) |
|---|
| 63 | |
|---|
| 64 | def _buildExtraJS(self): |
|---|
| 65 | for pluginName in self._pluginsWithIndexing: |
|---|
| 66 | extraJS = CollaborationTools.getExtraJS(pluginName, None) |
|---|
| 67 | if extraJS: |
|---|
| 68 | self.addExtraJS(extraJS) |
|---|
| 69 | |
|---|
| 70 | class WAdminCollaboration(wcomponents.WTemplated): |
|---|
| 71 | |
|---|
| 72 | def __init__(self, queryParams, pluginsWithIndexing): |
|---|
| 73 | wcomponents.WTemplated.__init__(self) |
|---|
| 74 | self._queryParams = queryParams |
|---|
| 75 | self._pluginsWithIndexing = pluginsWithIndexing # list of names |
|---|
| 76 | |
|---|
| 77 | def getVars( self ): |
|---|
| 78 | vars = wcomponents.WTemplated.getVars( self ) |
|---|
| 79 | |
|---|
| 80 | #dictionary where the keys are names of false "indexes" for the user, and the values are IndexInformation objects |
|---|
| 81 | vars["Indexes"] = CollaborationTools.getCollaborationPluginType().getOption("pluginsPerIndex").getValue() |
|---|
| 82 | vars["InitialIndex"] = self._queryParams["indexName"] |
|---|
| 83 | vars["InitialViewBy"] = self._queryParams["viewBy"] |
|---|
| 84 | vars["InitialOrderBy"] = self._queryParams["orderBy"] |
|---|
| 85 | vars["InitialOnlyPending"] = self._queryParams["onlyPending"] |
|---|
| 86 | vars["InitialConferenceId"] = self._queryParams["conferenceId"] |
|---|
| 87 | vars["InitialCategoryId"] = self._queryParams["categoryId"] |
|---|
| 88 | vars["InitialSinceDate"] = self._queryParams["sinceDate"] |
|---|
| 89 | vars["InitialToDate"] = self._queryParams["toDate"] |
|---|
| 90 | vars["InitialFromDays"] = self._queryParams["fromDays"] |
|---|
| 91 | vars["InitialToDays"] = self._queryParams["toDays"] |
|---|
| 92 | vars["InitialFromTitle"] = self._queryParams["fromTitle"] |
|---|
| 93 | vars["InitialToTitle"] = self._queryParams["toTitle"] |
|---|
| 94 | vars["InitialResultsPerPage"] = self._queryParams["resultsPerPage"] |
|---|
| 95 | vars["InitialPage"] = self._queryParams["page"] |
|---|
| 96 | vars["BaseURL"] = urlHandlers.UHAdminCollaboration.getURL() |
|---|
| 97 | |
|---|
| 98 | if self._queryParams["queryOnLoad"]: |
|---|
| 99 | ci = IndexesHolder().getById('collaboration') |
|---|
| 100 | tz = self._rh._getUser().getTimezone() |
|---|
| 101 | ##### |
|---|
| 102 | minKey = None |
|---|
| 103 | maxKey = None |
|---|
| 104 | if self._queryParams['sinceDate']: |
|---|
| 105 | minKey = setAdjustedDate(parseDateTime(self._queryParams['sinceDate'].strip()), tz = self._tz) |
|---|
| 106 | if self._queryParams['toDate']: |
|---|
| 107 | maxKey = setAdjustedDate(parseDateTime(self._queryParams['toDate'].strip()), tz = self._tz) |
|---|
| 108 | if self._queryParams['fromTitle']: |
|---|
| 109 | minKey = self._queryParams['fromTitle'].strip() |
|---|
| 110 | if self._queryParams['toTitle']: |
|---|
| 111 | maxKey = self._queryParams['toTitle'].strip() |
|---|
| 112 | if self._queryParams['fromDays']: |
|---|
| 113 | try: |
|---|
| 114 | fromDays = int(self._queryParams['fromDays']) |
|---|
| 115 | except ValueError, e: |
|---|
| 116 | raise CollaborationException(_("Parameter 'fromDays' is not an integer"), inner = e) |
|---|
| 117 | minKey = nowutc() - timedelta(days = fromDays) |
|---|
| 118 | if self._queryParams['toDays']: |
|---|
| 119 | try: |
|---|
| 120 | toDays = int(self._queryParams['toDays']) |
|---|
| 121 | except ValueError, e: |
|---|
| 122 | raise CollaborationException(_("Parameter 'toDays' is not an integer"), inner = e) |
|---|
| 123 | maxKey = nowutc() + timedelta(days = toDays) |
|---|
| 124 | |
|---|
| 125 | if self._queryParams["conferenceId"]: |
|---|
| 126 | conferenceId = self._queryParams["conferenceId"] |
|---|
| 127 | else: |
|---|
| 128 | conferenceId = None |
|---|
| 129 | |
|---|
| 130 | if self._queryParams["categoryId"]: |
|---|
| 131 | categoryId = self._queryParams["categoryId"] |
|---|
| 132 | else: |
|---|
| 133 | categoryId = None |
|---|
| 134 | |
|---|
| 135 | result = ci.getBookings( |
|---|
| 136 | self._queryParams["indexName"], |
|---|
| 137 | self._queryParams["viewBy"], |
|---|
| 138 | self._queryParams["orderBy"], |
|---|
| 139 | minKey, |
|---|
| 140 | maxKey, |
|---|
| 141 | tz = tz, |
|---|
| 142 | onlyPending = self._queryParams["onlyPending"], |
|---|
| 143 | conferenceId = conferenceId, |
|---|
| 144 | categoryId = categoryId, |
|---|
| 145 | pickle = True, |
|---|
| 146 | dateFormat='%a %d %b %Y', |
|---|
| 147 | page = self._queryParams["page"], |
|---|
| 148 | resultsPerPage = self._queryParams["resultsPerPage"]) |
|---|
| 149 | |
|---|
| 150 | vars["InitialBookings"] = result["results"] |
|---|
| 151 | vars["InitialNumberOfBookings"] = result["nBookings"] |
|---|
| 152 | vars["InitialTotalInIndex"] = result["totalInIndex"] |
|---|
| 153 | vars["InitialNumberOfPages"] = result["nPages"] |
|---|
| 154 | |
|---|
| 155 | else: |
|---|
| 156 | vars["InitialBookings"] = None |
|---|
| 157 | vars["InitialNumberOfBookings"] = -1 |
|---|
| 158 | vars["InitialTotalInIndex"] = -1 |
|---|
| 159 | vars["InitialNumberOfPages"] = -1 |
|---|
| 160 | |
|---|
| 161 | JSCodes = {} |
|---|
| 162 | for pluginName in self._pluginsWithIndexing: |
|---|
| 163 | templateClass = CollaborationTools.getTemplateClass(pluginName, "WIndexing") |
|---|
| 164 | if templateClass: |
|---|
| 165 | JSCodes[pluginName] = templateClass(pluginName, None).getHTML() |
|---|
| 166 | |
|---|
| 167 | vars["JSCodes"] = JSCodes |
|---|
| 168 | |
|---|
| 169 | return vars |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | ################################################### Event Modif pages ############################################### |
|---|
| 173 | |
|---|
| 174 | class WPConfModifCSBase (WPConferenceModifBase): |
|---|
| 175 | |
|---|
| 176 | def __init__(self, rh, conf): |
|---|
| 177 | """ Constructor |
|---|
| 178 | The rh is expected to have the attributes _tabs, _activeTab, _tabPlugins (like for ex. RHConfModifCSBookings) |
|---|
| 179 | """ |
|---|
| 180 | WPConferenceModifBase.__init__(self, rh, conf) |
|---|
| 181 | self._conf = conf |
|---|
| 182 | self._tabs = {} # list of Indico's Tab objects |
|---|
| 183 | self._tabNames = rh._tabs |
|---|
| 184 | self._activeTabName = rh._activeTabName |
|---|
| 185 | |
|---|
| 186 | def _createTabCtrl(self): |
|---|
| 187 | self._tabCtrl = wcomponents.TabControl() |
|---|
| 188 | |
|---|
| 189 | isUsingHTTPS = CollaborationTools.isUsingHTTPS() |
|---|
| 190 | for tabName in self._tabNames: |
|---|
| 191 | if tabName == 'Managers': |
|---|
| 192 | url = urlHandlers.UHConfModifCollaborationManagers.getURL(self._conf) |
|---|
| 193 | else: |
|---|
| 194 | url = urlHandlers.UHConfModifCollaboration.getURL(self._conf, secure = isUsingHTTPS, tab = tabName) |
|---|
| 195 | self._tabs[tabName] = self._tabCtrl.newTab(tabName, tabName, url) |
|---|
| 196 | |
|---|
| 197 | self._setActiveTab() |
|---|
| 198 | |
|---|
| 199 | def _setActiveTab( self ): |
|---|
| 200 | self._tabs[self._activeTabName].setActive() |
|---|
| 201 | |
|---|
| 202 | def _setActiveSideMenuItem(self): |
|---|
| 203 | self._videoServicesMenuItem.setActive() |
|---|
| 204 | |
|---|
| 205 | class WPConfModifCollaboration( WPConfModifCSBase ): |
|---|
| 206 | |
|---|
| 207 | def __init__(self, rh, conf): |
|---|
| 208 | """ Constructor |
|---|
| 209 | The rh is expected to have the attributes _tabs, _activeTabName, _tabPlugins (like RHConfModifCSBookings) |
|---|
| 210 | """ |
|---|
| 211 | WPConfModifCSBase.__init__(self, rh, conf) |
|---|
| 212 | self._tabPlugins = rh._tabPlugins |
|---|
| 213 | self._buildExtraCSS() |
|---|
| 214 | self._buildExtraJS() |
|---|
| 215 | |
|---|
| 216 | def getJSFiles(self): |
|---|
| 217 | return WPMainBase.getJSFiles(self) + self._includeJSPackage('Collaboration') + self._includeJSPackage("Management") |
|---|
| 218 | |
|---|
| 219 | ######### private methods ############### |
|---|
| 220 | def _buildExtraCSS(self): |
|---|
| 221 | for plugin in self._tabPlugins: |
|---|
| 222 | extraCSS = CollaborationTools.getExtraCSS(plugin.getName()) |
|---|
| 223 | if extraCSS: |
|---|
| 224 | self.addExtraCSS(extraCSS) |
|---|
| 225 | |
|---|
| 226 | def _buildExtraJS(self): |
|---|
| 227 | for plugin in self._tabPlugins: |
|---|
| 228 | extraJS = CollaborationTools.getExtraJS(plugin.getName(), self._conf) |
|---|
| 229 | if extraJS: |
|---|
| 230 | self.addExtraJS(extraJS) |
|---|
| 231 | |
|---|
| 232 | ############## overloading methods ################# |
|---|
| 233 | |
|---|
| 234 | def _getPageContent( self, params ): |
|---|
| 235 | if len(self._tabNames) > 0: |
|---|
| 236 | self._createTabCtrl() |
|---|
| 237 | wc = WConfModifCollaboration( self._conf, self._rh.getAW().getUser(), self._activeTabName, self._tabPlugins) |
|---|
| 238 | return wcomponents.WTabControl( self._tabCtrl, self._getAW() ).getHTML( wc.getHTML({}) ) |
|---|
| 239 | else: |
|---|
| 240 | return _("No available plugins, or no active plugins") |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | class WConfModifCollaboration( wcomponents.WTemplated ): |
|---|
| 244 | |
|---|
| 245 | def __init__( self, conference, user, activeTab, tabPlugins ): |
|---|
| 246 | self._conf = conference |
|---|
| 247 | self._user = user |
|---|
| 248 | self._activeTab = activeTab |
|---|
| 249 | self._tabPlugins = tabPlugins |
|---|
| 250 | |
|---|
| 251 | def getVars( self ): |
|---|
| 252 | vars = wcomponents.WTemplated.getVars( self ) |
|---|
| 253 | |
|---|
| 254 | plugins = self._tabPlugins |
|---|
| 255 | singleBookingPlugins, multipleBookingPlugins = CollaborationTools.splitPluginsByAllowMultiple(plugins) |
|---|
| 256 | CSBookingManager = self._conf.getCSBookingManager() |
|---|
| 257 | |
|---|
| 258 | bookingsS = {} |
|---|
| 259 | for p in singleBookingPlugins: |
|---|
| 260 | bookingList = CSBookingManager.getBookingList(filterByType = p.getName()) |
|---|
| 261 | if len(bookingList) > 0: |
|---|
| 262 | bookingsS[p.getName()] = DictPickler.pickle(bookingList[0]) |
|---|
| 263 | |
|---|
| 264 | bookingsM = DictPickler.pickle(CSBookingManager.getBookingList( |
|---|
| 265 | sorted = True, |
|---|
| 266 | notify = True, |
|---|
| 267 | filterByType = [p.getName() for p in multipleBookingPlugins])) |
|---|
| 268 | |
|---|
| 269 | vars["Conference"] = self._conf |
|---|
| 270 | vars["AllPlugins"] = plugins |
|---|
| 271 | vars["SingleBookingPlugins"] = singleBookingPlugins |
|---|
| 272 | vars["BookingsS"] = bookingsS |
|---|
| 273 | vars["MultipleBookingPlugins"] = multipleBookingPlugins |
|---|
| 274 | vars["BookingsM"] = bookingsM |
|---|
| 275 | vars["Tab"] = self._activeTab |
|---|
| 276 | vars["EventDate"] = formatDateTime(getAdjustedDate(nowutc(),self._conf)) |
|---|
| 277 | |
|---|
| 278 | from MaKaC.webinterface.rh.collaboration import RCCollaborationAdmin, RCCollaborationPluginAdmin |
|---|
| 279 | vars["UserIsAdmin"] = RCCollaborationAdmin.hasRights(user = self._user) or RCCollaborationPluginAdmin.hasRights(user = self._user, plugins = self._tabPlugins) |
|---|
| 280 | |
|---|
| 281 | singleBookingForms = {} |
|---|
| 282 | multipleBookingForms = {} |
|---|
| 283 | JSCodes = {} |
|---|
| 284 | canBeNotified = {} |
|---|
| 285 | |
|---|
| 286 | for plugin in singleBookingPlugins: |
|---|
| 287 | pluginName = plugin.getName() |
|---|
| 288 | templateClass = CollaborationTools.getTemplateClass(pluginName, "WNewBookingForm") |
|---|
| 289 | singleBookingForms[pluginName] = templateClass(self._conf, pluginName, self._user).getHTML() |
|---|
| 290 | |
|---|
| 291 | for plugin in multipleBookingPlugins: |
|---|
| 292 | pluginName = plugin.getName() |
|---|
| 293 | templateClass = CollaborationTools.getTemplateClass(pluginName, "WNewBookingForm") |
|---|
| 294 | multipleBookingForms[pluginName] = templateClass(self._conf, pluginName, self._user).getHTML() |
|---|
| 295 | |
|---|
| 296 | for plugin in plugins: |
|---|
| 297 | pluginName = plugin.getName() |
|---|
| 298 | |
|---|
| 299 | templateClass = CollaborationTools.getTemplateClass(pluginName, "WMain") |
|---|
| 300 | JSCodes[pluginName] = templateClass(pluginName, self._conf).getHTML() |
|---|
| 301 | |
|---|
| 302 | bookingClass = CollaborationTools.getCSBookingClass(pluginName) |
|---|
| 303 | canBeNotified[pluginName] = bookingClass._canBeNotifiedOfEventDateChanges |
|---|
| 304 | |
|---|
| 305 | vars["SingleBookingForms"] = singleBookingForms |
|---|
| 306 | vars["MultipleBookingForms"] = multipleBookingForms |
|---|
| 307 | vars["JSCodes"] = JSCodes |
|---|
| 308 | vars["CanBeNotified"] = canBeNotified |
|---|
| 309 | |
|---|
| 310 | return vars |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | class WPConfModifCollaborationProtection( WPConfModifCSBase ): |
|---|
| 314 | |
|---|
| 315 | def __init__(self, rh, conf): |
|---|
| 316 | """ Constructor |
|---|
| 317 | The rh is expected to have the attributes _tabs, _activeTab, _tabPlugins (like RHConfModifCSBookings) |
|---|
| 318 | """ |
|---|
| 319 | WPConfModifCSBase.__init__(self, rh, conf) |
|---|
| 320 | self._user = rh._getUser() |
|---|
| 321 | |
|---|
| 322 | def _getPageContent( self, params ): |
|---|
| 323 | if len(self._tabNames) > 0: |
|---|
| 324 | self._createTabCtrl() |
|---|
| 325 | wc = WConfModifCollaborationProtection( self._conf, self._user ) |
|---|
| 326 | return wcomponents.WTabControl( self._tabCtrl, self._getAW() ).getHTML( wc.getHTML({}) ) |
|---|
| 327 | else: |
|---|
| 328 | return _("No available plugins, or no active plugins") |
|---|
| 329 | |
|---|
| 330 | class WConfModifCollaborationProtection( wcomponents.WTemplated ): |
|---|
| 331 | |
|---|
| 332 | def __init__( self, conference, user ): |
|---|
| 333 | self._conf = conference |
|---|
| 334 | self._user = user |
|---|
| 335 | |
|---|
| 336 | def getVars( self ): |
|---|
| 337 | vars = wcomponents.WTemplated.getVars( self ) |
|---|
| 338 | vars["Conference"] = self._conf |
|---|
| 339 | vars["CSBM"] = self._conf.getCSBookingManager() |
|---|
| 340 | vars["Favorites"] = DictPickler.pickle(self._user.getPersonalInfo().getBasket().getUsers()) |
|---|
| 341 | return vars |
|---|
| 342 | |
|---|
| 343 | ################################################### Event Display pages ############################################### |
|---|
| 344 | class WPCollaborationDisplay( WPConferenceDefaultDisplayBase ): |
|---|
| 345 | |
|---|
| 346 | def _defineSectionMenu( self ): |
|---|
| 347 | WPConferenceDefaultDisplayBase._defineSectionMenu(self) |
|---|
| 348 | self._sectionMenu.setCurrentItem(self._collaborationOpt) |
|---|
| 349 | |
|---|
| 350 | def _getBody( self, params ): |
|---|
| 351 | |
|---|
| 352 | wc = WCollaborationDisplay( self._getAW(), self._conf ) |
|---|
| 353 | return wc.getHTML() |
|---|
| 354 | |
|---|
| 355 | class WCollaborationDisplay( wcomponents.WTemplated ): |
|---|
| 356 | |
|---|
| 357 | def __init__(self, aw, conference): |
|---|
| 358 | wcomponents.WTemplated.__init__(self) |
|---|
| 359 | self._conf = conference |
|---|
| 360 | self._tz = DisplayTZ(aw, conference).getDisplayTZ() |
|---|
| 361 | |
|---|
| 362 | def getVars(self): |
|---|
| 363 | vars = wcomponents.WTemplated.getVars( self ) |
|---|
| 364 | |
|---|
| 365 | csbm = self._conf.getCSBookingManager() |
|---|
| 366 | pluginNames = csbm.getEventDisplayPlugins() |
|---|
| 367 | bookings = csbm.getBookingList(filterByType = pluginNames, notify = True, onlyPublic = True) |
|---|
| 368 | bookings.sort(key = lambda b: b.getStartDate()) |
|---|
| 369 | |
|---|
| 370 | ongoingBookings = [] |
|---|
| 371 | scheduledBookings = {} #date, list of bookings |
|---|
| 372 | |
|---|
| 373 | for b in bookings: |
|---|
| 374 | if b.canBeStarted(): |
|---|
| 375 | ongoingBookings.append(b) |
|---|
| 376 | if b.getAdjustedStartDate('UTC') > nowutc(): |
|---|
| 377 | scheduledBookings.setdefault(b.getAdjustedStartDate(self._tz).date(), []).append(b) |
|---|
| 378 | |
|---|
| 379 | keys = scheduledBookings.keys() |
|---|
| 380 | keys.sort() |
|---|
| 381 | scheduledBookings = [(date, scheduledBookings[date]) for date in keys] |
|---|
| 382 | |
|---|
| 383 | vars["OngoingBookings"] = ongoingBookings |
|---|
| 384 | vars["ScheduledBookings"] = scheduledBookings |
|---|
| 385 | vars["Timezone"] = self._tz |
|---|
| 386 | |
|---|
| 387 | return vars |
|---|