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

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

Reorganize ICourseTicket. Add ICourseTicketImport which validates a new field called level_session.

Customize checkConversion of CourseTicketProcessor?:
If level_session is provided in row the importer checks if
the parent studylevel exists and if its level_session
attribute corresponds with the expected value in row. The error message
then tells us why course result import fails.

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