source: main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/studylevel.py @ 9103

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

Replace getStudent method by a 'student' attribute.

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