1 | ## $Id: studylevel.py 16521 2021-06-29 13:29:15Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2012 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.utils.helpers import attrs_to_fields |
---|
26 | from waeup.kofa.students.studylevel import ( |
---|
27 | StudentStudyLevel, CourseTicket, |
---|
28 | CourseTicketFactory, StudentStudyLevelFactory) |
---|
29 | from waeup.kofa.students.interfaces import IStudentNavigation, ICourseTicket |
---|
30 | from waeup.uniben.students.interfaces import ( |
---|
31 | ICustomStudentStudyLevel, ICustomCourseTicket) |
---|
32 | |
---|
33 | |
---|
34 | class CustomStudentStudyLevel(StudentStudyLevel): |
---|
35 | """This is a container for course tickets. |
---|
36 | """ |
---|
37 | grok.implements(ICustomStudentStudyLevel, IStudentNavigation) |
---|
38 | grok.provides(ICustomStudentStudyLevel) |
---|
39 | |
---|
40 | def addCourseTicket(self, ticket, course): |
---|
41 | """Add a course ticket object. |
---|
42 | """ |
---|
43 | if not ICourseTicket.providedBy(ticket): |
---|
44 | raise TypeError( |
---|
45 | 'StudentStudyLeves contain only ICourseTicket instances') |
---|
46 | ticket.code = course.code |
---|
47 | ticket.title = course.title |
---|
48 | ticket.fcode = course.__parent__.__parent__.__parent__.code |
---|
49 | ticket.dcode = course.__parent__.__parent__.code |
---|
50 | ticket.credits = course.credits |
---|
51 | if self.student.entry_session < 2013: |
---|
52 | ticket.passmark = course.passmark - 5 |
---|
53 | else: |
---|
54 | ticket.passmark = course.passmark |
---|
55 | ticket.semester = course.semester |
---|
56 | self[ticket.code] = ticket |
---|
57 | return |
---|
58 | |
---|
59 | CustomStudentStudyLevel = attrs_to_fields( |
---|
60 | CustomStudentStudyLevel, omit=['total_credits', 'gpa']) |
---|
61 | |
---|
62 | class CustomStudentStudyLevelFactory(StudentStudyLevelFactory): |
---|
63 | """A factory for student study levels. |
---|
64 | """ |
---|
65 | |
---|
66 | def __call__(self, *args, **kw): |
---|
67 | return CustomStudentStudyLevel() |
---|
68 | |
---|
69 | def getInterfaces(self): |
---|
70 | return implementedBy(CustomStudentStudyLevel) |
---|
71 | |
---|
72 | class CustomCourseTicket(CourseTicket): |
---|
73 | """This is a course ticket which allows the |
---|
74 | student to attend the course. Lecturers will enter scores and more at |
---|
75 | the end of the term. |
---|
76 | |
---|
77 | A course ticket contains a copy of the original course and |
---|
78 | course referrer data. If the courses and/or their referrers are removed, the |
---|
79 | corresponding tickets remain unchanged. So we do not need any event |
---|
80 | triggered actions on course tickets. |
---|
81 | """ |
---|
82 | grok.implements(ICustomCourseTicket, IStudentNavigation) |
---|
83 | grok.provides(ICustomCourseTicket) |
---|
84 | |
---|
85 | @property |
---|
86 | def removable_by_student(self): |
---|
87 | return True |
---|
88 | |
---|
89 | @property |
---|
90 | def _getGradeWeightFromScore(self): |
---|
91 | """Uniben Course Grading System |
---|
92 | """ |
---|
93 | if self.total_score is None: |
---|
94 | return (None, None) |
---|
95 | if self.total_score < self.passmark: |
---|
96 | return ('F',0) |
---|
97 | if getattr(self, 'grading_sys', 'A') == 'A': |
---|
98 | if self.total_score >= 70: |
---|
99 | return ('A',5) |
---|
100 | if self.total_score >= 60: |
---|
101 | return ('B',4) |
---|
102 | if self.total_score >= 50: |
---|
103 | return ('C',3) |
---|
104 | if self.total_score >= 45: |
---|
105 | return ('D',2) |
---|
106 | if self.total_score >= 40: |
---|
107 | return ('E',1) |
---|
108 | return ('F',0) |
---|
109 | else: |
---|
110 | if self.total_score >= 70: |
---|
111 | return ('A',5) |
---|
112 | if self.total_score >= 60: |
---|
113 | return ('B',4) |
---|
114 | if self.total_score >= 50: |
---|
115 | return ('C',3) |
---|
116 | if self.total_score >= 45: |
---|
117 | return ('D',2) |
---|
118 | return ('F',0) |
---|
119 | |
---|
120 | |
---|
121 | CustomCourseTicket = attrs_to_fields(CustomCourseTicket) |
---|
122 | |
---|
123 | class CustomCourseTicketFactory(CourseTicketFactory): |
---|
124 | """A factory for student study levels. |
---|
125 | """ |
---|
126 | |
---|
127 | def __call__(self, *args, **kw): |
---|
128 | return CustomCourseTicket() |
---|
129 | |
---|
130 | def getInterfaces(self): |
---|
131 | return implementedBy(CustomCourseTicket) |
---|