1 | ## $Id: studylevel.py 8494 2012-05-23 06:36:40Z 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 | """ |
---|
19 | Container which holds the data of a student study level |
---|
20 | and contains the course tickets. |
---|
21 | """ |
---|
22 | import grok |
---|
23 | from zope.component.interfaces import IFactory |
---|
24 | from zope.interface import implementedBy |
---|
25 | from waeup.kofa.students.interfaces import ( |
---|
26 | IStudentStudyLevel, IStudentNavigation, ICourseTicket) |
---|
27 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
28 | from waeup.kofa.students.vocabularies import StudyLevelSource |
---|
29 | |
---|
30 | class 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 | def getStudent(self): |
---|
44 | return getattr(getattr(self, '__parent__', None), '__parent__', None) |
---|
45 | |
---|
46 | @property |
---|
47 | def level_title(self): |
---|
48 | studylevelsource = StudyLevelSource() |
---|
49 | return studylevelsource.factory.getTitle(self.__parent__, self.level) |
---|
50 | |
---|
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') |
---|
57 | self[courseticket.code] = courseticket |
---|
58 | return |
---|
59 | |
---|
60 | StudentStudyLevel = attrs_to_fields(StudentStudyLevel) |
---|
61 | |
---|
62 | class 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 | |
---|
76 | class 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. |
---|
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. |
---|
85 | """ |
---|
86 | grok.implements(ICourseTicket, IStudentNavigation) |
---|
87 | grok.provides(ICourseTicket) |
---|
88 | |
---|
89 | def __init__(self): |
---|
90 | super(CourseTicket, self).__init__() |
---|
91 | self.code = None |
---|
92 | self.title = None |
---|
93 | self.fcode = None |
---|
94 | self.dcode = None |
---|
95 | self.credits = None |
---|
96 | self.passmark = None |
---|
97 | self.semester = None |
---|
98 | return |
---|
99 | |
---|
100 | def getStudent(self): |
---|
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 |
---|
108 | |
---|
109 | def getLevel(self): |
---|
110 | """Returns the id of the level the ticket has been added to. |
---|
111 | """ |
---|
112 | # XXX: shouldn't that be an attribute? |
---|
113 | try: |
---|
114 | return self.__parent__.level |
---|
115 | except AttributeError: |
---|
116 | return None |
---|
117 | |
---|
118 | def getLevelSession(self): |
---|
119 | """Returns the session of the level the ticket has been added to. |
---|
120 | """ |
---|
121 | # XXX: shouldn't that be an attribute? |
---|
122 | try: |
---|
123 | return self.__parent__.level_session |
---|
124 | except AttributeError: |
---|
125 | return None |
---|
126 | |
---|
127 | |
---|
128 | CourseTicket = attrs_to_fields(CourseTicket) |
---|
129 | |
---|
130 | class 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) |
---|