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,
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.
26 from MaKaC
.common
.ObjectHolders
import ObjectHolder
27 from MaKaC
.errors
import MaKaCError
28 from MaKaC
.i18n
import _
29 from persistent
import Persistent
32 class ModuleHolder( ObjectHolder
):
33 """ Specialised ObjectHolder class which provides a wrapper for collections
34 based in a Catalog for indexing the objects. It allows to index some
35 declared attributes of the stored objects and then perform SQL-like
39 counterName
= "MODULES"
40 _availableModules
= None
43 ObjectHolder
.__init
__(self
)
44 # These imports are done like this in order to avoid circular imports problems.
45 from indico
.modules
import news
46 from indico
.modules
import cssTpls
47 from indico
.modules
import upcoming
48 from indico
.modules
import scheduler
50 ModuleHolder
._availableModules
= {
51 news
.NewsModule
.id : news
.NewsModule
,
52 cssTpls
.CssTplsModule
.id : cssTpls
.CssTplsModule
,
53 upcoming
.UpcomingEventsModule
.id : upcoming
.UpcomingEventsModule
,
54 scheduler
.SchedulerModule
.id : scheduler
.SchedulerModule
58 id = ObjectHolder
._newId
( self
)
61 def destroyById(self
, moduleId
):
62 del self
._getIdx
()[str(moduleId
)]
64 def getById(self
, moduleId
):
65 """returns an object from the index which id corresponds to the one
69 if type(moduleId
) is int:
70 moduleId
= str(moduleId
)
71 if self
._getIdx
().has_key(str(moduleId
)):
72 return self
._getIdx
()[str(moduleId
)]
73 elif self
._availableModules
.has_key(moduleId
):
74 newmod
=self
._availableModules
[moduleId
]()
78 raise MaKaCError( ("Module id %s does not exist") % str(moduleId
) )
81 class Module(Persistent
):
83 This class represents a general module that it is stored in the database.
84 A module class is a way to access the main data for a general Indico module.
85 A module could be news management, plugins management, etc and anything not
86 related to Indico settings (HelperMaKaCInfo) categories and conferences.
99 def destroyDBInstance(cls
):
100 return ModuleHolder().destroyById(cls
.id)
103 def getDBInstance(cls
):
105 Returns the module instance that is stored in the database
107 return ModuleHolder().getById(cls
.id)