source: main/waeup.sirp/trunk/src/waeup/sirp/configuration.py @ 7259

Last change on this file since 7259 was 7193, checked in by Henrik Bettermann, 13 years ago

More copyright adjustments.

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1## $Id: configuration.py 7193 2011-11-25 07:21:29Z 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"""
19Containers for session configuration objects.
20"""
21import grok
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from waeup.sirp.interfaces import (
25    ISessionConfiguration, IConfigurationContainer, ISessionConfigurationAdd,
26    academic_sessions_vocab)
27from waeup.sirp.utils.helpers import attrs_to_fields
28
29class 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 ISessionConfiguration instances')
42        code = unicode(sessionconfiguration.academic_session)
43        self[code] = sessionconfiguration
44        return
45
46ConfigurationContainer = attrs_to_fields(ConfigurationContainer)
47
48class SessionConfiguration(grok.Model):
49    """
50    Session configuration model
51    """
52
53    grok.implements(ISessionConfiguration, ISessionConfigurationAdd)
54
55    def getSessionString(self):
56        return academic_sessions_vocab.getTerm(self.academic_session).title
57
58SessionConfiguration = attrs_to_fields(SessionConfiguration)
59
60class SessionConfigurationFactory(grok.GlobalUtility):
61    """A factory for session configuration objects.
62    """
63    grok.implements(IFactory)
64    grok.name(u'waeup.SessionConfiguration')
65    title = u"Create a new session configuration object.",
66    description = u"This factory instantiates new session configurations."
67
68    def __call__(self, *args, **kw):
69        return SessionConfiguration(*args, **kw)
70
71    def getInterfaces(self):
72        return implementedBy(SessionConfiguration)
Note: See TracBrowser for help on using the repository browser.