1 | ## $Id: interfaces.py 9462 2012-10-30 07:17:17Z 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 zope import schema |
---|
22 | from waeup.kofa.applicants.interfaces import ( |
---|
23 | contextual_reg_num_source, |
---|
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 |
---|
30 | from waeup.kofa.students.vocabularies import nats_vocab, GenderSource |
---|
31 | from kofacustom.nigeria.interfaces import ( |
---|
32 | LGASource, high_qual, high_grade, exam_types) |
---|
33 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
34 | from kofacustom.nigeria.payments.interfaces import INigeriaOnlinePayment |
---|
35 | |
---|
36 | # Fields to be omitted in all display forms. course_admitted is |
---|
37 | # rendered separately. |
---|
38 | |
---|
39 | OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted', |
---|
40 | 'result_uploaded', 'suspended') |
---|
41 | |
---|
42 | # UG students are all undergraduate students. |
---|
43 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS |
---|
44 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
45 | UG_OMIT_MANAGE_FIELDS = () |
---|
46 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
47 | 'student_id', 'notice', |
---|
48 | 'screening_score', 'screening_venue', |
---|
49 | 'screening_date', 'jamb_subjects', |
---|
50 | 'jamb_score', 'aggregate') |
---|
51 | |
---|
52 | # PUTME is a subgroup of UG with the same interface. |
---|
53 | PUTME_OMIT_FIELDS = ( |
---|
54 | 'hq_type', 'hq_matric_no', |
---|
55 | 'hq_degree', 'hq_school', |
---|
56 | 'hq_session', 'hq_disc',) |
---|
57 | PUTME_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + PUTME_OMIT_FIELDS |
---|
58 | PUTME_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + PUTME_OMIT_FIELDS |
---|
59 | PUTME_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + PUTME_OMIT_FIELDS + ( |
---|
60 | 'firstname', 'middlename', 'lastname', 'sex', |
---|
61 | 'course1', 'lga') |
---|
62 | PUTME_OMIT_PDF_FIELDS = PUTME_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
63 | PUTME_OMIT_RESULT_SLIP_FIELDS = PUTME_OMIT_DISPLAY_FIELDS + ( |
---|
64 | 'phone', |
---|
65 | 'date_of_birth', 'sex', |
---|
66 | 'nationality', 'lga', #'perm_address', |
---|
67 | 'course2', 'screening_venue', |
---|
68 | 'screening_date') |
---|
69 | |
---|
70 | # PUDE is a subgroup of UG with the same interface. |
---|
71 | PUDE_OMIT_FIELDS = ( |
---|
72 | 'jamb_subjects','jamb_score', 'aggregate') |
---|
73 | PUDE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + PUDE_OMIT_FIELDS |
---|
74 | PUDE_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + PUDE_OMIT_FIELDS |
---|
75 | PUDE_OMIT_EDIT_FIELDS = set(UG_OMIT_EDIT_FIELDS + PUDE_OMIT_FIELDS + ( |
---|
76 | 'firstname', 'middlename', 'lastname', 'sex', |
---|
77 | 'course1', 'lga')) |
---|
78 | PUDE_OMIT_PDF_FIELDS = PUDE_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
79 | PUDE_OMIT_RESULT_SLIP_FIELDS = PUDE_OMIT_DISPLAY_FIELDS + ( |
---|
80 | 'phone', |
---|
81 | 'date_of_birth', 'sex', |
---|
82 | 'nationality', 'lga', #'perm_address', |
---|
83 | 'course2', 'screening_venue', |
---|
84 | 'screening_date') |
---|
85 | |
---|
86 | # PG has its own interface |
---|
87 | PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS |
---|
88 | PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
89 | PG_OMIT_MANAGE_FIELDS = () |
---|
90 | PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + PG_OMIT_DISPLAY_FIELDS + ( |
---|
91 | 'student_id', 'notice', |
---|
92 | 'screening_score', 'screening_venue', |
---|
93 | 'screening_date',) |
---|
94 | |
---|
95 | class INigeriaUGApplicant(IApplicantBaseData): |
---|
96 | """An undergraduate applicant. |
---|
97 | |
---|
98 | This interface defines the least common multiple of all fields |
---|
99 | in ug application forms. In customized forms, fields can be excluded by |
---|
100 | adding them to the UG_OMIT* tuples. |
---|
101 | """ |
---|
102 | |
---|
103 | nationality = schema.Choice( |
---|
104 | source = nats_vocab, |
---|
105 | title = _(u'Nationality'), |
---|
106 | required = True, |
---|
107 | ) |
---|
108 | lga = schema.Choice( |
---|
109 | source = LGASource(), |
---|
110 | title = _(u'State/LGA (Nigerians only)'), |
---|
111 | required = False, |
---|
112 | ) |
---|
113 | #perm_address = schema.Text( |
---|
114 | # title = _(u'Permanent Address'), |
---|
115 | # required = False, |
---|
116 | # ) |
---|
117 | course1 = schema.Choice( |
---|
118 | title = _(u'1st Choice Course of Study'), |
---|
119 | source = AppCatCertificateSource(), |
---|
120 | required = True, |
---|
121 | ) |
---|
122 | course2 = schema.Choice( |
---|
123 | title = _(u'2nd Choice Course of Study'), |
---|
124 | source = AppCatCertificateSource(), |
---|
125 | required = False, |
---|
126 | ) |
---|
127 | hq_type = schema.Choice( |
---|
128 | title = _(u'Qualification Obtained'), |
---|
129 | required = False, |
---|
130 | readonly = False, |
---|
131 | vocabulary = high_qual, |
---|
132 | ) |
---|
133 | hq_matric_no = schema.TextLine( |
---|
134 | title = _(u'Former Matric Number'), |
---|
135 | required = False, |
---|
136 | readonly = False, |
---|
137 | ) |
---|
138 | hq_degree = schema.Choice( |
---|
139 | title = _(u'Class of Degree'), |
---|
140 | required = False, |
---|
141 | readonly = False, |
---|
142 | vocabulary = high_grade, |
---|
143 | ) |
---|
144 | hq_school = schema.TextLine( |
---|
145 | title = _(u'Institution Attended'), |
---|
146 | required = False, |
---|
147 | readonly = False, |
---|
148 | ) |
---|
149 | hq_session = schema.TextLine( |
---|
150 | title = _(u'Years Attended'), |
---|
151 | required = False, |
---|
152 | readonly = False, |
---|
153 | ) |
---|
154 | hq_disc = schema.TextLine( |
---|
155 | title = _(u'Discipline'), |
---|
156 | required = False, |
---|
157 | readonly = False, |
---|
158 | ) |
---|
159 | jamb_subjects = schema.Text( |
---|
160 | title = _(u'Subjects and Scores'), |
---|
161 | required = False, |
---|
162 | ) |
---|
163 | jamb_score = schema.Int( |
---|
164 | title = _(u'Total JAMB Score'), |
---|
165 | required = False, |
---|
166 | ) |
---|
167 | notice = schema.Text( |
---|
168 | title = _(u'Notice'), |
---|
169 | required = False, |
---|
170 | ) |
---|
171 | screening_venue = schema.TextLine( |
---|
172 | title = _(u'Screening Venue'), |
---|
173 | required = False, |
---|
174 | ) |
---|
175 | screening_date = schema.TextLine( |
---|
176 | title = _(u'Screening Date'), |
---|
177 | required = False, |
---|
178 | ) |
---|
179 | screening_score = schema.Int( |
---|
180 | title = _(u'Screening Score (%)'), |
---|
181 | required = False, |
---|
182 | ) |
---|
183 | aggregate = schema.Int( |
---|
184 | title = _(u'Aggregate Score (%)'), |
---|
185 | description = _(u'(average of relative JAMB and PUTME scores)'), |
---|
186 | required = False, |
---|
187 | ) |
---|
188 | result_uploaded = schema.Bool( |
---|
189 | title = _(u'Result uploaded'), |
---|
190 | default = False, |
---|
191 | ) |
---|
192 | student_id = schema.TextLine( |
---|
193 | title = _(u'Student Id'), |
---|
194 | required = False, |
---|
195 | readonly = False, |
---|
196 | ) |
---|
197 | course_admitted = schema.Choice( |
---|
198 | title = _(u'Admitted Course of Study'), |
---|
199 | source = CertificateSource(), |
---|
200 | required = False, |
---|
201 | ) |
---|
202 | locked = schema.Bool( |
---|
203 | title = _(u'Form locked'), |
---|
204 | default = False, |
---|
205 | ) |
---|
206 | |
---|
207 | class INigeriaPGApplicant(IApplicantBaseData): |
---|
208 | """A postgraduate applicant. |
---|
209 | |
---|
210 | This interface defines the least common multiple of all fields |
---|
211 | in pg application forms. In customized forms, fields can be excluded by |
---|
212 | adding them to the PG_OMIT* tuples. |
---|
213 | """ |
---|
214 | |
---|
215 | nationality = schema.Choice( |
---|
216 | source = nats_vocab, |
---|
217 | title = _(u'Nationality'), |
---|
218 | required = True, |
---|
219 | ) |
---|
220 | lga = schema.Choice( |
---|
221 | source = LGASource(), |
---|
222 | title = _(u'State/LGA (Nigerians only)'), |
---|
223 | required = False, |
---|
224 | ) |
---|
225 | #perm_address = schema.Text( |
---|
226 | # title = _(u'Permanent Address'), |
---|
227 | # required = False, |
---|
228 | # ) |
---|
229 | course1 = schema.Choice( |
---|
230 | title = _(u'1st Choice Course of Study'), |
---|
231 | source = AppCatCertificateSource(), |
---|
232 | required = True, |
---|
233 | ) |
---|
234 | course2 = schema.Choice( |
---|
235 | title = _(u'2nd Choice Course of Study'), |
---|
236 | source = AppCatCertificateSource(), |
---|
237 | required = False, |
---|
238 | ) |
---|
239 | hq_type = schema.Choice( |
---|
240 | title = _(u'Qualification Obtained'), |
---|
241 | required = False, |
---|
242 | readonly = False, |
---|
243 | vocabulary = high_qual, |
---|
244 | ) |
---|
245 | hq_matric_no = schema.TextLine( |
---|
246 | title = _(u'Former Matric Number'), |
---|
247 | required = False, |
---|
248 | readonly = False, |
---|
249 | ) |
---|
250 | hq_degree = schema.Choice( |
---|
251 | title = _(u'Class of Degree'), |
---|
252 | required = False, |
---|
253 | readonly = False, |
---|
254 | vocabulary = high_grade, |
---|
255 | ) |
---|
256 | hq_school = schema.TextLine( |
---|
257 | title = _(u'Institution Attended'), |
---|
258 | required = False, |
---|
259 | readonly = False, |
---|
260 | ) |
---|
261 | hq_session = schema.TextLine( |
---|
262 | title = _(u'Years Attended'), |
---|
263 | required = False, |
---|
264 | readonly = False, |
---|
265 | ) |
---|
266 | hq_disc = schema.TextLine( |
---|
267 | title = _(u'Discipline'), |
---|
268 | required = False, |
---|
269 | readonly = False, |
---|
270 | ) |
---|
271 | pp_school = schema.Choice( |
---|
272 | title = _(u'Qualification Obtained'), |
---|
273 | required = False, |
---|
274 | readonly = False, |
---|
275 | vocabulary = exam_types, |
---|
276 | ) |
---|
277 | presently_inst = schema.TextLine( |
---|
278 | title = _(u'If yes, name of institution'), |
---|
279 | required = False, |
---|
280 | readonly = False, |
---|
281 | ) |
---|
282 | nysc_year = schema.Int( |
---|
283 | title = _(u'Nysc Year'), |
---|
284 | required = False, |
---|
285 | readonly = False, |
---|
286 | ) |
---|
287 | nysc_lga = schema.Choice( |
---|
288 | source = LGASource(), |
---|
289 | title = _(u'Nysc Location'), |
---|
290 | required = False, |
---|
291 | ) |
---|
292 | employer = schema.TextLine( |
---|
293 | title = _(u'Employer'), |
---|
294 | required = False, |
---|
295 | readonly = False, |
---|
296 | ) |
---|
297 | emp_position = schema.TextLine( |
---|
298 | title = _(u'Employer Position'), |
---|
299 | required = False, |
---|
300 | readonly = False, |
---|
301 | ) |
---|
302 | emp_start = FormattedDate( |
---|
303 | title = _(u'Start Date'), |
---|
304 | required = False, |
---|
305 | readonly = False, |
---|
306 | show_year = True, |
---|
307 | ) |
---|
308 | emp_end = FormattedDate( |
---|
309 | title = _(u'End Date'), |
---|
310 | required = False, |
---|
311 | readonly = False, |
---|
312 | show_year = True, |
---|
313 | ) |
---|
314 | emp_reason = schema.TextLine( |
---|
315 | title = _(u'Reason for Leaving'), |
---|
316 | required = False, |
---|
317 | readonly = False, |
---|
318 | ) |
---|
319 | employer2 = schema.TextLine( |
---|
320 | title = _(u'2nd Employer'), |
---|
321 | required = False, |
---|
322 | readonly = False, |
---|
323 | ) |
---|
324 | emp2_position = schema.TextLine( |
---|
325 | title = _(u'2nd Employer Position'), |
---|
326 | required = False, |
---|
327 | readonly = False, |
---|
328 | ) |
---|
329 | emp2_start = FormattedDate( |
---|
330 | title = _(u'Start Date'), |
---|
331 | required = False, |
---|
332 | readonly = False, |
---|
333 | show_year = True, |
---|
334 | ) |
---|
335 | emp2_end = FormattedDate( |
---|
336 | title = _(u'End Date'), |
---|
337 | required = False, |
---|
338 | readonly = False, |
---|
339 | show_year = True, |
---|
340 | ) |
---|
341 | emp2_reason = schema.TextLine( |
---|
342 | title = _(u'Reason for Leaving'), |
---|
343 | required = False, |
---|
344 | readonly = False, |
---|
345 | ) |
---|
346 | notice = schema.Text( |
---|
347 | title = _(u'Notice'), |
---|
348 | required = False, |
---|
349 | readonly = False, |
---|
350 | ) |
---|
351 | screening_venue = schema.TextLine( |
---|
352 | title = _(u'Screening Venue'), |
---|
353 | required = False, |
---|
354 | ) |
---|
355 | screening_date = schema.TextLine( |
---|
356 | title = _(u'Screening Date'), |
---|
357 | required = False, |
---|
358 | ) |
---|
359 | screening_score = schema.Int( |
---|
360 | title = _(u'Screening Score (%)'), |
---|
361 | required = False, |
---|
362 | ) |
---|
363 | student_id = schema.TextLine( |
---|
364 | title = _(u'Student Id'), |
---|
365 | required = False, |
---|
366 | readonly = False, |
---|
367 | ) |
---|
368 | course_admitted = schema.Choice( |
---|
369 | title = _(u'Admitted Course of Study'), |
---|
370 | source = CertificateSource(), |
---|
371 | required = False, |
---|
372 | readonly = False, |
---|
373 | ) |
---|
374 | locked = schema.Bool( |
---|
375 | title = _(u'Form locked'), |
---|
376 | default = False, |
---|
377 | ) |
---|
378 | |
---|
379 | class INigeriaApplicant(INigeriaUGApplicant, INigeriaPGApplicant): |
---|
380 | """An interface for both types of applicants. |
---|
381 | |
---|
382 | Attention: The INigeriaPGApplicant field seetings will be overwritten |
---|
383 | by INigeriaPGApplicant field settings. If a field is defined |
---|
384 | in both interfaces zope.schema validates only against the |
---|
385 | constraints in INigeriaUGApplicant. This does not affect the forms |
---|
386 | since they are build on either INigeriaUGApplicant or INigeriaPGApplicant. |
---|
387 | """ |
---|
388 | |
---|
389 | def writeLogMessage(view, comment): |
---|
390 | """Adds an INFO message to the log file |
---|
391 | """ |
---|
392 | |
---|
393 | def createStudent(): |
---|
394 | """Create a student object from applicant data |
---|
395 | and copy applicant object. |
---|
396 | """ |
---|
397 | |
---|
398 | class INigeriaUGApplicantEdit(INigeriaUGApplicant): |
---|
399 | """An undergraduate applicant interface for edit forms. |
---|
400 | |
---|
401 | Here we can repeat the fields from base data and set the |
---|
402 | `required` and `readonly` attributes to True to further restrict |
---|
403 | the data access. Or we can allow only certain certificates to be |
---|
404 | selected by choosing the appropriate source. |
---|
405 | |
---|
406 | We cannot omit fields here. This has to be done in the |
---|
407 | respective form page. |
---|
408 | """ |
---|
409 | |
---|
410 | email = schema.ASCIILine( |
---|
411 | title = _(u'Email Address'), |
---|
412 | required = True, |
---|
413 | constraint=validate_email, |
---|
414 | ) |
---|
415 | date_of_birth = FormattedDate( |
---|
416 | title = _(u'Date of Birth'), |
---|
417 | required = True, |
---|
418 | show_year = True, |
---|
419 | ) |
---|
420 | |
---|
421 | INigeriaUGApplicantEdit[ |
---|
422 | 'date_of_birth'].order = INigeriaUGApplicant['date_of_birth'].order |
---|
423 | INigeriaUGApplicantEdit[ |
---|
424 | 'email'].order = INigeriaUGApplicant['email'].order |
---|
425 | |
---|
426 | class INigeriaPGApplicantEdit(INigeriaPGApplicant): |
---|
427 | """A postgraduate applicant interface for editing. |
---|
428 | |
---|
429 | Here we can repeat the fields from base data and set the |
---|
430 | `required` and `readonly` attributes to True to further restrict |
---|
431 | the data access. Or we can allow only certain certificates to be |
---|
432 | selected by choosing the appropriate source. |
---|
433 | |
---|
434 | We cannot omit fields here. This has to be done in the |
---|
435 | respective form page. |
---|
436 | """ |
---|
437 | |
---|
438 | email = schema.ASCIILine( |
---|
439 | title = _(u'Email Address'), |
---|
440 | required = True, |
---|
441 | constraint=validate_email, |
---|
442 | ) |
---|
443 | date_of_birth = FormattedDate( |
---|
444 | title = _(u'Date of Birth'), |
---|
445 | required = True, |
---|
446 | show_year = True, |
---|
447 | ) |
---|
448 | |
---|
449 | INigeriaPGApplicantEdit[ |
---|
450 | 'date_of_birth'].order = INigeriaPGApplicant['date_of_birth'].order |
---|
451 | INigeriaPGApplicantEdit[ |
---|
452 | 'email'].order = INigeriaPGApplicant['email'].order |
---|
453 | |
---|
454 | class INigeriaApplicantOnlinePayment(INigeriaOnlinePayment): |
---|
455 | """An applicant payment via payment gateways. |
---|
456 | |
---|
457 | """ |
---|
458 | |
---|
459 | class IPUTMEApplicantEdit(INigeriaUGApplicant): |
---|
460 | """An undergraduate applicant interface for editing. |
---|
461 | |
---|
462 | Here we can repeat the fields from base data and set the |
---|
463 | `required` and `readonly` attributes to True to further restrict |
---|
464 | the data access. Or we can allow only certain certificates to be |
---|
465 | selected by choosing the appropriate source. |
---|
466 | |
---|
467 | We cannot omit fields here. This has to be done in the |
---|
468 | respective form page. |
---|
469 | """ |
---|
470 | email = schema.ASCIILine( |
---|
471 | title = _(u'Email Address'), |
---|
472 | required = True, |
---|
473 | constraint=validate_email, |
---|
474 | ) |
---|
475 | date_of_birth = FormattedDate( |
---|
476 | title = _(u'Date of Birth'), |
---|
477 | required = True, |
---|
478 | show_year = True, |
---|
479 | ) |
---|
480 | |
---|
481 | IPUTMEApplicantEdit[ |
---|
482 | 'date_of_birth'].order = INigeriaUGApplicant['date_of_birth'].order |
---|
483 | IPUTMEApplicantEdit[ |
---|
484 | 'email'].order = INigeriaUGApplicant['email'].order |
---|
485 | |
---|
486 | class INigeriaApplicantUpdateByRegNo(INigeriaApplicant): |
---|
487 | """Representation of an applicant. |
---|
488 | |
---|
489 | Skip regular reg_number validation if reg_number is used for finding |
---|
490 | the applicant object. |
---|
491 | """ |
---|
492 | reg_number = schema.TextLine( |
---|
493 | title = u'Registration Number', |
---|
494 | required = False, |
---|
495 | ) |
---|