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