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

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

Customize warnCreditsOOR and IStudentStudyLevel.

  • Property svn:keywords set to Id
File size: 3.9 KB
RevLine 
[8326]1## $Id: studylevel.py 14591 2017-02-25 17:59:16Z 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)
[8868]29from waeup.kofa.students.interfaces import IStudentNavigation
[8460]30from waeup.fceokene.students.interfaces import (
[8868]31    ICustomStudentStudyLevel, ICustomCourseTicket)
[8326]32
[14406]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)
[8326]47
48class CustomStudentStudyLevel(StudentStudyLevel):
49    """This is a container for course tickets.
50    """
51    grok.implements(ICustomStudentStudyLevel, IStudentNavigation)
52    grok.provides(ICustomStudentStudyLevel)
53
[14591]54    @property
55    def total_credits_s1(self):
56        total = 0
57        for ticket in self.values():
58            if ticket.semester == 1 and not ticket.outstanding:
59                total += ticket.credits
60        return total
61
62    @property
63    def total_credits_s2(self):
64        total = 0
65        for ticket in self.values():
66            if ticket.semester == 2 and not ticket.outstanding:
67                total += ticket.credits
68        return total
69
[9693]70CustomStudentStudyLevel = attrs_to_fields(
[14591]71    CustomStudentStudyLevel, omit=[
72    'total_credits', 'total_credits_s1', 'total_credits_s2', 'gpa'])
[8326]73
74class 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
84class 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
[9809]97    @property
98    def removable_by_student(self):
99        return True
100
[14406]101    @property
102    def grade(self):
103        """Returns the grade calculated from total score.
104        """
[14408]105        return getGradeWeightFromScore(self.total_score)[0]
[14406]106
107    @property
108    def weight(self):
109        """Returns the weight calculated from total score.
110        """
[14408]111        return getGradeWeightFromScore(self.total_score)[1]
[14406]112
[8326]113CustomCourseTicket = attrs_to_fields(CustomCourseTicket)
114
115class CustomCourseTicketFactory(CourseTicketFactory):
116    """A factory for student study levels.
117    """
118
119    def __call__(self, *args, **kw):
120        return CustomCourseTicket()
121
122    def getInterfaces(self):
123        return implementedBy(CustomCourseTicket)
Note: See TracBrowser for help on using the repository browser.