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