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

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

We need to customize StudentStudyCourse? and StudentStudyLevel?. Therefore it's better to use the factory utility.

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