1 | ## $Id: studycourse.py 7661 2012-02-17 07:43:22Z 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 | """ |
---|
19 | Container which holds the data of the student study courses |
---|
20 | and contains the (student) study level objects. |
---|
21 | """ |
---|
22 | import grok |
---|
23 | from zope.component.interfaces import IFactory |
---|
24 | from zope.interface import implementedBy |
---|
25 | from waeup.sirp.students.interfaces import ( |
---|
26 | IStudentStudyCourse, IStudentNavigation, IStudentStudyLevel) |
---|
27 | from waeup.sirp.students.studylevel import CourseTicket |
---|
28 | from waeup.sirp.utils.helpers import attrs_to_fields |
---|
29 | |
---|
30 | class 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 | def addStudentStudyLevel(self, cert, studylevel): |
---|
44 | """Add a study level object. |
---|
45 | """ |
---|
46 | if not IStudentStudyLevel.providedBy(studylevel): |
---|
47 | raise TypeError( |
---|
48 | 'StudentStudyCourses contain only IStudentStudyLevel instances') |
---|
49 | self[str(studylevel.level)] = studylevel |
---|
50 | |
---|
51 | #Create course tickets automatically |
---|
52 | if cert is not None: |
---|
53 | for key, val in cert.items(): |
---|
54 | if val.level != studylevel.level: |
---|
55 | continue |
---|
56 | ticket = CourseTicket() |
---|
57 | ticket.code = val.getCourseCode() |
---|
58 | ticket.automatic = True |
---|
59 | ticket.core_or_elective = val.core_or_elective |
---|
60 | ticket.title = val.course.title |
---|
61 | ticket.fcode = val.course.__parent__.__parent__.__parent__.code |
---|
62 | ticket.dcode = val.course.__parent__.__parent__.code |
---|
63 | ticket.credits = val.course.credits |
---|
64 | ticket.passmark = val.course.passmark |
---|
65 | ticket.semester = val.course.semester |
---|
66 | self[str(studylevel.level)][ticket.code] = ticket |
---|
67 | # Collect carry-over courses in base levels (not in repeating levels) |
---|
68 | if studylevel.level % 100 == 0: |
---|
69 | levels = sorted(self.keys()) |
---|
70 | index = levels.index(str(studylevel.level)) |
---|
71 | if index > 0: |
---|
72 | previous_level = self[levels[index-1]] |
---|
73 | for key, val in previous_level.items(): |
---|
74 | if val.score < val.passmark: |
---|
75 | if key in self[str(studylevel.level)]: |
---|
76 | # Carry-over ticket exists |
---|
77 | continue |
---|
78 | co_ticket = CourseTicket() |
---|
79 | for name in ['code', 'title', 'credits', 'passmark', |
---|
80 | 'semester', 'core_or_elective', |
---|
81 | 'fcode', 'dcode']: |
---|
82 | setattr(co_ticket, name, getattr(val, name)) |
---|
83 | co_ticket.automatic = True |
---|
84 | co_ticket.carry_over = True |
---|
85 | self[str(studylevel.level)][co_ticket.code] = co_ticket |
---|
86 | return |
---|
87 | |
---|
88 | StudentStudyCourse = attrs_to_fields(StudentStudyCourse) |
---|
89 | |
---|
90 | class StudentStudyCourseFactory(grok.GlobalUtility): |
---|
91 | """A factory for student study courses. |
---|
92 | """ |
---|
93 | grok.implements(IFactory) |
---|
94 | grok.name(u'waeup.StudentStudyCourse') |
---|
95 | title = u"Create a new student study course.", |
---|
96 | description = u"This factory instantiates new student study course instances." |
---|
97 | |
---|
98 | def __call__(self, *args, **kw): |
---|
99 | return StudentStudyCourse() |
---|
100 | |
---|
101 | def getInterfaces(self): |
---|
102 | return implementedBy(StudentStudyCourse) |
---|