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

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

Rename course referrers to certificate courses (according to the discussion long time ago).

Edit some button labels and titles.

Move code from view to content components.

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