1 | ## $Id: configuration.py 13118 2015-06-30 07:14:17Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """ |
---|
19 | Components for portal configuration. |
---|
20 | """ |
---|
21 | import grok |
---|
22 | from zope.component.interfaces import IFactory |
---|
23 | from zope.interface import implementedBy |
---|
24 | from waeup.kofa.interfaces import ( |
---|
25 | ISessionConfiguration, IConfigurationContainer, ISessionConfigurationAdd, |
---|
26 | academic_sessions_vocab) |
---|
27 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
28 | |
---|
29 | class ConfigurationContainer(grok.Container): |
---|
30 | """ |
---|
31 | The node containing the session configuration models |
---|
32 | """ |
---|
33 | |
---|
34 | grok.implements(IConfigurationContainer) |
---|
35 | |
---|
36 | def addSessionConfiguration(self, sessionconfiguration): |
---|
37 | """Add a session configuration object. |
---|
38 | """ |
---|
39 | if not ISessionConfiguration.providedBy(sessionconfiguration): |
---|
40 | raise TypeError( |
---|
41 | 'ConfigurationContainers contain only ' |
---|
42 | 'ISessionConfiguration instances') |
---|
43 | code = unicode(sessionconfiguration.academic_session) |
---|
44 | self[code] = sessionconfiguration |
---|
45 | return |
---|
46 | |
---|
47 | ConfigurationContainer = attrs_to_fields(ConfigurationContainer) |
---|
48 | |
---|
49 | class SessionConfiguration(grok.Model): |
---|
50 | """ |
---|
51 | Session configuration model |
---|
52 | """ |
---|
53 | |
---|
54 | grok.implements(ISessionConfiguration, ISessionConfigurationAdd) |
---|
55 | |
---|
56 | def getSessionString(self): |
---|
57 | """Return the session string from the vocabulary. |
---|
58 | """ |
---|
59 | return academic_sessions_vocab.getTerm(self.academic_session).title |
---|
60 | |
---|
61 | SessionConfiguration = attrs_to_fields(SessionConfiguration) |
---|
62 | |
---|
63 | class SessionConfigurationFactory(grok.GlobalUtility): |
---|
64 | """A factory for session configuration objects. |
---|
65 | """ |
---|
66 | grok.implements(IFactory) |
---|
67 | grok.name(u'waeup.SessionConfiguration') |
---|
68 | title = u"Create a new session configuration object.", |
---|
69 | description = u"This factory instantiates new session configurations." |
---|
70 | |
---|
71 | def __call__(self, *args, **kw): |
---|
72 | return SessionConfiguration(*args, **kw) |
---|
73 | |
---|
74 | def getInterfaces(self): |
---|
75 | return implementedBy(SessionConfiguration) |
---|