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

Last change on this file since 15172 was 15163, checked in by Henrik Bettermann, 6 years ago

Merge with /main/waeup.kofa/branches/henrik-transcript-workflow:15127-15162

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