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

Last change on this file since 9253 was 9253, checked in by Henrik Bettermann, 12 years ago

Export always certcode which is very helpful for offline data evaluation. Also add current_level, current_session and is_postgrad to StudentExporter?.

  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1## $Id: studylevel.py 9253 2012-09-28 09:56:23Z 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"""
19Container which holds the data of a student study level
20and contains the course tickets.
21"""
22import grok
23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
25from waeup.kofa.students.interfaces import (
26    IStudentStudyLevel, IStudentNavigation, ICourseTicket)
27from waeup.kofa.utils.helpers import attrs_to_fields
28from waeup.kofa.students.vocabularies import StudyLevelSource
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
39        return
40
41    @property
42    def student(self):
43        try:
44            return self.__parent__.__parent__
45        except AttributeError:
46            return None
47
48    @property
49    def certcode(self):
50        try:
51            return self.__parent__.certificate.code
52        except AttributeError:
53            return None
54
55    @property
56    def number_of_tickets(self):
57        return len(self)
58
59    def writeLogMessage(self, view, message):
60        return self.__parent__.__parent__.writeLogMessage(view, message)
61
62    @property
63    def level_title(self):
64        studylevelsource = StudyLevelSource()
65        return studylevelsource.factory.getTitle(self.__parent__, self.level)
66
67    def addCourseTicket(self, ticket, course):
68        """Add a course ticket object.
69        """
70        if not ICourseTicket.providedBy(ticket):
71            raise TypeError(
72                'StudentStudyLeves contain only ICourseTicket instances')
73        ticket.code = course.code
74        ticket.title = course.title
75        ticket.fcode = course.__parent__.__parent__.__parent__.code
76        ticket.dcode = course.__parent__.__parent__.code
77        ticket.credits = course.credits
78        ticket.passmark = course.passmark
79        ticket.semester = course.semester
80        self[ticket.code] = ticket
81        return
82
83StudentStudyLevel = attrs_to_fields(StudentStudyLevel)
84
85class StudentStudyLevelFactory(grok.GlobalUtility):
86    """A factory for student study levels.
87    """
88    grok.implements(IFactory)
89    grok.name(u'waeup.StudentStudyLevel')
90    title = u"Create a new student study level.",
91    description = u"This factory instantiates new student study level instances."
92
93    def __call__(self, *args, **kw):
94        return StudentStudyLevel()
95
96    def getInterfaces(self):
97        return implementedBy(StudentStudyLevel)
98
99class CourseTicket(grok.Model):
100    """This is a course ticket which allows the
101    student to attend the course. Lecturers will enter scores and more at
102    the end of the term.
103
104    A course ticket contains a copy of the original course and
105    certificate course data. If the courses and/or the referrin certificate
106    courses are removed, the corresponding tickets remain unchanged.
107    So we do not need any event
108    triggered actions on course tickets.
109    """
110    grok.implements(ICourseTicket, IStudentNavigation)
111    grok.provides(ICourseTicket)
112
113    def __init__(self):
114        super(CourseTicket, self).__init__()
115        self.code = None
116        self.title = None
117        self.fcode = None
118        self.dcode = None
119        self.credits = None
120        self.passmark = None
121        self.semester = None
122        return
123
124    @property
125    def student(self):
126        """Get the associated student object.
127        """
128        try:
129            return self.__parent__.__parent__.__parent__
130        except AttributeError:
131            return None
132
133    @property
134    def certcode(self):
135        try:
136            return self.__parent__.__parent__.certificate.code
137        except AttributeError:
138            return None
139
140    def writeLogMessage(self, view, message):
141        return self.__parent__.__parent__.__parent__.writeLogMessage(view, message)
142
143    def getLevel(self):
144        """Returns the id of the level the ticket has been added to.
145        """
146        # XXX: shouldn't that be an attribute?
147        try:
148            return self.__parent__.level
149        except AttributeError:
150            return None
151
152    def getLevelSession(self):
153        """Returns the session of the level the ticket has been added to.
154        """
155        # XXX: shouldn't that be an attribute?
156        try:
157            return self.__parent__.level_session
158        except AttributeError:
159            return None
160
161
162CourseTicket = attrs_to_fields(CourseTicket)
163
164class CourseTicketFactory(grok.GlobalUtility):
165    """A factory for student study levels.
166    """
167    grok.implements(IFactory)
168    grok.name(u'waeup.CourseTicket')
169    title = u"Create a new course ticket.",
170    description = u"This factory instantiates new course ticket instances."
171
172    def __call__(self, *args, **kw):
173        return CourseTicket()
174
175    def getInterfaces(self):
176        return implementedBy(CourseTicket)
Note: See TracBrowser for help on using the repository browser.