1 | ## $Id: export.py 12084 2014-11-28 09:54:10Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2015 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 datetime import datetime |
---|
22 | from waeup.kofa.interfaces import IKofaUtils |
---|
23 | from zope.component import getUtility |
---|
24 | from waeup.uniben.students.interfaces import ( |
---|
25 | ICustomStudent, |
---|
26 | ICustomStudentStudyCourse, |
---|
27 | ICustomStudentStudyLevel, |
---|
28 | ICustomCourseTicket, |
---|
29 | ICustomStudentOnlinePayment, |
---|
30 | IMedicalHistory) |
---|
31 | from kofacustom.nigeria.students.export import ( |
---|
32 | NigeriaStudentExporter, |
---|
33 | NigeriaStudentStudyCourseExporter, |
---|
34 | NigeriaStudentStudyLevelExporter, |
---|
35 | NigeriaCourseTicketExporter, |
---|
36 | NigeriaStudentPaymentExporter, |
---|
37 | NigeriaDataForBursaryExporter, |
---|
38 | NigeriaTrimmedDataExporter, |
---|
39 | ) |
---|
40 | from waeup.kofa.students.export import ( |
---|
41 | SchoolFeePaymentsOverviewExporter, StudentExporterBase) |
---|
42 | from waeup.kofa.utils.helpers import iface_names |
---|
43 | |
---|
44 | class CustomStudentExporter(NigeriaStudentExporter): |
---|
45 | """Exporter for Students. |
---|
46 | """ |
---|
47 | |
---|
48 | fields = tuple(sorted(iface_names( |
---|
49 | ICustomStudent, omit=['loggerInfo']))) + ( |
---|
50 | 'password', 'state', 'history', 'certcode', 'is_postgrad', |
---|
51 | 'current_level', 'current_session') |
---|
52 | |
---|
53 | class CustomTrimmedDataExporter(NigeriaTrimmedDataExporter): |
---|
54 | """The Student Trimmed Data Exporter first filters the set of students |
---|
55 | by searching the students catalog. Then it exports a trimmed data set |
---|
56 | of this set of students. |
---|
57 | """ |
---|
58 | fields = ( |
---|
59 | 'student_id', |
---|
60 | 'matric_number', |
---|
61 | 'reg_number', |
---|
62 | 'firstname', |
---|
63 | 'middlename', |
---|
64 | 'lastname', |
---|
65 | 'sex', |
---|
66 | 'email', |
---|
67 | 'email2', |
---|
68 | 'phone', |
---|
69 | 'perm_address', |
---|
70 | 'nationality', |
---|
71 | 'date_of_birth', |
---|
72 | 'state', |
---|
73 | 'current_mode', |
---|
74 | 'certcode', |
---|
75 | 'faccode', |
---|
76 | 'depcode', |
---|
77 | 'current_level', |
---|
78 | 'current_session', |
---|
79 | 'current_verdict', |
---|
80 | 'entry_session', |
---|
81 | 'lg_state', |
---|
82 | 'lg_area', |
---|
83 | 'flash_notice', |
---|
84 | 'physical_clearance_date', |
---|
85 | 'former_matric', |
---|
86 | 'hq_matric_no', |
---|
87 | 'hq2_matric_no') |
---|
88 | |
---|
89 | class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter): |
---|
90 | """Exporter for StudentStudyCourses. |
---|
91 | """ |
---|
92 | |
---|
93 | fields = tuple( |
---|
94 | sorted(iface_names(ICustomStudentStudyCourse))) + ( |
---|
95 | 'student_id', 'previous') |
---|
96 | |
---|
97 | class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter): |
---|
98 | """Exporter for StudentStudyLevels. |
---|
99 | """ |
---|
100 | #: Fieldnames considered by this exporter |
---|
101 | fields = tuple(sorted(iface_names( |
---|
102 | ICustomStudentStudyLevel))) + ( |
---|
103 | 'student_id', 'number_of_tickets','certcode', 'previous') |
---|
104 | |
---|
105 | class CustomCourseTicketExporter(NigeriaCourseTicketExporter): |
---|
106 | """Exporter for CourseTickets. |
---|
107 | """ |
---|
108 | |
---|
109 | fields = tuple(sorted(iface_names(ICustomCourseTicket) + |
---|
110 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
111 | 'certcode', 'display_fullname', 'previous', 'matric_number') |
---|
112 | |
---|
113 | class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter): |
---|
114 | """Exporter for OnlinePayment instances. |
---|
115 | """ |
---|
116 | |
---|
117 | fields = tuple( |
---|
118 | sorted(iface_names( |
---|
119 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
120 | omit=['display_item']))) + ( |
---|
121 | 'student_id','state','current_session') |
---|
122 | |
---|
123 | class CustomDataForBursaryExporter(NigeriaDataForBursaryExporter): |
---|
124 | """ |
---|
125 | """ |
---|
126 | |
---|
127 | fields = tuple( |
---|
128 | sorted(iface_names( |
---|
129 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
130 | omit=['display_item', 'certificate', 'student']))) + ( |
---|
131 | 'student_id','matric_number','reg_number', |
---|
132 | 'firstname', 'middlename', 'lastname', |
---|
133 | 'state','current_session', |
---|
134 | 'entry_session', 'entry_mode', |
---|
135 | 'faccode', 'depcode','certcode') |
---|
136 | |
---|
137 | class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter): |
---|
138 | |
---|
139 | curr_year = datetime.now().year |
---|
140 | year_range = range(curr_year - 14, curr_year + 1) # 3 more years in Uniben |
---|
141 | year_range_tuple = tuple([str(year) for year in year_range]) |
---|
142 | |
---|
143 | fields = ('student_id', 'matric_number', 'firstname', 'middlename', |
---|
144 | 'lastname', 'state', 'certcode', 'faccode', 'depcode', 'is_postgrad', |
---|
145 | 'current_level', 'current_session', 'current_mode', |
---|
146 | 'entry_session', 'reg_number', 'email2', 'sex' |
---|
147 | ) + year_range_tuple |
---|
148 | |
---|
149 | class MedicalHistoryExporter(grok.GlobalUtility, StudentExporterBase): |
---|
150 | """ |
---|
151 | """ |
---|
152 | grok.name('medicalhistory') |
---|
153 | |
---|
154 | fields = tuple( |
---|
155 | sorted(iface_names( |
---|
156 | IMedicalHistory, exclude_attribs=False,))) + ( |
---|
157 | 'student_id','display_fullname', 'matric_number', 'faccode', |
---|
158 | 'depcode', 'state','current_session', 'current_level', 'genotype', 'bloodgroup') |
---|
159 | title = 'Medical Questionnaire Data' |
---|
160 | |
---|
161 | def mangle_value(self, value, name, context=None): |
---|
162 | """The mangler determines the titles of faculty, department |
---|
163 | and certificate. It also computes the path of passport image file |
---|
164 | stored in the filesystem. |
---|
165 | """ |
---|
166 | if context is not None: |
---|
167 | student = context.student |
---|
168 | if name in ('student_id','display_fullname', |
---|
169 | 'matric_number', 'faccode', |
---|
170 | 'depcode', 'state','current_session', |
---|
171 | 'current_level', |
---|
172 | 'genotype', 'bloodgroup') and student is not None: |
---|
173 | value = getattr(student, name, None) |
---|
174 | return super( |
---|
175 | MedicalHistoryExporter, self).mangle_value( |
---|
176 | value, name, context=context) |
---|
177 | |
---|
178 | |
---|
179 | class NYSCExporter(SchoolFeePaymentsOverviewExporter): |
---|
180 | """ |
---|
181 | """ |
---|
182 | grok.name('nysc') |
---|
183 | curr_year = datetime.now().year |
---|
184 | year_range = range(curr_year - 11, curr_year + 1) |
---|
185 | year_range_tuple = tuple([str(year) for year in year_range]) |
---|
186 | fields = ('student_id', |
---|
187 | 'matric_number', |
---|
188 | 'reg_number', |
---|
189 | 'firstname', |
---|
190 | 'middlename', |
---|
191 | 'lastname', |
---|
192 | 'sex', |
---|
193 | #'email', |
---|
194 | #'phone', |
---|
195 | 'nationality', |
---|
196 | 'date_of_birth', |
---|
197 | 'state', |
---|
198 | 'lg_state', |
---|
199 | 'lg_area', |
---|
200 | 'current_mode', |
---|
201 | 'certificate', |
---|
202 | 'faccode', |
---|
203 | 'depcode', |
---|
204 | 'current_level', |
---|
205 | 'current_session', |
---|
206 | 'current_verdict', |
---|
207 | 'entry_session', |
---|
208 | 'nysc_verdict', |
---|
209 | 'nysc_senate_info', |
---|
210 | 'nysc_date_of_graduation', |
---|
211 | 'nysc_updated', |
---|
212 | 'nysc_processed', |
---|
213 | ) + year_range_tuple |
---|
214 | title = u'NYSC Indication' |
---|
215 | |
---|
216 | def filter_func(self, x, **kw): |
---|
217 | students = list() |
---|
218 | for student in x: |
---|
219 | if student.nysc == True and student.nysc_processed == False: |
---|
220 | students.append(student) |
---|
221 | return students |
---|
222 | |
---|
223 | def mangle_value(self, value, name, context=None): |
---|
224 | verdicts = getUtility(IKofaUtils).VERDICTS_DICT |
---|
225 | if name in ('lg_state', 'lg_area') and context.lga: |
---|
226 | value = context.lga |
---|
227 | if value.startswith('cross_river') or value.startswith('akwa_ibom'): |
---|
228 | value = context.lga.replace('_', '-', 1) |
---|
229 | if name == 'lg_state': |
---|
230 | value = value.split('_')[0] |
---|
231 | if name == 'lg_area': |
---|
232 | value = '-'.join(value.split('_')[1:]) |
---|
233 | if name == 'certificate': |
---|
234 | cert = getattr(context.get('studycourse', None), 'certificate', None) |
---|
235 | if cert is not None: |
---|
236 | value = cert.title |
---|
237 | if name == 'nysc_verdict' and value: |
---|
238 | value = verdicts[value] |
---|
239 | return super( |
---|
240 | NYSCExporter, self).mangle_value( |
---|
241 | value, name, context=context) |
---|