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

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

Add SessionConfigurationManageFormPage? and SessionConfigurationBreadcrumb?.

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