source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/studylevel.py @ 14543

Last change on this file since 14543 was 14408, 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 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"""
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 waeup.fceokene.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
48class CustomStudentStudyLevel(StudentStudyLevel):
49    """This is a container for course tickets.
50    """
51    grok.implements(ICustomStudentStudyLevel, IStudentNavigation)
52    grok.provides(ICustomStudentStudyLevel)
53
54CustomStudentStudyLevel = attrs_to_fields(
55    CustomStudentStudyLevel, omit=['total_credits', 'gpa'])
56
57class 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
67class 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
80    @property
81    def removable_by_student(self):
82        return True
83
84    @property
85    def grade(self):
86        """Returns the grade calculated from total score.
87        """
88        return getGradeWeightFromScore(self.total_score)[0]
89
90    @property
91    def weight(self):
92        """Returns the weight calculated from total score.
93        """
94        return getGradeWeightFromScore(self.total_score)[1]
95
96CustomCourseTicket = attrs_to_fields(CustomCourseTicket)
97
98class 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)
Note: See TracBrowser for help on using the repository browser.