1 | ## $Id: studylevel.py 9692 2012-11-20 06:37:11Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2012 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 a student study level |
---|
20 | and contains the course tickets. |
---|
21 | """ |
---|
22 | import grok |
---|
23 | from zope.component.interfaces import IFactory |
---|
24 | from zope.component import createObject |
---|
25 | from zope.interface import implementedBy |
---|
26 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
27 | from waeup.kofa.students.studylevel import ( |
---|
28 | StudentStudyLevel, CourseTicket, |
---|
29 | CourseTicketFactory, StudentStudyLevelFactory) |
---|
30 | from waeup.kofa.students.interfaces import IStudentNavigation |
---|
31 | from waeup.aaue.students.interfaces import ( |
---|
32 | ICustomStudentStudyLevel, ICustomCourseTicket) |
---|
33 | |
---|
34 | |
---|
35 | class CustomStudentStudyLevel(StudentStudyLevel): |
---|
36 | """This is a container for course tickets. |
---|
37 | """ |
---|
38 | grok.implements(ICustomStudentStudyLevel, IStudentNavigation) |
---|
39 | grok.provides(ICustomStudentStudyLevel) |
---|
40 | |
---|
41 | def addCertCourseTickets(self, cert): |
---|
42 | """Collect all certificate courses and create course |
---|
43 | tickets automatically. |
---|
44 | |
---|
45 | Add ticket only if student has paid for the course.semester. |
---|
46 | """ |
---|
47 | payments = self.student.getPaymentTuples() |
---|
48 | if cert is not None: |
---|
49 | for key, val in cert.items(): |
---|
50 | if val.level != self.level: |
---|
51 | continue |
---|
52 | if val.course.semester == 2 and \ |
---|
53 | not (self.student.current_session, |
---|
54 | 'schoolfee_2', 'paid') in payments: |
---|
55 | continue |
---|
56 | ticket = createObject(u'waeup.CourseTicket') |
---|
57 | ticket.automatic = True |
---|
58 | ticket.mandatory = val.mandatory |
---|
59 | ticket.carry_over = False |
---|
60 | self.addCourseTicket(ticket, val.course) |
---|
61 | return |
---|
62 | |
---|
63 | CustomStudentStudyLevel = attrs_to_fields( |
---|
64 | CustomStudentStudyLevel, omit=['total_credits', 'gpa']) |
---|
65 | |
---|
66 | class CustomStudentStudyLevelFactory(StudentStudyLevelFactory): |
---|
67 | """A factory for student study levels. |
---|
68 | """ |
---|
69 | |
---|
70 | def __call__(self, *args, **kw): |
---|
71 | return CustomStudentStudyLevel() |
---|
72 | |
---|
73 | def getInterfaces(self): |
---|
74 | return implementedBy(CustomStudentStudyLevel) |
---|
75 | |
---|
76 | class CustomCourseTicket(CourseTicket): |
---|
77 | """This is a course ticket which allows the |
---|
78 | student to attend the course. Lecturers will enter scores and more at |
---|
79 | the end of the term. |
---|
80 | |
---|
81 | A course ticket contains a copy of the original course and |
---|
82 | course referrer data. If the courses and/or their referrers are removed, the |
---|
83 | corresponding tickets remain unchanged. So we do not need any event |
---|
84 | triggered actions on course tickets. |
---|
85 | """ |
---|
86 | grok.implements(ICustomCourseTicket, IStudentNavigation) |
---|
87 | grok.provides(ICustomCourseTicket) |
---|
88 | |
---|
89 | CustomCourseTicket = attrs_to_fields(CustomCourseTicket) |
---|
90 | |
---|
91 | class CustomCourseTicketFactory(CourseTicketFactory): |
---|
92 | """A factory for student study levels. |
---|
93 | """ |
---|
94 | |
---|
95 | def __call__(self, *args, **kw): |
---|
96 | return CustomCourseTicket() |
---|
97 | |
---|
98 | def getInterfaces(self): |
---|
99 | return implementedBy(CustomCourseTicket) |
---|