[7193] | 1 | ## $Id: configuration.py 13118 2015-06-30 07:14:17Z henrik $ |
---|
| 2 | ## |
---|
[6907] | 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 | """ |
---|
[11477] | 19 | Components for portal configuration. |
---|
[6907] | 20 | """ |
---|
| 21 | import grok |
---|
[6916] | 22 | from zope.component.interfaces import IFactory |
---|
[6920] | 23 | from zope.interface import implementedBy |
---|
[7811] | 24 | from waeup.kofa.interfaces import ( |
---|
[6918] | 25 | ISessionConfiguration, IConfigurationContainer, ISessionConfigurationAdd, |
---|
| 26 | academic_sessions_vocab) |
---|
[7811] | 27 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[6907] | 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( |
---|
[7314] | 41 | 'ConfigurationContainers contain only ' |
---|
| 42 | 'ISessionConfiguration instances') |
---|
[6916] | 43 | code = unicode(sessionconfiguration.academic_session) |
---|
| 44 | self[code] = sessionconfiguration |
---|
[6907] | 45 | return |
---|
| 46 | |
---|
| 47 | ConfigurationContainer = attrs_to_fields(ConfigurationContainer) |
---|
[6916] | 48 | |
---|
| 49 | class SessionConfiguration(grok.Model): |
---|
| 50 | """ |
---|
| 51 | Session configuration model |
---|
| 52 | """ |
---|
| 53 | |
---|
| 54 | grok.implements(ISessionConfiguration, ISessionConfigurationAdd) |
---|
| 55 | |
---|
[6918] | 56 | def getSessionString(self): |
---|
[13118] | 57 | """Return the session string from the vocabulary. |
---|
| 58 | """ |
---|
[6918] | 59 | return academic_sessions_vocab.getTerm(self.academic_session).title |
---|
| 60 | |
---|
[6916] | 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): |
---|
[7314] | 75 | return implementedBy(SessionConfiguration) |
---|