1 | ## $Id: export.py 15351 2019-03-11 20:43:33Z 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 | """Exporters for student related stuff. |
---|
19 | """ |
---|
20 | import grok |
---|
21 | from waeup.kofa.interfaces import REQUESTED |
---|
22 | from kofacustom.nigeria.students.interfaces import ( |
---|
23 | INigeriaStudent, |
---|
24 | INigeriaStudentStudyCourse, |
---|
25 | INigeriaStudentStudyLevel, |
---|
26 | INigeriaCourseTicket, |
---|
27 | INigeriaStudentOnlinePayment) |
---|
28 | from waeup.kofa.students.export import ( |
---|
29 | StudentExporter, |
---|
30 | StudentStudyCourseExporter, |
---|
31 | StudentStudyLevelExporter, |
---|
32 | CourseTicketExporter, |
---|
33 | StudentPaymentExporter, |
---|
34 | DataForBursaryExporter) |
---|
35 | from waeup.kofa.utils.helpers import iface_names |
---|
36 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
37 | |
---|
38 | class NigeriaStudentExporter(StudentExporter): |
---|
39 | """Exporter for Students. |
---|
40 | """ |
---|
41 | |
---|
42 | fields = tuple(sorted(iface_names( |
---|
43 | INigeriaStudent, omit=['loggerInfo']))) + ( |
---|
44 | 'password', 'state', 'history', 'certcode', 'is_postgrad', |
---|
45 | 'current_level', 'current_session') |
---|
46 | |
---|
47 | def mangle_value(self, value, name, context=None): |
---|
48 | if '_result' in name and value: |
---|
49 | value = [eval(entry.to_string()) for entry in value] |
---|
50 | return super( |
---|
51 | NigeriaStudentExporter, self).mangle_value( |
---|
52 | value, name, context=context) |
---|
53 | |
---|
54 | class NigeriaStudentStudyCourseExporter(StudentStudyCourseExporter): |
---|
55 | """Exporter for StudentStudyCourses. |
---|
56 | """ |
---|
57 | |
---|
58 | fields = tuple( |
---|
59 | sorted(iface_names(INigeriaStudentStudyCourse))) + ('student_id',) |
---|
60 | |
---|
61 | class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter): |
---|
62 | """Exporter for StudentStudyLevels. |
---|
63 | """ |
---|
64 | fields = tuple(sorted(iface_names( |
---|
65 | INigeriaStudentStudyLevel))) + ( |
---|
66 | 'student_id', 'number_of_tickets','certcode') |
---|
67 | |
---|
68 | class NigeriaCourseTicketExporter(CourseTicketExporter): |
---|
69 | """Exporter for CourseTickets. |
---|
70 | """ |
---|
71 | |
---|
72 | fields = tuple(sorted(iface_names(INigeriaCourseTicket) + |
---|
73 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
74 | 'certcode', 'display_fullname') |
---|
75 | |
---|
76 | class NigeriaStudentPaymentExporter(StudentPaymentExporter): |
---|
77 | """Exporter for OnlinePayment instances. |
---|
78 | """ |
---|
79 | |
---|
80 | fields = tuple( |
---|
81 | sorted(iface_names( |
---|
82 | INigeriaStudentOnlinePayment, exclude_attribs=False, |
---|
83 | omit=['display_item','formatted_p_date']))) + ( |
---|
84 | 'student_id','state','current_session') |
---|
85 | |
---|
86 | class NigeriaDataForBursaryExporter(DataForBursaryExporter): |
---|
87 | """Exporter for bursary data. |
---|
88 | """ |
---|
89 | |
---|
90 | fields = tuple( |
---|
91 | sorted(iface_names( |
---|
92 | INigeriaStudentOnlinePayment, exclude_attribs=False, |
---|
93 | omit=['display_item', 'certificate', 'student']))) + ( |
---|
94 | 'student_id','matric_number','reg_number', |
---|
95 | 'firstname', 'middlename', 'lastname', |
---|
96 | 'state','current_session', |
---|
97 | 'entry_session', 'entry_mode', |
---|
98 | 'faccode', 'depcode','certcode','lga') |
---|
99 | |
---|
100 | def mangle_value(self, value, name, context=None): |
---|
101 | """The mangler fetches the student data. |
---|
102 | """ |
---|
103 | if context is not None: |
---|
104 | student = context.student |
---|
105 | if name in [ |
---|
106 | 'student_id','matric_number', 'reg_number', |
---|
107 | 'firstname', 'middlename', 'lastname', |
---|
108 | 'state', 'current_session', |
---|
109 | 'entry_session', 'entry_mode', |
---|
110 | 'faccode', 'depcode', 'certcode', |
---|
111 | 'lga'] and student is not None: |
---|
112 | value = getattr(student, name, None) |
---|
113 | return super( |
---|
114 | StudentPaymentExporter, self).mangle_value( |
---|
115 | value, name, context=context) |
---|
116 | |
---|
117 | class ClearanceRequestedStudentExporter(StudentExporter): |
---|
118 | """Exporter of data used to assign physical clearance dates. |
---|
119 | """ |
---|
120 | |
---|
121 | grok.name('clearancerequested') |
---|
122 | |
---|
123 | fields = ('student_id', 'reg_number', 'display_fullname', |
---|
124 | 'state', 'current_session', 'history', 'physical_clearance_date', |
---|
125 | 'email','phone') |
---|
126 | |
---|
127 | title = _(u'Clearance Invitation Data') |
---|
128 | |
---|
129 | def filter_func(self, x, **kw): |
---|
130 | # We use this method to post-filter students in state |
---|
131 | # 'clearance_requested' |
---|
132 | return [student for student in x if student.state == REQUESTED] |
---|
133 | |
---|
134 | def mangle_value(self, value, name, context=None): |
---|
135 | if name == 'history': |
---|
136 | # Only show last mesage |
---|
137 | value = value.messages[-1] |
---|
138 | return super( |
---|
139 | StudentExporter, self).mangle_value( |
---|
140 | value, name, context=context) |
---|