source: main/waeup.aaue/trunk/src/waeup/aaue/students/studycourse.py @ 17540

Last change on this file since 17540 was 16907, checked in by Henrik Bettermann, 3 years ago

Add cert courses tickets only if no carry-over ticket has been found.

  • Property svn:keywords set to Id
File size: 4.3 KB
RevLine 
[8326]1## $Id: studycourse.py 16907 2022-03-25 18:49:53Z 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 the student study courses
20and contains the (student) study level objects.
21"""
22import grok
[8474]23from zope.interface import implementedBy
[16907]24from zope.component import createObject
[9357]25from waeup.kofa.students.studycourse import StudentStudyCourseFactory
[8474]26from waeup.kofa.utils.helpers import attrs_to_fields
[16907]27from waeup.kofa.students.interfaces import (
28    IStudentNavigation, IStudentStudyLevel)
[8474]29from waeup.kofa.students.workflow import CLEARED, RETURNING, PAID
[9357]30from kofacustom.nigeria.students.studycourse import NigeriaStudentStudyCourse
[8867]31from waeup.aaue.students.interfaces import ICustomStudentStudyCourse
[8326]32
[9357]33class CustomStudentStudyCourse(NigeriaStudentStudyCourse):
[13528]34    """This is a container for study levels. All pg students
35    must register courses. Thus all pg certificates are 'special'
36    and the property method `ICertificate.check_pg_conditions`
37    is not applied.
[8326]38    """
39    grok.implements(ICustomStudentStudyCourse, IStudentNavigation)
40    grok.provides(ICustomStudentStudyCourse)
41
[13528]42    @property
43    def is_postgrad(self):
44        if self.certificate is None:
45            return False
46        return self.certificate.study_mode.startswith('special_pg')
[8326]47
[13528]48    @property
49    def is_special_postgrad(self):
50        return self.is_postgrad
[9357]51
[16907]52    def addStudentStudyLevel(self, cert, studylevel, course_category=None):
53        """Add a study level object.
54        """
55        if not IStudentStudyLevel.providedBy(studylevel):
56            raise TypeError(
57                'StudentStudyCourses contain only IStudentStudyLevel instances')
58        self[str(studylevel.level)] = studylevel
59        #studylevel.addCertCourseTickets(cert)
60        # Collect carry-over courses in base levels (not in repeating levels)
61        try:
62            co_enabled = grok.getSite()['configuration'].carry_over
63        except TypeError:
64            # In tests we might not have a site object
65            co_enabled = True
66        if not co_enabled or studylevel.level % 100 != 0:
67            return
68        levels = sorted(self.keys())
69        index = levels.index(str(studylevel.level))
70        co_ticket = None
71        if index > 0:
72            previous_level = self[levels[index-1]]
73            for key, val in previous_level.items():
74                if val.total_score >= val.passmark:
75                    continue
76                if course_category and val.course_category != course_category:
77                    continue
78                if key in self[str(studylevel.level)]:
79                    # Carry-over ticket exists
80                    continue
81                co_ticket = createObject(u'waeup.CourseTicket')
82                for name in ['code', 'title', 'credits', 'passmark',
83                             'semester', 'mandatory', 'fcode', 'dcode',
84                             'course_category']:
85                    setattr(co_ticket, name, getattr(val, name))
86                co_ticket.automatic = True
87                co_ticket.carry_over = True
88                self[str(studylevel.level)][co_ticket.code] = co_ticket
89        # AAUE modifaction: Add cert courses tickets only if no carry-over
90        # ticket has been found
91        if not co_ticket:
92            studylevel.addCertCourseTickets(cert)
93        return
94
95
[8326]96CustomStudentStudyCourse = attrs_to_fields(CustomStudentStudyCourse)
97
98class CustomStudentStudyCourseFactory(StudentStudyCourseFactory):
99    """A factory for student study courses.
100    """
101
102    def __call__(self, *args, **kw):
103        return CustomStudentStudyCourse()
104
105    def getInterfaces(self):
106        return implementedBy(CustomStudentStudyCourse)
Note: See TracBrowser for help on using the repository browser.