source: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/studylevel.py @ 15328

Last change on this file since 15328 was 14409, checked in by Henrik Bettermann, 8 years ago

Fix methods.

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
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"""
19Container which holds the data of a student study level
20and contains the course tickets.
21"""
22import grok
23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
25from waeup.kofa.utils.helpers import attrs_to_fields
26from waeup.kofa.students.studylevel import (
27    StudentStudyLevel, CourseTicket,
28    CourseTicketFactory, StudentStudyLevelFactory)
29from waeup.kofa.students.interfaces import IStudentNavigation
30from kofacustom.coewarri.students.interfaces import (
31    ICustomStudentStudyLevel, ICustomCourseTicket)
32
33def 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)
47
48
49class CustomStudentStudyLevel(StudentStudyLevel):
50    """This is a container for course tickets.
51    """
52    grok.implements(ICustomStudentStudyLevel, IStudentNavigation)
53    grok.provides(ICustomStudentStudyLevel)
54
55CustomStudentStudyLevel = attrs_to_fields(
56    CustomStudentStudyLevel, omit=['total_credits', 'gpa'])
57
58class 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
68class 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
81    @property
82    def grade(self):
83        """Returns the grade calculated from total score.
84        """
85        return getGradeWeightFromScore(self.total_score)[0]
86
87    @property
88    def weight(self):
89        """Returns the weight calculated from total score.
90        """
91        return getGradeWeightFromScore(self.total_score)[1]
92
93CustomCourseTicket = attrs_to_fields(CustomCourseTicket)
94
95class 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)
Note: See TracBrowser for help on using the repository browser.