source: main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/studycourse.py @ 10009

Last change on this file since 10009 was 9211, checked in by uli, 12 years ago

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

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