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

Last change on this file since 8488 was 8483, checked in by Henrik Bettermann, 13 years ago

next_session_allowed is False if certificate is None.

  • Property svn:keywords set to Id
File size: 5.0 KB
RevLine 
[7191]1## $Id: studycourse.py 8483 2012-05-21 10:01:37Z 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 (
[6774]27    IStudentStudyCourse, IStudentNavigation, IStudentStudyLevel)
[7811]28from waeup.kofa.students.studylevel import CourseTicket
[8471]29from waeup.kofa.students.workflow import CLEARED, RETURNING, PAID
[7811]30from waeup.kofa.utils.helpers import attrs_to_fields
[6633]31
32class StudentStudyCourse(grok.Container):
33    """This is a container for study levels.
34    """
[6642]35    grok.implements(IStudentStudyCourse, IStudentNavigation)
[6633]36    grok.provides(IStudentStudyCourse)
37
38    def __init__(self):
39        super(StudentStudyCourse, self).__init__()
40        return
41
[6642]42    def getStudent(self):
43        return self.__parent__
44
[8323]45    @property
[8471]46    def next_session_allowed(self):
[8483]47        certificate = getattr(self, 'certificate', None)
48        if certificate == None:
49            return False
[8471]50        if self.getStudent().state in (CLEARED, RETURNING):
51            return True
52        if self.getStudent().state == PAID \
[8472]53            and self.getStudent().is_postgrad:
[8471]54            return True
55        return False
[8323]56
[8483]57    @property
58    def is_postgrad(self):
59        return self.certificate.study_mode.startswith('pg')
60        #return cert.start_level == 999 or cert.end_level == 999
61
[6782]62    def addStudentStudyLevel(self, cert, studylevel):
[6774]63        """Add a study level object.
64        """
65        if not IStudentStudyLevel.providedBy(studylevel):
66            raise TypeError(
67                'StudentStudyCourses contain only IStudentStudyLevel instances')
[6775]68        self[str(studylevel.level)] = studylevel
[6782]69
70        #Create course tickets automatically
[7533]71        if cert is not None:
72            for key, val in cert.items():
73                if val.level != studylevel.level:
74                    continue
[8325]75                ticket = createObject(u'waeup.CourseTicket')
[7533]76                ticket.code = val.getCourseCode()
77                ticket.automatic = True
[7665]78                ticket.mandatory = val.mandatory
[7533]79                ticket.title = val.course.title
80                ticket.fcode = val.course.__parent__.__parent__.__parent__.code
81                ticket.dcode = val.course.__parent__.__parent__.code
82                ticket.credits = val.course.credits
83                ticket.passmark = val.course.passmark
84                ticket.semester = val.course.semester
[8141]85                ticket.carry_over = False
[7661]86                self[str(studylevel.level)][ticket.code] = ticket
87        # Collect carry-over courses in base levels (not in repeating levels)
[7664]88        try:
89            co_enabled = grok.getSite()['configuration'].carry_over
90        except TypeError:
91            # In tests we might not have a site object
92            co_enabled = True
[8337]93        if not co_enabled or studylevel.level % 100 != 0:
94            return
95        levels = sorted(self.keys())
96        index = levels.index(str(studylevel.level))
97        if index <= 0:
98            return
99        previous_level = self[levels[index-1]]
100        for key, val in previous_level.items():
101            if val.score >= val.passmark:
102                continue
103            if key in self[str(studylevel.level)]:
104                # Carry-over ticket exists
105                continue
106            co_ticket = createObject(u'waeup.CourseTicket')
107            for name in ['code', 'title', 'credits', 'passmark',
108                         'semester', 'mandatory', 'fcode', 'dcode']:
109                setattr(co_ticket, name, getattr(val, name))
110            co_ticket.automatic = True
111            co_ticket.carry_over = True
112            self[str(studylevel.level)][co_ticket.code] = co_ticket
[6774]113        return
114
[6815]115StudentStudyCourse = attrs_to_fields(StudentStudyCourse)
116
[6822]117class StudentStudyCourseFactory(grok.GlobalUtility):
[7536]118    """A factory for student study courses.
[6822]119    """
120    grok.implements(IFactory)
121    grok.name(u'waeup.StudentStudyCourse')
122    title = u"Create a new student study course.",
123    description = u"This factory instantiates new student study course instances."
124
125    def __call__(self, *args, **kw):
126        return StudentStudyCourse()
127
128    def getInterfaces(self):
[7811]129        return implementedBy(StudentStudyCourse)
Note: See TracBrowser for help on using the repository browser.