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