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

Last change on this file since 7893 was 7314, checked in by uli, 13 years ago

Shorten overlong lines.

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1## $Id: configuration.py 7314 2011-12-09 10:50:51Z uli $
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 '
42                'ISessionConfiguration instances')
43        code = unicode(sessionconfiguration.academic_session)
44        self[code] = sessionconfiguration
45        return
46
47ConfigurationContainer = attrs_to_fields(ConfigurationContainer)
48
49class SessionConfiguration(grok.Model):
50    """
51    Session configuration model
52    """
53
54    grok.implements(ISessionConfiguration, ISessionConfigurationAdd)
55
56    def getSessionString(self):
57        return academic_sessions_vocab.getTerm(self.academic_session).title
58
59SessionConfiguration = attrs_to_fields(SessionConfiguration)
60
61class 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):
73        return implementedBy(SessionConfiguration)
Note: See TracBrowser for help on using the repository browser.