Remove the old scheduler
[cds-indico.git] / indico / modules / base.py
blob9a8a93dd8c35e7092372b4b3eeda30ca3cbb5157
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 """This file contain the definition of those classes which implement the
18 access to the objects in the DB related to "modules". "modules" is in the root
19 of the DB and holds a tree with Holders for different modules apart from categories,
20 conferences, and so.
21 The system will fetch and add objects to the collections (or holders) through these
22 classes that interact directly with the persistence layer and do the necessary operations
23 behind to ensure the persistence.
24 """
26 from MaKaC.common.ObjectHolders import ObjectHolder
27 from MaKaC.errors import MaKaCError
28 from persistent import Persistent
31 class ModuleHolder( ObjectHolder ):
32 """ Specialised ObjectHolder class which provides a wrapper for collections
33 based in a Catalog for indexing the objects. It allows to index some
34 declared attributes of the stored objects and then perform SQL-like
35 queries
36 """
37 idxName = "modules"
38 counterName = "MODULES"
39 _availableModules = None
41 def __init__(self):
42 ObjectHolder.__init__(self)
43 # These imports are done like this in order to avoid circular imports problems.
44 from indico.modules import news
45 from indico.modules import cssTpls
46 from indico.modules import upcoming
48 ModuleHolder._availableModules = {
49 news.NewsModule.id: news.NewsModule,
50 cssTpls.CssTplsModule.id: cssTpls.CssTplsModule,
51 upcoming.UpcomingEventsModule.id: upcoming.UpcomingEventsModule,
54 def _newId( self ):
55 id = ObjectHolder._newId( self )
56 return "%s"%id
58 def destroyById(self, moduleId):
59 del self._getIdx()[str(moduleId)]
61 def getById(self, moduleId):
62 """returns an object from the index which id corresponds to the one
63 which is specified.
64 """
66 if type(moduleId) is int:
67 moduleId = str(moduleId)
68 if self._getIdx().has_key(str(moduleId)):
69 return self._getIdx()[str(moduleId)]
70 elif self._availableModules.has_key(moduleId):
71 newmod=self._availableModules[moduleId]()
72 self.add(newmod)
73 return newmod
74 else:
75 raise MaKaCError( ("Module id %s does not exist") % str(moduleId) )
78 class Module(Persistent):
79 """
80 This class represents a general module that it is stored in the database.
81 A module class is a way to access the main data for a general Indico module.
82 A module could be news management, plugins management, etc and anything not
83 related to Indico settings (HelperMaKaCInfo) categories and conferences.
84 """
86 id = ""
88 def getId(self):
89 return self.id
91 def setId(self, id):
92 self.id = id
93 return self.id
95 @classmethod
96 def destroyDBInstance(cls):
97 return ModuleHolder().destroyById(cls.id)
99 @classmethod
100 def getDBInstance(cls):
102 Returns the module instance that is stored in the database
104 return ModuleHolder().getById(cls.id)