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

Last change on this file since 9912 was 9501, checked in by Henrik Bettermann, 12 years ago

Add addCertCourseTickets method to StudentStudyLevel?.

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