[7193] | 1 | ## $Id: configuration.py 11949 2014-11-13 14:40:27Z 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 |
---|
[11949] | 24 | from waeup.ikoba.interfaces import ( |
---|
[6918] | 25 | ISessionConfiguration, IConfigurationContainer, ISessionConfigurationAdd, |
---|
[11947] | 26 | application_sessions_vocab) |
---|
[11949] | 27 | from waeup.ikoba.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') |
---|
[11947] | 43 | code = unicode(sessionconfiguration.application_session) |
---|
[6916] | 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): |
---|
[11947] | 57 | return application_sessions_vocab.getTerm(self.application_session).title |
---|
[6918] | 58 | |
---|
[6916] | 59 | SessionConfiguration = attrs_to_fields(SessionConfiguration) |
---|
| 60 | |
---|
| 61 | class SessionConfigurationFactory(grok.GlobalUtility): |
---|
| 62 | """A factory for session configuration objects. |
---|
| 63 | """ |
---|
| 64 | grok.implements(IFactory) |
---|
| 65 | grok.name(u'waeup.SessionConfiguration') |
---|
| 66 | title = u"Create a new session configuration object.", |
---|
| 67 | description = u"This factory instantiates new session configurations." |
---|
| 68 | |
---|
| 69 | def __call__(self, *args, **kw): |
---|
| 70 | return SessionConfiguration(*args, **kw) |
---|
| 71 | |
---|
| 72 | def getInterfaces(self): |
---|
[7314] | 73 | return implementedBy(SessionConfiguration) |
---|