[FIX] Error reports
[cds-indico.git] / indico / MaKaC / webinterface / webFactoryRegistry.py
blob15befe70c5be1b2a39bb71a658af3cc9ef65cb66
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.
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.
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.
21 from BTrees import OOBTree
22 import MaKaC.webinterface.simple_event as simple_event
23 import MaKaC.webinterface.meeting as meeting
24 from MaKaC.common import DBMgr
27 class WebFactoryRegistry:
28 """
29 """
31 def __init__( self ):
32 self._initFactoryRegistry()
33 self._confRegistry = None
35 def _initFactoryRegistry( self ):
36 self._factoryRegistry = {}
37 self._factoryRegistry[ simple_event.WebFactory.getId() ] = simple_event.WebFactory
38 self._factoryRegistry[ meeting.WebFactory.getId() ] = meeting.WebFactory
40 def _getConfRegistry( self ):
41 if not self._confRegistry:
42 db_root = DBMgr.getInstance().getDBConnection().root()
43 if db_root.has_key( "webfactoryregistry" ):
44 self._confRegistry = db_root["webfactoryregistry"]
45 else:
46 self._confRegistry = OOBTree.OOBTree()
47 db_root["webfactoryregistry"] = self._confRegistry
48 return self._confRegistry
50 def _getModuleFactory( self, name ):
51 comp = __import__( name )
52 for compName in name.split(".")[1:]:
53 comp = getattr( comp, compName )
54 return getattr( comp, "WebFactory" )
56 def registerFactory( self, conference, factory ):
57 """Associates a given conference with a certain webfactory
58 """
59 self._getConfRegistry()[ conference.getId() ] = factory
61 def getFactory( self, conference ):
62 """Gives back the webfactory associated with a given conference or None
63 if no association exists
64 """
65 try:
66 if self._getConfRegistry().has_key( conference.getId() ):
67 return self._getConfRegistry()[ conference.getId() ]
68 except:
69 pass
70 return None
72 def getFactoryById( self, id):
73 """Gives back the web factory class corresponding to the specified id
74 """
75 id = id.strip().lower()
76 return self._factoryRegistry.get( id, None )
78 def getFactoryList( self ):
79 """Returns a list containing all the factories in the registry
80 """
81 return self._factoryRegistry.values()