source: main/waeup.kofa/trunk/src/waeup/kofa/students/studycourse.py @ 11359

Last change on this file since 11359 was 10479, checked in by Henrik Bettermann, 11 years ago

Reinvent temporary/unrectified/momentary/sessional gpa as a property attribute of study levels. The sessional gpa shown on transcript slips is now called 'rectified sessional gpa'.

  • Property svn:keywords set to Id
File size: 6.1 KB
RevLine 
[7191]1## $Id: studycourse.py 10479 2013-08-12 08:57:26Z henrik $
2##
[6633]3## Copyright (C) 2011 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 the student study courses
20and contains the (student) study level objects.
21"""
22import grok
23from zope.component.interfaces import IFactory
[8325]24from zope.component import createObject
[7256]25from zope.interface import implementedBy
[7811]26from waeup.kofa.students.interfaces import (
[10250]27    IStudentStudyCourse, IStudentNavigation, IStudentStudyLevel,
28    IStudentStudyCourseTranscript)
[7811]29from waeup.kofa.students.studylevel import CourseTicket
[8471]30from waeup.kofa.students.workflow import CLEARED, RETURNING, PAID
[7811]31from waeup.kofa.utils.helpers import attrs_to_fields
[6633]32
33class StudentStudyCourse(grok.Container):
34    """This is a container for study levels.
35    """
[10250]36    grok.implements(IStudentStudyCourse, IStudentNavigation,
37        IStudentStudyCourseTranscript)
[6633]38    grok.provides(IStudentStudyCourse)
39
[10155]40    is_special_postgrad = False
41
[6633]42    def __init__(self):
43        super(StudentStudyCourse, self).__init__()
44        return
45
[8736]46    @property
47    def student(self):
[6642]48        return self.__parent__
49
[8735]50    def writeLogMessage(self, view, message):
51        return self.__parent__.writeLogMessage(view, message)
52
[8323]53    @property
[8471]54    def next_session_allowed(self):
[8483]55        certificate = getattr(self, 'certificate', None)
56        if certificate == None:
57            return False
[8736]58        if self.student.state in (CLEARED, RETURNING):
[8471]59            return True
[8736]60        if self.student.state == PAID \
61            and self.student.is_postgrad:
[8471]62            return True
63        return False
[8323]64
[8483]65    @property
66    def is_postgrad(self):
[8972]67        if self.certificate is None:
68            return False
[8483]69        return self.certificate.study_mode.startswith('pg')
70
[9131]71    @property
72    def is_current(self):
73        if '_' in self.__name__:
74            return False
75        return True
76
[10059]77    @property
78    def is_previous(self):
79        if self.__name__ == 'studycourse_2':
80            return True
81        if self.__name__ == 'studycourse_1' and  \
82            not self.__parent__.has_key('studycourse_2'):
83            return True
84        return False
85
[6782]86    def addStudentStudyLevel(self, cert, studylevel):
[6774]87        """Add a study level object.
88        """
89        if not IStudentStudyLevel.providedBy(studylevel):
90            raise TypeError(
91                'StudentStudyCourses contain only IStudentStudyLevel instances')
[6775]92        self[str(studylevel.level)] = studylevel
[9501]93        studylevel.addCertCourseTickets(cert)
[7661]94        # Collect carry-over courses in base levels (not in repeating levels)
[7664]95        try:
96            co_enabled = grok.getSite()['configuration'].carry_over
97        except TypeError:
98            # In tests we might not have a site object
99            co_enabled = True
[8337]100        if not co_enabled or studylevel.level % 100 != 0:
101            return
102        levels = sorted(self.keys())
103        index = levels.index(str(studylevel.level))
104        if index <= 0:
105            return
106        previous_level = self[levels[index-1]]
107        for key, val in previous_level.items():
108            if val.score >= val.passmark:
109                continue
110            if key in self[str(studylevel.level)]:
111                # Carry-over ticket exists
112                continue
113            co_ticket = createObject(u'waeup.CourseTicket')
114            for name in ['code', 'title', 'credits', 'passmark',
115                         'semester', 'mandatory', 'fcode', 'dcode']:
116                setattr(co_ticket, name, getattr(val, name))
117            co_ticket.automatic = True
118            co_ticket.carry_over = True
119            self[str(studylevel.level)][co_ticket.code] = co_ticket
[6774]120        return
121
[10178]122    def getTranscriptData(self):
123        """Get a sorted list of dicts with level and course ticket data.
124
125        This method is used for transcripts.
126        """
127        levels = []
[10260]128        cgpa = 0.0
129        total_credits_counted = 0
[10178]130        for level_key, level_val in self.items():
131            tickets_1 = []
132            tickets_2 = []
133            tickets_3 = []
[10250]134            tickets = sorted(level_val.values(), key=lambda ticket: ticket.code)
135            for ticket in tickets:
[10178]136                if ticket.semester == 1:
137                    tickets_1.append(ticket)
138                elif ticket.semester == 2:
139                    tickets_2.append(ticket)
140                elif ticket.semester == 3:
141                    tickets_3.append(ticket)
[10479]142            gpa_params = level_val.gpa_params_rectified
[10276]143            sgpa = gpa_params[0]
144            total_credits_counted += gpa_params[1]
145            cgpa += gpa_params[2]
[10178]146            levels.append(
147                dict(level_key=level_key,
148                     level=level_val,
149                     tickets_1=tickets_1,
150                     tickets_2=tickets_2,
[10260]151                     tickets_3=tickets_3,
152                     sgpa=sgpa))
153        if total_credits_counted:
154            cgpa = round(cgpa/total_credits_counted, 2)
155        return sorted(levels, key=lambda level: level['level_key']), cgpa
[10178]156
[6815]157StudentStudyCourse = attrs_to_fields(StudentStudyCourse)
158
[6822]159class StudentStudyCourseFactory(grok.GlobalUtility):
[7536]160    """A factory for student study courses.
[6822]161    """
162    grok.implements(IFactory)
163    grok.name(u'waeup.StudentStudyCourse')
164    title = u"Create a new student study course.",
165    description = u"This factory instantiates new student study course instances."
166
167    def __call__(self, *args, **kw):
168        return StudentStudyCourse()
169
170    def getInterfaces(self):
[7811]171        return implementedBy(StudentStudyCourse)
Note: See TracBrowser for help on using the repository browser.