source: main/waeup.kofa/trunk/src/waeup/kofa/students/studylevel.py @ 8384

Last change on this file since 8384 was 8338, checked in by uli, 13 years ago

Make study levels more robust.

  • Property svn:keywords set to Id
File size: 4.6 KB
RevLine 
[7191]1## $Id: studylevel.py 8338 2012-05-04 10:46:23Z uli $
2##
[6775]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"""
19Container which holds the data of a student study level
20and contains the course tickets.
21"""
22import grok
[7536]23from zope.component.interfaces import IFactory
[8330]24from zope.interface import implementedBy
[7811]25from waeup.kofa.students.interfaces import (
[6781]26    IStudentStudyLevel, IStudentNavigation, ICourseTicket)
[7811]27from waeup.kofa.utils.helpers import attrs_to_fields
28from waeup.kofa.students.vocabularies import StudyLevelSource
[6775]29
30class StudentStudyLevel(grok.Container):
31    """This is a container for course tickets.
32    """
33    grok.implements(IStudentStudyLevel, IStudentNavigation)
34    grok.provides(IStudentStudyLevel)
35
36    def __init__(self):
37        super(StudentStudyLevel, self).__init__()
38        self.level = None
[6795]39        self.validation_date = None
40        self.validated_by = None
[6775]41        return
42
43    def getStudent(self):
44        return self.__parent__.__parent__
45
46    @property
47    def level_title(self):
48        studylevelsource = StudyLevelSource()
49        return studylevelsource.factory.getTitle(self.__parent__, self.level)
50
[6781]51    def addCourseTicket(self, courseticket):
52        """Add a course ticket object.
53        """
54        if not ICourseTicket.providedBy(courseticket):
55            raise TypeError(
56                'StudentStudyLeves contain only ICourseTicket instances')
[6782]57        self[courseticket.code] = courseticket
[6781]58        return
59
60StudentStudyLevel = attrs_to_fields(StudentStudyLevel)
61
[7536]62class StudentStudyLevelFactory(grok.GlobalUtility):
63    """A factory for student study levels.
64    """
65    grok.implements(IFactory)
66    grok.name(u'waeup.StudentStudyLevel')
67    title = u"Create a new student study level.",
68    description = u"This factory instantiates new student study level instances."
69
70    def __call__(self, *args, **kw):
71        return StudentStudyLevel()
72
73    def getInterfaces(self):
74        return implementedBy(StudentStudyLevel)
75
[6781]76class CourseTicket(grok.Model):
77    """This is a course ticket which allows the
78    student to attend the course. Lecturers will enter scores and more at
79    the end of the term.
[6783]80
81    A course ticket contains a copy of the original course and
82    course referrer data. If the courses and/or their referrers are removed, the
83    corresponding tickets remain unchanged. So we do not need any event
84    triggered actions on course tickets.
[6781]85    """
86    grok.implements(ICourseTicket, IStudentNavigation)
87    grok.provides(ICourseTicket)
88
[6795]89    def __init__(self):
[6781]90        super(CourseTicket, self).__init__()
[6795]91        self.code = None
92        self.title = None
[7304]93        self.fcode = None
94        self.dcode = None
[6795]95        self.credits = None
96        self.passmark = None
97        self.semester = None
[6781]98        return
99
100    def getStudent(self):
[8338]101        """Get the associated student object.
102        """
103        # XXX: shouldn't that be an attribute?
104        try:
105            return self.__parent__.__parent__.__parent__
106        except AttributeError:
107            return None
[6781]108
[7633]109    def getLevel(self):
110        """Returns the id of the level the ticket has been added to.
111        """
[8338]112        # XXX: shouldn't that be an attribute?
113        try:
114            return self.__parent__.level
115        except AttributeError:
116            return None
[7633]117
118    def getLevelSession(self):
119        """Returns the session of the level the ticket has been added to.
120        """
[8338]121        # XXX: shouldn't that be an attribute?
122        try:
123            return self.__parent__.level_session
124        except AttributeError:
125            return None
[7633]126
127
[6782]128CourseTicket = attrs_to_fields(CourseTicket)
[7548]129
130class CourseTicketFactory(grok.GlobalUtility):
131    """A factory for student study levels.
132    """
133    grok.implements(IFactory)
134    grok.name(u'waeup.CourseTicket')
135    title = u"Create a new course ticket.",
136    description = u"This factory instantiates new course ticket instances."
137
138    def __call__(self, *args, **kw):
139        return CourseTicket()
140
141    def getInterfaces(self):
142        return implementedBy(CourseTicket)
Note: See TracBrowser for help on using the repository browser.