| 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 | import os |
|---|
| 22 | from persistent import Persistent |
|---|
| 23 | from BTrees import OOBTree |
|---|
| 24 | from db import DBMgr |
|---|
| 25 | from Configuration import Config |
|---|
| 26 | |
|---|
| 27 | #from MaKaC.common.logger import Logger |
|---|
| 28 | |
|---|
| 29 | #the singleton pattern should be applied to this class to ensure that it is |
|---|
| 30 | # unique, but as Extended classes seem not to support classmethods it will |
|---|
| 31 | # be done by a helper class. To be migrated when the ZODB4 is released |
|---|
| 32 | class MaKaCInfo(Persistent): |
|---|
| 33 | """Holds and manages general information and data concerning each system |
|---|
| 34 | """ |
|---|
| 35 | |
|---|
| 36 | def __init__( self ): |
|---|
| 37 | # server description fields |
|---|
| 38 | self._title = "" |
|---|
| 39 | self._organisation = "" |
|---|
| 40 | self._supportEmail = "" |
|---|
| 41 | self._publicSupportEmail = "" |
|---|
| 42 | self._noReplyEmail = "" |
|---|
| 43 | self._city = "" |
|---|
| 44 | self._country = "" |
|---|
| 45 | self._lang = "en_GB" |
|---|
| 46 | self._tz = "" |
|---|
| 47 | |
|---|
| 48 | # Account-related features |
|---|
| 49 | self._authorisedAccountCreation = True |
|---|
| 50 | self._notifyAccountCreation = False |
|---|
| 51 | self._moderateAccountCreation = False |
|---|
| 52 | self._moderators = [] |
|---|
| 53 | |
|---|
| 54 | # Room booking related |
|---|
| 55 | self._roomBookingModuleActive = False |
|---|
| 56 | |
|---|
| 57 | # Global poster/badge templates |
|---|
| 58 | self._defaultConference = None |
|---|
| 59 | |
|---|
| 60 | # News management |
|---|
| 61 | self._news = "" |
|---|
| 62 | |
|---|
| 63 | # special features |
|---|
| 64 | self._cacheActive = False |
|---|
| 65 | self._newsActive = False |
|---|
| 66 | self._debugActive = False |
|---|
| 67 | |
|---|
| 68 | # template set |
|---|
| 69 | self._defaultTemplateSet = None |
|---|
| 70 | |
|---|
| 71 | # Define if Indico use a proxy (load balancing) |
|---|
| 72 | self. _proxy = False |
|---|
| 73 | # Define the volume used in archiving: |
|---|
| 74 | # e.g. /afs/cern.ch/project/indico/XXXX/2008/... |
|---|
| 75 | # XXXX will be replaced by self._archivingVolume |
|---|
| 76 | # if self._archivingVolume is empty the path would be: |
|---|
| 77 | # /afs/cern.ch/project/indico/2008/... |
|---|
| 78 | self._archivingVolume = "" |
|---|
| 79 | |
|---|
| 80 | # list of IPs that can access the private OAI gateway |
|---|
| 81 | self._oaiPrivateHarvesterList = [] |
|---|
| 82 | |
|---|
| 83 | # list of IPs that can access the private OAI gateway |
|---|
| 84 | self._oaiPrivateHarvesterList = [] |
|---|
| 85 | |
|---|
| 86 | # Event display style manager |
|---|
| 87 | self._styleMgr = StyleManager() |
|---|
| 88 | |
|---|
| 89 | def getStyleManager( self ): |
|---|
| 90 | try: |
|---|
| 91 | return self._styleMgr |
|---|
| 92 | except: |
|---|
| 93 | self._styleMgr = StyleManager() |
|---|
| 94 | return self._styleMgr |
|---|
| 95 | |
|---|
| 96 | def isDebugActive( self ): |
|---|
| 97 | if hasattr( self, "_debugActive" ): |
|---|
| 98 | return self._debugActive |
|---|
| 99 | else: |
|---|
| 100 | self._debugActive = False |
|---|
| 101 | return False |
|---|
| 102 | |
|---|
| 103 | def setDebugActive( self, bool=True ): |
|---|
| 104 | self._debugActive = bool |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | def getNews( self ): |
|---|
| 108 | try: |
|---|
| 109 | return self._news |
|---|
| 110 | except: |
|---|
| 111 | self._news = "" |
|---|
| 112 | return "" |
|---|
| 113 | |
|---|
| 114 | def setNews( self, news ): |
|---|
| 115 | self._news = news |
|---|
| 116 | |
|---|
| 117 | def getModerators( self ): |
|---|
| 118 | try: |
|---|
| 119 | return self._moderators |
|---|
| 120 | except: |
|---|
| 121 | self._moderators = [] |
|---|
| 122 | return self._moderators |
|---|
| 123 | |
|---|
| 124 | def addModerator( self, av ): |
|---|
| 125 | if av not in self.getModerators(): |
|---|
| 126 | self._moderators.append(av) |
|---|
| 127 | self._p_changed=1 |
|---|
| 128 | |
|---|
| 129 | def removeModerator( self, av ): |
|---|
| 130 | if av in self.getModerators(): |
|---|
| 131 | self._moderators.remove( av ) |
|---|
| 132 | self._p_changed=1 |
|---|
| 133 | |
|---|
| 134 | def isModerator( self, av ): |
|---|
| 135 | if av in self.getModerators(): |
|---|
| 136 | return True |
|---|
| 137 | else: |
|---|
| 138 | return False |
|---|
| 139 | |
|---|
| 140 | def getAuthorisedAccountCreation( self ): |
|---|
| 141 | try: |
|---|
| 142 | return self._authorisedAccountCreation |
|---|
| 143 | except: |
|---|
| 144 | self.setAuthorisedAccountCreation() |
|---|
| 145 | return self._authorisedAccountCreation |
|---|
| 146 | |
|---|
| 147 | def setAuthorisedAccountCreation( self, flag=True ): |
|---|
| 148 | self._authorisedAccountCreation = flag |
|---|
| 149 | |
|---|
| 150 | def getNotifyAccountCreation( self ): |
|---|
| 151 | try: |
|---|
| 152 | return self._notifyAccountCreation |
|---|
| 153 | except: |
|---|
| 154 | self.setNotifyAccountCreation() |
|---|
| 155 | return self._notifyAccountCreation |
|---|
| 156 | |
|---|
| 157 | def setNotifyAccountCreation( self, flag=False ): |
|---|
| 158 | self._notifyAccountCreation = flag |
|---|
| 159 | |
|---|
| 160 | def getModerateAccountCreation( self ): |
|---|
| 161 | try: |
|---|
| 162 | return self._moderateAccountCreation |
|---|
| 163 | except: |
|---|
| 164 | self.setModerateAccountCreation() |
|---|
| 165 | return self._moderateAccountCreation |
|---|
| 166 | |
|---|
| 167 | def setModerateAccountCreation( self, flag=False ): |
|---|
| 168 | self._moderateAccountCreation = flag |
|---|
| 169 | |
|---|
| 170 | def getTitle( self ): |
|---|
| 171 | return self._title |
|---|
| 172 | |
|---|
| 173 | def isCacheActive( self ): |
|---|
| 174 | if hasattr( self, "_cacheActive" ): |
|---|
| 175 | return self._cacheActive |
|---|
| 176 | else: |
|---|
| 177 | self._cacheActive = False |
|---|
| 178 | return False |
|---|
| 179 | |
|---|
| 180 | def setCacheActive( self, bool=True ): |
|---|
| 181 | self._cacheActive = bool |
|---|
| 182 | |
|---|
| 183 | def isNewsActive( self ): |
|---|
| 184 | if hasattr( self, "_newsActive" ): |
|---|
| 185 | return self._newsActive |
|---|
| 186 | else: |
|---|
| 187 | self._newsActive = False |
|---|
| 188 | return False |
|---|
| 189 | |
|---|
| 190 | def setNewsActive( self, bool=True ): |
|---|
| 191 | self._newsActive = bool |
|---|
| 192 | |
|---|
| 193 | def isHighlightActive ( self ): |
|---|
| 194 | if hasattr( self, "_highlightActive" ): |
|---|
| 195 | return self._highlightActive |
|---|
| 196 | else: |
|---|
| 197 | self._highlightActive = False |
|---|
| 198 | return False |
|---|
| 199 | |
|---|
| 200 | def setHighlightActive (self, bool=True ): |
|---|
| 201 | self._highlightActive = bool |
|---|
| 202 | |
|---|
| 203 | def setTitle( self, newTitle ): |
|---|
| 204 | self._title = newTitle.strip() |
|---|
| 205 | |
|---|
| 206 | def getOrganisation( self ): |
|---|
| 207 | return self._organisation |
|---|
| 208 | |
|---|
| 209 | def getAffiliation( self ): |
|---|
| 210 | return self._organisation |
|---|
| 211 | |
|---|
| 212 | def setOrganisation( self, newOrg ): |
|---|
| 213 | self._organisation = newOrg.strip() |
|---|
| 214 | |
|---|
| 215 | def getSupportEmail( self ): |
|---|
| 216 | if not hasattr( self, "_supportEmail" ) or (self._supportEmail == "" and Config.getInstance().getSupportEmail() != ""): |
|---|
| 217 | self._supportEmail = Config.getInstance().getSupportEmail() |
|---|
| 218 | return self._supportEmail |
|---|
| 219 | |
|---|
| 220 | def setSupportEmail( self, newEmail ): |
|---|
| 221 | self._supportEmail = newEmail.strip() |
|---|
| 222 | |
|---|
| 223 | def getPublicSupportEmail( self ): |
|---|
| 224 | if not hasattr( self, "_publicSupportEmail" ) or (self._publicSupportEmail == "" and Config.getInstance().getPublicSupportEmail() != ""): |
|---|
| 225 | self._publicSupportEmail = Config.getInstance().getPublicSupportEmail() |
|---|
| 226 | return self._publicSupportEmail |
|---|
| 227 | |
|---|
| 228 | def setPublicSupportEmail( self, newEmail ): |
|---|
| 229 | self._publicSupportEmail = newEmail.strip() |
|---|
| 230 | |
|---|
| 231 | def getNoReplyEmail( self, returnSupport=False ): |
|---|
| 232 | if not hasattr( self, "_noReplyEmail" ) or (self._noReplyEmail == "" and Config.getInstance().getNoReplyEmail() != ""): |
|---|
| 233 | self._noReplyEmail = Config.getInstance().getNoReplyEmail() |
|---|
| 234 | |
|---|
| 235 | if self._noReplyEmail != "": |
|---|
| 236 | return self._noReplyEmail |
|---|
| 237 | elif returnSupport: |
|---|
| 238 | return self.getSupportEmail() |
|---|
| 239 | else: |
|---|
| 240 | return "" |
|---|
| 241 | |
|---|
| 242 | return self._noReplyEmail |
|---|
| 243 | |
|---|
| 244 | def setNoReplyEmail( self, newEmail ): |
|---|
| 245 | self._noReplyEmail = newEmail.strip() |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | def getCity( self ): |
|---|
| 249 | return self._city |
|---|
| 250 | |
|---|
| 251 | def setCity( self, newCity ): |
|---|
| 252 | self._city = newCity.strip() |
|---|
| 253 | |
|---|
| 254 | def getCountry( self ): |
|---|
| 255 | return self._country |
|---|
| 256 | |
|---|
| 257 | def setCountry( self, newCountry ): |
|---|
| 258 | self._country = newCountry |
|---|
| 259 | |
|---|
| 260 | def getTimezone( self ): |
|---|
| 261 | try: |
|---|
| 262 | return self._timezone |
|---|
| 263 | except: |
|---|
| 264 | self.setTimezone('UTC') |
|---|
| 265 | return 'UTC' |
|---|
| 266 | |
|---|
| 267 | def setTimezone( self, tz=None): |
|---|
| 268 | if not tz: |
|---|
| 269 | tz = 'UTC' |
|---|
| 270 | self._timezone = tz |
|---|
| 271 | |
|---|
| 272 | def getAdminList( self ): |
|---|
| 273 | from MaKaC.accessControl import AdminList |
|---|
| 274 | return AdminList.getInstance() |
|---|
| 275 | |
|---|
| 276 | def getAdminEmails( self ): |
|---|
| 277 | emails = [] |
|---|
| 278 | for admin in self.getAdminList().getList(): |
|---|
| 279 | emails.append(admin.getEmail()) |
|---|
| 280 | return emails |
|---|
| 281 | |
|---|
| 282 | # === ROOM BOOKING RELATED =============================================== |
|---|
| 283 | |
|---|
| 284 | def getRoomBookingModuleActive( self ): |
|---|
| 285 | try: |
|---|
| 286 | return self._roomBookingModuleActive |
|---|
| 287 | except: |
|---|
| 288 | self.setRoomBookingModuleActive() |
|---|
| 289 | return self._roomBookingModuleActive |
|---|
| 290 | |
|---|
| 291 | def setRoomBookingModuleActive( self, active = False ): |
|---|
| 292 | self._roomBookingModuleActive = active |
|---|
| 293 | from MaKaC.webinterface.rh.JSContent import RHGetVarsJs |
|---|
| 294 | RHGetVarsJs.removeTmpVarsFile() |
|---|
| 295 | |
|---|
| 296 | # Only for default Indico/ZODB plugin |
|---|
| 297 | def getRoomBookingDBConnectionParams( self ): |
|---|
| 298 | #self._roomBookingStorageParams = ('indicodev.cern.ch', 9676) |
|---|
| 299 | try: |
|---|
| 300 | return self._roomBookingStorageParams |
|---|
| 301 | except: |
|---|
| 302 | self.setRoomBookingDBConnectionParams() |
|---|
| 303 | return self._roomBookingStorageParams |
|---|
| 304 | |
|---|
| 305 | def setRoomBookingDBConnectionParams( self, hostPortTuple = ('localhost', 9676) ): |
|---|
| 306 | self._roomBookingStorageParams = hostPortTuple |
|---|
| 307 | |
|---|
| 308 | # Only for default Indico/ZODB plugin |
|---|
| 309 | def getRoomBookingDBUserName( self ): |
|---|
| 310 | try: |
|---|
| 311 | return self._roomBookingDBUserName |
|---|
| 312 | except: |
|---|
| 313 | self._roomBookingDBUserName = "" |
|---|
| 314 | return self._roomBookingDBUserName |
|---|
| 315 | |
|---|
| 316 | # Only for default Indico/ZODB plugin |
|---|
| 317 | def setRoomBookingDBUserName( self, user = "" ): |
|---|
| 318 | self._roomBookingDBUserName = user |
|---|
| 319 | |
|---|
| 320 | # Only for default Indico/ZODB plugin |
|---|
| 321 | def getRoomBookingDBPassword( self ): |
|---|
| 322 | try: |
|---|
| 323 | return self._roomBookingDBPassword |
|---|
| 324 | except: |
|---|
| 325 | self._roomBookingDBPassword = "" |
|---|
| 326 | return self._roomBookingDBPassword |
|---|
| 327 | |
|---|
| 328 | # Only for default Indico/ZODB plugin |
|---|
| 329 | def setRoomBookingDBPassword( self, password = "" ): |
|---|
| 330 | self._roomBookingDBPassword = password |
|---|
| 331 | |
|---|
| 332 | # Only for default Indico/ZODB plugin |
|---|
| 333 | def getRoomBookingDBRealm( self ): |
|---|
| 334 | try: |
|---|
| 335 | return self._roomBookingDBRealm |
|---|
| 336 | except: |
|---|
| 337 | self._roomBookingDBRealm = "" |
|---|
| 338 | return self._roomBookingDBRealm |
|---|
| 339 | |
|---|
| 340 | # Only for default Indico/ZODB plugin |
|---|
| 341 | def setRoomBookingDBRealm( self, realm = "" ): |
|---|
| 342 | self._roomBookingDBRealm = realm |
|---|
| 343 | |
|---|
| 344 | def getDefaultConference( self ): |
|---|
| 345 | try: |
|---|
| 346 | self._defaultConference |
|---|
| 347 | except AttributeError: |
|---|
| 348 | self._defaultConference = None |
|---|
| 349 | |
|---|
| 350 | return self._defaultConference |
|---|
| 351 | |
|---|
| 352 | def setDefaultConference( self, dConf ): |
|---|
| 353 | self._defaultConference = dConf |
|---|
| 354 | return self._defaultConference |
|---|
| 355 | |
|---|
| 356 | def setProxy(self, proxy): |
|---|
| 357 | self._proxy = proxy |
|---|
| 358 | |
|---|
| 359 | def useProxy(self): |
|---|
| 360 | try: |
|---|
| 361 | return self._proxy |
|---|
| 362 | except: |
|---|
| 363 | self._proxy = False |
|---|
| 364 | return self._proxy |
|---|
| 365 | |
|---|
| 366 | def getDefaultTemplateSet( self ): |
|---|
| 367 | try: |
|---|
| 368 | return self._defaultTemplateSet |
|---|
| 369 | except: |
|---|
| 370 | self._defaultTemplateSet = None |
|---|
| 371 | return None |
|---|
| 372 | |
|---|
| 373 | def setDefaultTemplateSet( self, defTemp ): |
|---|
| 374 | self._defaultTemplateSet = defTemp |
|---|
| 375 | return self._defaultTemplateSet |
|---|
| 376 | |
|---|
| 377 | def getLang( self ): |
|---|
| 378 | try: |
|---|
| 379 | return self._lang |
|---|
| 380 | except: |
|---|
| 381 | self._lang = "en_GB" |
|---|
| 382 | #Logger.get('i18n').warning('No language set in MaKaCInfo... using %s by default' % self._lang) |
|---|
| 383 | return self._lang |
|---|
| 384 | |
|---|
| 385 | def setLang( self, lang ): |
|---|
| 386 | self._lang = lang |
|---|
| 387 | |
|---|
| 388 | def setArchivingVolume(self, volume): |
|---|
| 389 | if isinstance(volume, str): |
|---|
| 390 | self._archivingVolume = volume |
|---|
| 391 | |
|---|
| 392 | def getArchivingVolume(self): |
|---|
| 393 | if not hasattr(self, "_archivingVolume"): |
|---|
| 394 | self._archivingVolume = "" |
|---|
| 395 | return self._archivingVolume |
|---|
| 396 | |
|---|
| 397 | def getOAIPrivateHarvesterList(self): |
|---|
| 398 | """ Returns the list of allowed IPs of harvesters |
|---|
| 399 | for the private OAI gateway """ |
|---|
| 400 | |
|---|
| 401 | try: |
|---|
| 402 | self._oaiPrivateHarvesterList |
|---|
| 403 | except: |
|---|
| 404 | self._oaiPrivateHarvesterList = [] |
|---|
| 405 | return self._oaiPrivateHarvesterList |
|---|
| 406 | |
|---|
| 407 | def setOAIPrivateHarvesterList(self, harvList): |
|---|
| 408 | self._oaiPrivateHarvesterList = harvList |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | class HelperMaKaCInfo: |
|---|
| 412 | """Helper class used for getting and instance of MaKaCInfo. |
|---|
| 413 | It will be migrated into a static method in MaKaCInfo class once the |
|---|
| 414 | ZODB4 is released and the Persistent classes are no longer Extension |
|---|
| 415 | ones. |
|---|
| 416 | """ |
|---|
| 417 | |
|---|
| 418 | def getMaKaCInfoInstance(cls): |
|---|
| 419 | dbmgr = DBMgr.getInstance() |
|---|
| 420 | root = dbmgr.getDBConnection().root() |
|---|
| 421 | try: |
|---|
| 422 | minfo = root["MaKaCInfo"]["main"] |
|---|
| 423 | except KeyError, e: |
|---|
| 424 | minfo = MaKaCInfo() |
|---|
| 425 | root["MaKaCInfo"] = OOBTree.OOBTree() |
|---|
| 426 | root["MaKaCInfo"]["main"] = minfo |
|---|
| 427 | |
|---|
| 428 | return minfo |
|---|
| 429 | |
|---|
| 430 | getMaKaCInfoInstance = classmethod( getMaKaCInfoInstance ) |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | class StyleManager(Persistent): |
|---|
| 434 | """This class manages the styles used by the server for the display |
|---|
| 435 | of events timetables |
|---|
| 436 | """ |
|---|
| 437 | |
|---|
| 438 | def __init__( self ): |
|---|
| 439 | self._styles = Config.getInstance().getStyles() |
|---|
| 440 | self._eventStylesheets = Config.getInstance().getEventStylesheets() |
|---|
| 441 | self._defaultEventStylesheet = Config.getInstance().getDefaultEventStylesheet() |
|---|
| 442 | |
|---|
| 443 | def getStyles(self): |
|---|
| 444 | try: |
|---|
| 445 | return self._styles |
|---|
| 446 | except AttributeError: |
|---|
| 447 | self._styles = Config.getInstance().getStyles() |
|---|
| 448 | return self._styles |
|---|
| 449 | |
|---|
| 450 | def setStyles(self, newStyles): |
|---|
| 451 | self._styles = newStyles |
|---|
| 452 | |
|---|
| 453 | def getEventStyles(self): |
|---|
| 454 | """gives back the entire style/event association list. |
|---|
| 455 | """ |
|---|
| 456 | return self._eventStylesheets |
|---|
| 457 | |
|---|
| 458 | def setEventStyles(self, sDict={}): |
|---|
| 459 | self._eventStylesheets = sDict |
|---|
| 460 | |
|---|
| 461 | def getDefaultEventStyles(self): |
|---|
| 462 | """gives back the default styles/event association |
|---|
| 463 | """ |
|---|
| 464 | return self._defaultEventStylesheet |
|---|
| 465 | |
|---|
| 466 | def setDefaultEventStyle(self, sDict={}): |
|---|
| 467 | self._defaultEventStylesheet = sDict |
|---|
| 468 | |
|---|
| 469 | def getDefaultStyleForEventType(self, eventType): |
|---|
| 470 | """gives back the default stylesheet for the given type of event |
|---|
| 471 | """ |
|---|
| 472 | return self._defaultEventStylesheet.get(eventType, "") |
|---|
| 473 | |
|---|
| 474 | def removeStyle(self, styleId, type=""): |
|---|
| 475 | if type == "": |
|---|
| 476 | # style globally removed |
|---|
| 477 | styles = self.getStyles() |
|---|
| 478 | if styles.has_key(styleId): |
|---|
| 479 | del styles[styleId] |
|---|
| 480 | self.setStyles(styles) |
|---|
| 481 | self.removeStyleFromAllTypes(styleId) |
|---|
| 482 | else: |
|---|
| 483 | # style removed only in the type list |
|---|
| 484 | self.removeStyleFromEventType(styleId, type) |
|---|
| 485 | |
|---|
| 486 | def addStyleToEventType( self, style, type ): |
|---|
| 487 | dict = self.getEventStyles() |
|---|
| 488 | styles = dict.get(type,[]) |
|---|
| 489 | if style not in styles: |
|---|
| 490 | styles.append(style) |
|---|
| 491 | dict[type] = styles |
|---|
| 492 | self.setEventStyles(dict) |
|---|
| 493 | |
|---|
| 494 | def removeStyleFromEventType( self, style, type ): |
|---|
| 495 | # style removed only in the type list |
|---|
| 496 | dict = self.getEventStyles() |
|---|
| 497 | styles = dict.get(type,[]) |
|---|
| 498 | defaultStyle = self.getDefaultStyleForEventType(type) |
|---|
| 499 | if style != "" and style in styles: |
|---|
| 500 | styles.remove(style) |
|---|
| 501 | dict[type] = styles |
|---|
| 502 | self.setEventStyles(dict) |
|---|
| 503 | if style.strip() == defaultStyle.strip(): |
|---|
| 504 | if len(styles) > 0: |
|---|
| 505 | newDefaultStyle = styles[0] |
|---|
| 506 | else: |
|---|
| 507 | newDefaultStyle = None |
|---|
| 508 | self.setDefaultStyle( newDefaultStyle, type ) |
|---|
| 509 | |
|---|
| 510 | def setDefaultStyle( self, style, type ): |
|---|
| 511 | if style != "": |
|---|
| 512 | dict = self.getDefaultEventStyles() |
|---|
| 513 | dict[type] = style |
|---|
| 514 | self.setDefaultEventStyle(dict) |
|---|
| 515 | |
|---|
| 516 | def removeStyleFromAllTypes( self, style ): |
|---|
| 517 | for type in ["simple_event", "meeting", "conference"]: |
|---|
| 518 | self.removeStyleFromEventType(style, type) |
|---|
| 519 | |
|---|
| 520 | def getStyleListForEventType(self, eventType): |
|---|
| 521 | """gives back the style list associated to a given type of event. |
|---|
| 522 | If no event was specified it returns the empty list. |
|---|
| 523 | Params: |
|---|
| 524 | type -- unique identifier of the event type |
|---|
| 525 | """ |
|---|
| 526 | return self._eventStylesheets.get(eventType, []) |
|---|
| 527 | |
|---|
| 528 | def isCorrectStyle(self, styleId): |
|---|
| 529 | if styleId not in self._styles: |
|---|
| 530 | return False |
|---|
| 531 | correctCSS = self.existsCSSFile(styleId) or not self.getCSSFilename(styleId) |
|---|
| 532 | return styleId == 'static' or (self.existsTPLFile(styleId) and correctCSS) or (self.existsXSLFile(styleId) and correctCSS) |
|---|
| 533 | |
|---|
| 534 | def getExistingStylesForEventType(self, eventType): |
|---|
| 535 | result = [] |
|---|
| 536 | for style in self.getStyleListForEventType(eventType): |
|---|
| 537 | if self.isCorrectStyle(style): |
|---|
| 538 | result.append(style) |
|---|
| 539 | return result |
|---|
| 540 | |
|---|
| 541 | def getStyleDictForEventType(self, type): |
|---|
| 542 | """gives back the style list associated to a given type of event. |
|---|
| 543 | If no event was specified it returns the empty list. |
|---|
| 544 | Params: |
|---|
| 545 | type -- unique identifier of the event type |
|---|
| 546 | """ |
|---|
| 547 | styles = self.getStyles() |
|---|
| 548 | return dict((styleID, styles[styleID]) for styleID in self._eventStylesheets.get(type, [])) |
|---|
| 549 | |
|---|
| 550 | def getStyleName(self, styleId): |
|---|
| 551 | styles = self.getStyles() |
|---|
| 552 | if styleId in styles: |
|---|
| 553 | return styles[styleId][0] |
|---|
| 554 | else: |
|---|
| 555 | return "" |
|---|
| 556 | |
|---|
| 557 | def getBaseTPLPath(self): |
|---|
| 558 | tplDir = Config.getInstance().getTPLDir() |
|---|
| 559 | return os.path.join(tplDir, "events") |
|---|
| 560 | |
|---|
| 561 | def getBaseXSLPath(self): |
|---|
| 562 | xslDir = Config.getInstance().getStylesheetsDir() |
|---|
| 563 | return os.path.join(xslDir, "events") |
|---|
| 564 | |
|---|
| 565 | def existsTPLFile(self, styleId): |
|---|
| 566 | if styleId.strip() != "": |
|---|
| 567 | tplFile = self.getTemplateFilename(styleId) |
|---|
| 568 | if not tplFile: |
|---|
| 569 | return False |
|---|
| 570 | path = os.path.join(self.getBaseTPLPath(), tplFile) |
|---|
| 571 | if os.path.exists(path): |
|---|
| 572 | return True |
|---|
| 573 | return False |
|---|
| 574 | |
|---|
| 575 | def existsXSLFile(self, styleId): |
|---|
| 576 | if styleId.strip() != "": |
|---|
| 577 | xslFile = self.getTemplateFilename(styleId) |
|---|
| 578 | if not xslFile: |
|---|
| 579 | return False |
|---|
| 580 | path = os.path.join(self.getBaseXSLPath(), xslFile) |
|---|
| 581 | if os.path.exists(path): |
|---|
| 582 | return True |
|---|
| 583 | return False |
|---|
| 584 | |
|---|
| 585 | def getXSLPath(self, styleId): |
|---|
| 586 | if styleId.strip() != "": |
|---|
| 587 | xslFile = self.getTemplateFilename(styleId) |
|---|
| 588 | if not xslFile: |
|---|
| 589 | return False |
|---|
| 590 | path = os.path.join(self.getBaseXSLPath(), xslFile) |
|---|
| 591 | if os.path.exists(path): |
|---|
| 592 | return path |
|---|
| 593 | return None |
|---|
| 594 | |
|---|
| 595 | def getTemplateFilename(self, styleId): |
|---|
| 596 | styles = self.getStyles() |
|---|
| 597 | if styleId in styles: |
|---|
| 598 | fileName = styles[styleId][1] |
|---|
| 599 | return fileName |
|---|
| 600 | else: |
|---|
| 601 | return None |
|---|
| 602 | |
|---|
| 603 | def getBaseCSSPath( self ): |
|---|
| 604 | return os.path.join(Config.getInstance().getHtdocsDir(),"css", "events") |
|---|
| 605 | |
|---|
| 606 | def existsCSSFile(self, styleId): |
|---|
| 607 | if styleId.strip() != "": |
|---|
| 608 | basepath = self.getBaseCSSPath() |
|---|
| 609 | filename = self.getCSSFilename(styleId) |
|---|
| 610 | if not filename: |
|---|
| 611 | return False |
|---|
| 612 | path = os.path.join(basepath, filename) |
|---|
| 613 | if os.path.exists(path): |
|---|
| 614 | return True |
|---|
| 615 | return False |
|---|
| 616 | |
|---|
| 617 | def getCSSFilename( self, stylesheet ): |
|---|
| 618 | if stylesheet.strip() != "" and stylesheet in self._styles: |
|---|
| 619 | return self._styles[stylesheet][2] |
|---|
| 620 | return None |
|---|
| 621 | |
|---|
| 622 | def getXSLStyles(self): |
|---|
| 623 | xslStyles = [] |
|---|
| 624 | for style in self._styles: |
|---|
| 625 | if self._styles[style][1]!= None and self._styles[style][1].endswith(".xsl"): |
|---|
| 626 | xslStyles.append(style) |
|---|
| 627 | return xslStyles |
|---|
| 628 | |
|---|
| 629 | def existsStyle(self, styleId): |
|---|
| 630 | styles = self.getStyles() |
|---|
| 631 | if styleId in styles: |
|---|
| 632 | return True |
|---|
| 633 | else: |
|---|
| 634 | return False |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|