[8326] | 1 | ## $Id: studylevel.py 14408 2017-01-16 12:46:10Z 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) |
---|
[8868] | 29 | from waeup.kofa.students.interfaces import IStudentNavigation |
---|
[8460] | 30 | from waeup.fceokene.students.interfaces import ( |
---|
[8868] | 31 | ICustomStudentStudyLevel, ICustomCourseTicket) |
---|
[8326] | 32 | |
---|
[14406] | 33 | def getGradeWeightFromScore(score): |
---|
| 34 | if score is None: |
---|
| 35 | return (None, None) |
---|
| 36 | if score >= 70: |
---|
| 37 | return ('A',5) |
---|
| 38 | if score >= 60: |
---|
| 39 | return ('B',4) |
---|
| 40 | if score >= 50: |
---|
| 41 | return ('C',3) |
---|
| 42 | if score >= 45: |
---|
| 43 | return ('D',2) |
---|
| 44 | if score >= 40: |
---|
| 45 | return ('E',1) |
---|
| 46 | return ('F',0) |
---|
[8326] | 47 | |
---|
| 48 | class CustomStudentStudyLevel(StudentStudyLevel): |
---|
| 49 | """This is a container for course tickets. |
---|
| 50 | """ |
---|
| 51 | grok.implements(ICustomStudentStudyLevel, IStudentNavigation) |
---|
| 52 | grok.provides(ICustomStudentStudyLevel) |
---|
| 53 | |
---|
[9693] | 54 | CustomStudentStudyLevel = attrs_to_fields( |
---|
[10482] | 55 | CustomStudentStudyLevel, omit=['total_credits', 'gpa']) |
---|
[8326] | 56 | |
---|
| 57 | class CustomStudentStudyLevelFactory(StudentStudyLevelFactory): |
---|
| 58 | """A factory for student study levels. |
---|
| 59 | """ |
---|
| 60 | |
---|
| 61 | def __call__(self, *args, **kw): |
---|
| 62 | return CustomStudentStudyLevel() |
---|
| 63 | |
---|
| 64 | def getInterfaces(self): |
---|
| 65 | return implementedBy(CustomStudentStudyLevel) |
---|
| 66 | |
---|
| 67 | class CustomCourseTicket(CourseTicket): |
---|
| 68 | """This is a course ticket which allows the |
---|
| 69 | student to attend the course. Lecturers will enter scores and more at |
---|
| 70 | the end of the term. |
---|
| 71 | |
---|
| 72 | A course ticket contains a copy of the original course and |
---|
| 73 | course referrer data. If the courses and/or their referrers are removed, the |
---|
| 74 | corresponding tickets remain unchanged. So we do not need any event |
---|
| 75 | triggered actions on course tickets. |
---|
| 76 | """ |
---|
| 77 | grok.implements(ICustomCourseTicket, IStudentNavigation) |
---|
| 78 | grok.provides(ICustomCourseTicket) |
---|
| 79 | |
---|
[9809] | 80 | @property |
---|
| 81 | def removable_by_student(self): |
---|
| 82 | return True |
---|
| 83 | |
---|
[14406] | 84 | @property |
---|
| 85 | def grade(self): |
---|
| 86 | """Returns the grade calculated from total score. |
---|
| 87 | """ |
---|
[14408] | 88 | return getGradeWeightFromScore(self.total_score)[0] |
---|
[14406] | 89 | |
---|
| 90 | @property |
---|
| 91 | def weight(self): |
---|
| 92 | """Returns the weight calculated from total score. |
---|
| 93 | """ |
---|
[14408] | 94 | return getGradeWeightFromScore(self.total_score)[1] |
---|
[14406] | 95 | |
---|
[8326] | 96 | CustomCourseTicket = attrs_to_fields(CustomCourseTicket) |
---|
| 97 | |
---|
| 98 | class CustomCourseTicketFactory(CourseTicketFactory): |
---|
| 99 | """A factory for student study levels. |
---|
| 100 | """ |
---|
| 101 | |
---|
| 102 | def __call__(self, *args, **kw): |
---|
| 103 | return CustomCourseTicket() |
---|
| 104 | |
---|
| 105 | def getInterfaces(self): |
---|
| 106 | return implementedBy(CustomCourseTicket) |
---|