1 | ## $Id: studylevel.py 10443 2013-07-31 07:13:00Z 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.component import createObject |
---|
25 | from zope.interface import implementedBy |
---|
26 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
27 | from waeup.kofa.students.studylevel import ( |
---|
28 | StudentStudyLevel, CourseTicket, |
---|
29 | CourseTicketFactory, StudentStudyLevelFactory) |
---|
30 | from waeup.kofa.students.interfaces import IStudentNavigation |
---|
31 | from waeup.aaue.students.interfaces import ( |
---|
32 | ICustomStudentStudyLevel, ICustomCourseTicket) |
---|
33 | |
---|
34 | |
---|
35 | class CustomStudentStudyLevel(StudentStudyLevel): |
---|
36 | """This is a container for course tickets. |
---|
37 | """ |
---|
38 | grok.implements(ICustomStudentStudyLevel, IStudentNavigation) |
---|
39 | grok.provides(ICustomStudentStudyLevel) |
---|
40 | |
---|
41 | @property |
---|
42 | def total_credits_s1(self): |
---|
43 | total = 0 |
---|
44 | for ticket in self.values(): |
---|
45 | if ticket.semester == 1: |
---|
46 | total += ticket.credits |
---|
47 | return total |
---|
48 | |
---|
49 | @property |
---|
50 | def total_credits_s2(self): |
---|
51 | total = 0 |
---|
52 | for ticket in self.values(): |
---|
53 | if ticket.semester == 2: |
---|
54 | total += ticket.credits |
---|
55 | return total |
---|
56 | |
---|
57 | @property |
---|
58 | def gpa_params(self): |
---|
59 | weighted_credits = 0.0 |
---|
60 | credits_counted = 0 |
---|
61 | level_gpa = 0.0 |
---|
62 | for ticket in self.values(): |
---|
63 | if ticket.score: |
---|
64 | credits_counted += ticket.credits |
---|
65 | weighted_credits += ticket.credits * ticket.weight |
---|
66 | if credits_counted: |
---|
67 | level_gpa = round(weighted_credits/credits_counted, 2) |
---|
68 | return level_gpa, credits_counted, weighted_credits |
---|
69 | |
---|
70 | CustomStudentStudyLevel = attrs_to_fields( |
---|
71 | CustomStudentStudyLevel, omit=[ |
---|
72 | 'total_credits', 'total_credits_s1', 'total_credits_s2']) |
---|
73 | |
---|
74 | class CustomStudentStudyLevelFactory(StudentStudyLevelFactory): |
---|
75 | """A factory for student study levels. |
---|
76 | """ |
---|
77 | |
---|
78 | def __call__(self, *args, **kw): |
---|
79 | return CustomStudentStudyLevel() |
---|
80 | |
---|
81 | def getInterfaces(self): |
---|
82 | return implementedBy(CustomStudentStudyLevel) |
---|
83 | |
---|
84 | class CustomCourseTicket(CourseTicket): |
---|
85 | """This is a course ticket which allows the |
---|
86 | student to attend the course. Lecturers will enter scores and more at |
---|
87 | the end of the term. |
---|
88 | |
---|
89 | A course ticket contains a copy of the original course and |
---|
90 | course referrer data. If the courses and/or their referrers are removed, the |
---|
91 | corresponding tickets remain unchanged. So we do not need any event |
---|
92 | triggered actions on course tickets. |
---|
93 | """ |
---|
94 | grok.implements(ICustomCourseTicket, IStudentNavigation) |
---|
95 | grok.provides(ICustomCourseTicket) |
---|
96 | |
---|
97 | CustomCourseTicket = attrs_to_fields(CustomCourseTicket) |
---|
98 | |
---|
99 | class CustomCourseTicketFactory(CourseTicketFactory): |
---|
100 | """A factory for student study levels. |
---|
101 | """ |
---|
102 | |
---|
103 | def __call__(self, *args, **kw): |
---|
104 | return CustomCourseTicket() |
---|
105 | |
---|
106 | def getInterfaces(self): |
---|
107 | return implementedBy(CustomCourseTicket) |
---|