source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/studylevel.py @ 17921

Last change on this file since 17921 was 17025, checked in by Henrik Bettermann, 2 years ago

Add continuous assessment (ca) field.

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1## $Id: studylevel.py 17025 2022-07-17 08:50:14Z 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.unidel.students.interfaces import (
31    ICustomStudentStudyLevel, ICustomCourseTicket)
32
33
34class CustomStudentStudyLevel(StudentStudyLevel):
35    """This is a container for course tickets.
36    """
37    grok.implements(ICustomStudentStudyLevel, IStudentNavigation)
38    grok.provides(ICustomStudentStudyLevel)
39
40    @property
41    def total_credits_s1(self):
42        total = 0
43        for ticket in self.values():
44            if ticket.semester == 1 and not ticket.outstanding:
45                total += ticket.credits
46        return total
47
48    @property
49    def total_credits_s2(self):
50        total = 0
51        for ticket in self.values():
52            if ticket.semester == 2 and not ticket.outstanding:
53                total += ticket.credits
54        return total
55
56CustomStudentStudyLevel = attrs_to_fields(
57    CustomStudentStudyLevel, omit=['total_credits', 'gpa',
58        'total_credits_s1', 'total_credits_s2'])
59
60class CustomStudentStudyLevelFactory(StudentStudyLevelFactory):
61    """A factory for student study levels.
62    """
63
64    def __call__(self, *args, **kw):
65        return CustomStudentStudyLevel()
66
67    def getInterfaces(self):
68        return implementedBy(CustomStudentStudyLevel)
69
70class CustomCourseTicket(CourseTicket):
71    """This is a course ticket which allows the
72    student to attend the course. Lecturers will enter scores and more at
73    the end of the term.
74
75    A course ticket contains a copy of the original course and
76    course referrer data. If the courses and/or their referrers are removed, the
77    corresponding tickets remain unchanged. So we do not need any event
78    triggered actions on course tickets.
79    """
80    grok.implements(ICustomCourseTicket, IStudentNavigation)
81    grok.provides(ICustomCourseTicket)
82
83    @property
84    def total_score(self):
85        """Returns ca + score or imported total score.
86        """
87        if self.outstanding:
88            return None
89        # Override total_score if value has been imported
90        if getattr(self, 'imported_ts', None):
91            return self.imported_ts
92        if self.score == -1:
93            return 0
94        if not None in (self.score, self.ca):
95            return self.score + self.ca
96        return None
97
98CustomCourseTicket = attrs_to_fields(CustomCourseTicket)
99
100class CustomCourseTicketFactory(CourseTicketFactory):
101    """A factory for student study levels.
102    """
103
104    def __call__(self, *args, **kw):
105        return CustomCourseTicket()
106
107    def getInterfaces(self):
108        return implementedBy(CustomCourseTicket)
Note: See TracBrowser for help on using the repository browser.