1 | ## $Id: interfaces.py 15576 2019-09-03 08:08:55Z 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 | """Customized interfaces of the university application package. |
---|
19 | """ |
---|
20 | |
---|
21 | from datetime import datetime |
---|
22 | from zope import schema |
---|
23 | from waeup.kofa.applicants.interfaces import ( |
---|
24 | IApplicantBaseData, |
---|
25 | AppCatCertificateSource, CertificateSource) |
---|
26 | from waeup.kofa.schoolgrades import ResultEntryField |
---|
27 | from waeup.kofa.interfaces import ( |
---|
28 | SimpleKofaVocabulary, academic_sessions_vocab, validate_email) |
---|
29 | from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber |
---|
30 | from waeup.kofa.students.vocabularies import nats_vocab, GenderSource |
---|
31 | from waeup.kofa.applicants.interfaces import ( |
---|
32 | contextual_reg_num_source, ISpecialApplicant) |
---|
33 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
34 | LGASource, high_qual, high_grade, exam_types, |
---|
35 | OMIT_DISPLAY_FIELDS, |
---|
36 | INigeriaUGApplicant, INigeriaPGApplicant, |
---|
37 | INigeriaApplicantOnlinePayment, |
---|
38 | INigeriaUGApplicantEdit, INigeriaPGApplicantEdit, |
---|
39 | INigeriaApplicantUpdateByRegNo, |
---|
40 | IPUTMEApplicantEdit, |
---|
41 | ) |
---|
42 | from kofacustom.dspg.interfaces import MessageFactory as _ |
---|
43 | from kofacustom.dspg.payments.interfaces import ICustomOnlinePayment |
---|
44 | |
---|
45 | ND_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
46 | 'hq_type', |
---|
47 | 'hq_matric_no', |
---|
48 | 'hq_degree', |
---|
49 | 'hq_school', |
---|
50 | 'hq_session', |
---|
51 | 'hq_disc', |
---|
52 | 'hq_type') |
---|
53 | ND_OMIT_PDF_FIELDS = ND_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
54 | ND_OMIT_MANAGE_FIELDS = ('special_application',) |
---|
55 | ND_OMIT_EDIT_FIELDS = ND_OMIT_MANAGE_FIELDS + ND_OMIT_DISPLAY_FIELDS + ( |
---|
56 | 'student_id', 'notice', |
---|
57 | 'screening_score', |
---|
58 | 'screening_venue', |
---|
59 | 'screening_date', |
---|
60 | 'jamb_age', |
---|
61 | #'jamb_subjects', |
---|
62 | #'jamb_score', |
---|
63 | 'aggregate') |
---|
64 | |
---|
65 | class ICustomUGApplicant(IApplicantBaseData): |
---|
66 | """An undergraduate applicant. |
---|
67 | |
---|
68 | This interface defines the least common multiple of all fields |
---|
69 | in ug application forms. In customized forms, fields can be excluded by |
---|
70 | adding them to the UG_OMIT* tuples. |
---|
71 | """ |
---|
72 | sex = schema.Choice( |
---|
73 | title = _(u'Sex'), |
---|
74 | source = GenderSource(), |
---|
75 | required = False, |
---|
76 | ) |
---|
77 | nationality = schema.Choice( |
---|
78 | source = nats_vocab, |
---|
79 | title = _(u'Nationality'), |
---|
80 | required = False, |
---|
81 | ) |
---|
82 | lga = schema.Choice( |
---|
83 | source = LGASource(), |
---|
84 | title = _(u'State/LGA (Nigerians only)'), |
---|
85 | required = False, |
---|
86 | ) |
---|
87 | #perm_address = schema.Text( |
---|
88 | # title = _(u'Permanent Address'), |
---|
89 | # required = False, |
---|
90 | # ) |
---|
91 | next_kin_address = schema.Text( |
---|
92 | title = _(u'Next of Kin Address'), |
---|
93 | required = False, |
---|
94 | ) |
---|
95 | jamb_reg_number = schema.TextLine( |
---|
96 | title = _(u'JAMB Registration Number'), |
---|
97 | required = False, |
---|
98 | ) |
---|
99 | course1 = schema.Choice( |
---|
100 | title = _(u'1st Choice Course of Study'), |
---|
101 | source = AppCatCertificateSource(), |
---|
102 | required = False, |
---|
103 | ) |
---|
104 | course2 = schema.Choice( |
---|
105 | title = _(u'2nd Choice Course of Study'), |
---|
106 | source = AppCatCertificateSource(), |
---|
107 | required = False, |
---|
108 | ) |
---|
109 | olevel_type = schema.Choice( |
---|
110 | title = _(u'Qualification Obtained'), |
---|
111 | required = False, |
---|
112 | readonly = False, |
---|
113 | vocabulary = exam_types, |
---|
114 | ) |
---|
115 | olevel_school = schema.TextLine( |
---|
116 | title = _(u'Institution Attended'), |
---|
117 | required = False, |
---|
118 | readonly = False, |
---|
119 | ) |
---|
120 | olevel_exam_number = schema.TextLine( |
---|
121 | title = _(u'Exam Number'), |
---|
122 | required = False, |
---|
123 | readonly = False, |
---|
124 | ) |
---|
125 | olevel_exam_date = FormattedDate( |
---|
126 | title = _(u'Exam Date'), |
---|
127 | required = False, |
---|
128 | readonly = False, |
---|
129 | show_year = True, |
---|
130 | ) |
---|
131 | olevel_results = schema.List( |
---|
132 | title = _(u'Exam Results'), |
---|
133 | value_type = ResultEntryField(), |
---|
134 | required = False, |
---|
135 | readonly = False, |
---|
136 | defaultFactory=list, |
---|
137 | ) |
---|
138 | olevel_pin = schema.TextLine( |
---|
139 | title = _(u'Result Checking PIN'), |
---|
140 | required = False, |
---|
141 | readonly = False, |
---|
142 | ) |
---|
143 | olevel_pin_serial = schema.TextLine( |
---|
144 | title = _(u'PIN Serial Number'), |
---|
145 | required = False, |
---|
146 | readonly = False, |
---|
147 | ) |
---|
148 | olevel_type2 = schema.Choice( |
---|
149 | title = _(u'2nd Qualification Obtained'), |
---|
150 | required = False, |
---|
151 | readonly = False, |
---|
152 | vocabulary = exam_types, |
---|
153 | ) |
---|
154 | olevel_school2 = schema.TextLine( |
---|
155 | title = _(u'2nd Institution Attended'), |
---|
156 | required = False, |
---|
157 | readonly = False, |
---|
158 | ) |
---|
159 | olevel_exam_number2 = schema.TextLine( |
---|
160 | title = _(u'2nd Exam Number'), |
---|
161 | required = False, |
---|
162 | readonly = False, |
---|
163 | ) |
---|
164 | olevel_exam_date2 = FormattedDate( |
---|
165 | title = _(u'2nd Exam Date'), |
---|
166 | required = False, |
---|
167 | readonly = False, |
---|
168 | show_year = True, |
---|
169 | ) |
---|
170 | olevel_results2 = schema.List( |
---|
171 | title = _(u'2nd Exam Results'), |
---|
172 | value_type = ResultEntryField(), |
---|
173 | required = False, |
---|
174 | readonly = False, |
---|
175 | defaultFactory=list, |
---|
176 | ) |
---|
177 | olevel_pin2 = schema.TextLine( |
---|
178 | title = _(u'2nd Result Checking PIN'), |
---|
179 | required = False, |
---|
180 | readonly = False, |
---|
181 | ) |
---|
182 | olevel_pin_serial2 = schema.TextLine( |
---|
183 | title = _(u'2nd PIN Serial Number'), |
---|
184 | required = False, |
---|
185 | readonly = False, |
---|
186 | ) |
---|
187 | hq_type = schema.Choice( |
---|
188 | title = _(u'Qualification Obtained'), |
---|
189 | required = False, |
---|
190 | readonly = False, |
---|
191 | vocabulary = high_qual, |
---|
192 | ) |
---|
193 | hq_matric_no = schema.TextLine( |
---|
194 | title = _(u'Former Matric Number'), |
---|
195 | required = False, |
---|
196 | readonly = False, |
---|
197 | ) |
---|
198 | hq_degree = schema.Choice( |
---|
199 | title = _(u'Class of Degree'), |
---|
200 | required = False, |
---|
201 | readonly = False, |
---|
202 | vocabulary = high_grade, |
---|
203 | ) |
---|
204 | hq_school = schema.TextLine( |
---|
205 | title = _(u'Institution Attended'), |
---|
206 | required = False, |
---|
207 | readonly = False, |
---|
208 | ) |
---|
209 | hq_session = schema.TextLine( |
---|
210 | title = _(u'Years Attended'), |
---|
211 | required = False, |
---|
212 | readonly = False, |
---|
213 | ) |
---|
214 | hq_disc = schema.TextLine( |
---|
215 | title = _(u'Discipline'), |
---|
216 | required = False, |
---|
217 | readonly = False, |
---|
218 | ) |
---|
219 | jamb_subjects = schema.Text( |
---|
220 | title = _(u'Subjects and Scores'), |
---|
221 | description = _(u'(one subject with score per line)'), |
---|
222 | required = False, |
---|
223 | ) |
---|
224 | jamb_score = schema.Int( |
---|
225 | title = _(u'Total JAMB Score'), |
---|
226 | required = False, |
---|
227 | ) |
---|
228 | jamb_age = schema.Int( |
---|
229 | title = _(u'Age (provided by JAMB)'), |
---|
230 | required = False, |
---|
231 | ) |
---|
232 | notice = schema.Text( |
---|
233 | title = _(u'Notice'), |
---|
234 | required = False, |
---|
235 | ) |
---|
236 | screening_venue = schema.TextLine( |
---|
237 | title = _(u'Screening Venue'), |
---|
238 | required = False, |
---|
239 | ) |
---|
240 | screening_date = schema.TextLine( |
---|
241 | title = _(u'Screening Date'), |
---|
242 | required = False, |
---|
243 | ) |
---|
244 | screening_score = schema.Int( |
---|
245 | title = _(u'Screening Score (%)'), |
---|
246 | required = False, |
---|
247 | ) |
---|
248 | aggregate = schema.Int( |
---|
249 | title = _(u'Aggregate Score (%)'), |
---|
250 | description = _(u'(average of relative JAMB and PUTME scores)'), |
---|
251 | required = False, |
---|
252 | ) |
---|
253 | result_uploaded = schema.Bool( |
---|
254 | title = _(u'Result uploaded'), |
---|
255 | default = False, |
---|
256 | required = False, |
---|
257 | ) |
---|
258 | student_id = schema.TextLine( |
---|
259 | title = _(u'Student Id'), |
---|
260 | required = False, |
---|
261 | readonly = False, |
---|
262 | ) |
---|
263 | course_admitted = schema.Choice( |
---|
264 | title = _(u'Admitted Course of Study'), |
---|
265 | source = CertificateSource(), |
---|
266 | required = False, |
---|
267 | ) |
---|
268 | locked = schema.Bool( |
---|
269 | title = _(u'Form locked'), |
---|
270 | default = False, |
---|
271 | required = False, |
---|
272 | ) |
---|
273 | |
---|
274 | ICustomUGApplicant[ |
---|
275 | 'sex'].order = IApplicantBaseData['sex'].order |
---|
276 | |
---|
277 | class ICustomPGApplicant(INigeriaPGApplicant): |
---|
278 | """A postgraduate applicant. |
---|
279 | |
---|
280 | This interface defines the least common multiple of all fields |
---|
281 | in pg application forms. In customized forms, fields can be excluded by |
---|
282 | adding them to the PG_OMIT* tuples. |
---|
283 | """ |
---|
284 | |
---|
285 | def grad_year_range(): |
---|
286 | curr_year = datetime.now().year |
---|
287 | return range(curr_year - 10, curr_year + 0) |
---|
288 | |
---|
289 | class ICustomSpecialApplicant(ISpecialApplicant): |
---|
290 | |
---|
291 | carryover_courses = schema.Text( |
---|
292 | title = _(u'Carry-Over Courses'), |
---|
293 | required = False, |
---|
294 | description = _( |
---|
295 | u'Enter course titles if carry-over remedial payment.'), |
---|
296 | ) |
---|
297 | |
---|
298 | department = schema.TextLine( |
---|
299 | title = _(u'Department'), |
---|
300 | required = True, |
---|
301 | readonly = False, |
---|
302 | ) |
---|
303 | |
---|
304 | grad_year = schema.Choice( |
---|
305 | title = _(u'Year of Graduation'), |
---|
306 | required = True, |
---|
307 | values = grad_year_range(), |
---|
308 | readonly = False, |
---|
309 | ) |
---|
310 | |
---|
311 | class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant, |
---|
312 | ICustomSpecialApplicant): |
---|
313 | """An interface for both types of applicants. |
---|
314 | |
---|
315 | Attention: The ICustomPGApplicant field seetings will be overwritten |
---|
316 | by ICustomPGApplicant field settings. If a field is defined |
---|
317 | in both interfaces zope.schema validates only against the |
---|
318 | constraints in ICustomUGApplicant. This does not affect the forms |
---|
319 | since they are build on either ICustomUGApplicant or ICustomPGApplicant. |
---|
320 | """ |
---|
321 | |
---|
322 | def writeLogMessage(view, comment): |
---|
323 | """Adds an INFO message to the log file |
---|
324 | """ |
---|
325 | |
---|
326 | def createStudent(): |
---|
327 | """Create a student object from applicant data |
---|
328 | and copy applicant object. |
---|
329 | """ |
---|
330 | |
---|
331 | class ICustomUGApplicantEdit(ICustomUGApplicant): |
---|
332 | """An undergraduate applicant interface for edit forms. |
---|
333 | |
---|
334 | Here we can repeat the fields from base data and set the |
---|
335 | `required` and `readonly` attributes to True to further restrict |
---|
336 | the data access. Or we can allow only certain certificates to be |
---|
337 | selected by choosing the appropriate source. |
---|
338 | |
---|
339 | We cannot omit fields here. This has to be done in the |
---|
340 | respective form page. |
---|
341 | """ |
---|
342 | email = schema.ASCIILine( |
---|
343 | title = _(u'Email Address'), |
---|
344 | required = True, |
---|
345 | constraint=validate_email, |
---|
346 | ) |
---|
347 | phone = PhoneNumber( |
---|
348 | title = _(u'Phone'), |
---|
349 | description = u'', |
---|
350 | required = True, |
---|
351 | ) |
---|
352 | date_of_birth = FormattedDate( |
---|
353 | title = _(u'Date of Birth'), |
---|
354 | required = True, |
---|
355 | show_year = True, |
---|
356 | ) |
---|
357 | sex = schema.Choice( |
---|
358 | title = _(u'Sex'), |
---|
359 | source = GenderSource(), |
---|
360 | required = True, |
---|
361 | ) |
---|
362 | nationality = schema.Choice( |
---|
363 | source = nats_vocab, |
---|
364 | title = _(u'Nationality'), |
---|
365 | required = True, |
---|
366 | ) |
---|
367 | course1 = schema.Choice( |
---|
368 | title = _(u'1st Choice Course of Study'), |
---|
369 | source = AppCatCertificateSource(), |
---|
370 | required = True, |
---|
371 | ) |
---|
372 | olevel_type = schema.Choice( |
---|
373 | title = _(u'Qualification Obtained'), |
---|
374 | required = True, |
---|
375 | readonly = False, |
---|
376 | vocabulary = exam_types, |
---|
377 | ) |
---|
378 | jamb_subjects = schema.Text( |
---|
379 | title = _(u'Subjects and Scores'), |
---|
380 | description = _(u'(one subject with score per line)'), |
---|
381 | required = False, |
---|
382 | ) |
---|
383 | jamb_reg_number = schema.TextLine( |
---|
384 | title = _(u'JAMB Registration Number'), |
---|
385 | required = False, |
---|
386 | ) |
---|
387 | |
---|
388 | ICustomUGApplicantEdit[ |
---|
389 | 'nationality'].order = ICustomUGApplicant['nationality'].order |
---|
390 | ICustomUGApplicantEdit[ |
---|
391 | 'email'].order = ICustomUGApplicant['email'].order |
---|
392 | ICustomUGApplicantEdit[ |
---|
393 | 'phone'].order = ICustomUGApplicant['phone'].order |
---|
394 | ICustomUGApplicantEdit[ |
---|
395 | 'course1'].order = ICustomUGApplicant['course1'].order |
---|
396 | ICustomUGApplicantEdit[ |
---|
397 | 'date_of_birth'].order = ICustomUGApplicant['date_of_birth'].order |
---|
398 | ICustomUGApplicantEdit[ |
---|
399 | 'sex'].order = ICustomUGApplicant['sex'].order |
---|
400 | ICustomUGApplicantEdit[ |
---|
401 | 'olevel_type'].order = ICustomUGApplicant['olevel_type'].order |
---|
402 | ICustomUGApplicantEdit[ |
---|
403 | 'jamb_subjects'].order = ICustomUGApplicant['jamb_subjects'].order |
---|
404 | ICustomUGApplicantEdit[ |
---|
405 | 'jamb_reg_number'].order = ICustomUGApplicant['jamb_reg_number'].order |
---|
406 | |
---|
407 | class ICustomPGApplicantEdit(INigeriaPGApplicantEdit): |
---|
408 | """A postgraduate applicant interface for editing. |
---|
409 | |
---|
410 | Here we can repeat the fields from base data and set the |
---|
411 | `required` and `readonly` attributes to True to further restrict |
---|
412 | the data access. Or we can allow only certain certificates to be |
---|
413 | selected by choosing the appropriate source. |
---|
414 | |
---|
415 | We cannot omit fields here. This has to be done in the |
---|
416 | respective form page. |
---|
417 | """ |
---|
418 | |
---|
419 | class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment): |
---|
420 | """An applicant payment via payment gateways. |
---|
421 | |
---|
422 | """ |
---|
423 | |
---|
424 | class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo): |
---|
425 | """Representation of an applicant. |
---|
426 | |
---|
427 | Skip regular reg_number validation if reg_number is used for finding |
---|
428 | the applicant object. |
---|
429 | """ |
---|