source: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/interfaces.py @ 17865

Last change on this file since 17865 was 17744, checked in by Henrik Bettermann, 8 months ago

Email addresses of applicants must be unique.

  • Property svn:keywords set to Id
File size: 17.8 KB
Line 
1## $Id: interfaces.py 17744 2024-04-23 16:13:48Z 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
21from zope import schema
22from zc.sourcefactory.basic import BasicSourceFactory
23from waeup.kofa.applicants.interfaces import (
24    IApplicantBaseData,
25    AppCatCertificateSource, CertificateSource)
26from waeup.kofa.schoolgrades import ResultEntryField
27from waeup.kofa.interfaces import (
28    SimpleKofaVocabulary, academic_sessions_vocab, validate_email,
29    IKofaObject)
30from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber
31from waeup.kofa.schoolgrades import ResultEntryField
32from waeup.kofa.students.vocabularies import nats_vocab, GenderSource
33from waeup.kofa.applicants.interfaces import (
34    contextual_reg_num_source,
35    contextual_email_source,
36    IApplicantRegisterUpdate)
37from kofacustom.nigeria.applicants.interfaces import (
38    LGASource, high_qual, high_grade, exam_types,
39    INigeriaUGApplicant, INigeriaPGApplicant,
40    INigeriaApplicantOnlinePayment,
41    INigeriaUGApplicantEdit,
42    INigeriaApplicantUpdateByRegNo,
43    IPUTMEApplicantEdit,
44    OMIT_DISPLAY_FIELDS
45    )
46from waeup.fceokene.applicants.schools_tpu import SCHOOLS_TPU
47from waeup.fceokene.applicants.schools_utp import SCHOOLS_UTP
48from waeup.fceokene.interfaces import MessageFactory as _
49
50BEC_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS
51BEC_OMIT_PDF_FIELDS = BEC_OMIT_DISPLAY_FIELDS + ('phone',)
52BEC_OMIT_MANAGE_FIELDS = ('special_application',)
53BEC_OMIT_EDIT_FIELDS = BEC_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
54    'student_id', 'notice',
55    'screening_score',
56    'screening_venue',
57    'screening_date',
58    #'jamb_subjects',
59    #'jamb_score',
60    'aggregate')
61
62class TPUCertificateSource(AppCatCertificateSource):
63
64    def getValues(self, context):
65        resultlist = super(TPUCertificateSource, self).getValues(context)
66        return [i for i in resultlist if i.code.startswith('NCE')]
67
68class UTPCertificateSource(AppCatCertificateSource):
69
70    def getValues(self, context):
71        resultlist = super(UTPCertificateSource, self).getValues(context)
72        return [i for i in resultlist if i.code.startswith('BED')]
73
74class TPUSchoolSource(BasicSourceFactory):
75    """A source that delivers all kinds of TPU schools.
76    """
77    def getValues(self):
78        sorted_items = sorted(
79            SCHOOLS_TPU.items(),
80            key=lambda element: element[1][0] + element[1][1] +element[1][2])
81        return [item[0] for item in sorted_items]
82
83    def getToken(self, value):
84        return value
85
86    def getTitle(self, value):
87        if not SCHOOLS_TPU.get(value, None):
88            return u"none-existent"
89        return u"%s: %s -- %s" % (
90            SCHOOLS_TPU[value][0],
91            SCHOOLS_TPU[value][1],
92            SCHOOLS_TPU[value][2],)
93
94class UTPSchoolSource(BasicSourceFactory):
95    """A source that delivers all kinds of UTP schools.
96    """
97    def getValues(self):
98        sorted_items = sorted(
99            SCHOOLS_UTP.items(),
100            key=lambda element: element[1][0] + element[1][1] +element[1][2])
101        return [item[0] for item in sorted_items]
102
103    def getToken(self, value):
104        return value
105
106    def getTitle(self, value):
107        if not SCHOOLS_UTP.get(value, None):
108            return u"none-existent"
109        return u"%s: %s -- %s" % (
110            SCHOOLS_UTP[value][0],
111            SCHOOLS_UTP[value][1],
112            SCHOOLS_UTP[value][2],)
113
114class ITPURegistration(IKofaObject):
115    """A TPU registrant.
116    """
117
118    suspended = schema.Bool(
119        title = _(u'Account suspended'),
120        default = False,
121        required = False,
122        )
123
124    locked = schema.Bool(
125        title = _(u'Form locked'),
126        default = False,
127        required = False,
128        )
129
130    applicant_id = schema.TextLine(
131        title = _(u'Applicant Id'),
132        required = False,
133        readonly = False,
134        )
135
136    reg_number = schema.TextLine(
137        title = _(u'Registration Number'),
138        required = False,
139        readonly = False,
140        )
141
142    matric_number = schema.TextLine(
143        title = _(u'Matriculation Number'),
144        required = False,
145        readonly = False,
146        )
147
148    firstname = schema.TextLine(
149        title = _(u'First Name'),
150        required = True,
151        )
152
153    middlename = schema.TextLine(
154        title = _(u'Middle Name'),
155        required = False,
156        )
157
158    lastname = schema.TextLine(
159        title = _(u'Last Name (Surname)'),
160        required = True,
161        )
162
163    email = TextLineChoice(
164        title = _(u'Email Address'),
165        required = True,
166        constraint=validate_email,
167        source = contextual_email_source,
168        )
169
170    phone = PhoneNumber(
171        title = _(u'Phone'),
172        description = u'',
173        required = False,
174        )
175
176    perm_address = schema.Text(
177        title = _(u'Home Address'),
178        required = False,
179        readonly = False,
180        )
181
182    lga = schema.Choice(
183        source = LGASource(),
184        title = _(u'State/LGA'),
185        required = False,
186        )
187
188    subj_comb = schema.Choice(
189        title = _(u'Subject Combination'),
190        source = TPUCertificateSource(),
191        required = False,
192        )
193
194    school_tpu = schema.Choice(
195        title = _(u'1st Choice TPZ and School'),
196        source = TPUSchoolSource(),
197        required = False,
198        )
199
200class IUTPRegistration(IKofaObject):
201    """An UTP registrant.
202    """
203
204    suspended = schema.Bool(
205        title = _(u'Account suspended'),
206        default = False,
207        required = False,
208        )
209
210    locked = schema.Bool(
211        title = _(u'Form locked'),
212        default = False,
213        required = False,
214        )
215
216    applicant_id = schema.TextLine(
217        title = _(u'Applicant Id'),
218        required = False,
219        readonly = False,
220        )
221
222    reg_number = schema.TextLine(
223        title = _(u'Registration Number'),
224        required = False,
225        readonly = False,
226        )
227
228    matric_number = schema.TextLine(
229        title = _(u'Matriculation Number'),
230        required = False,
231        readonly = False,
232        )
233
234    firstname = schema.TextLine(
235        title = _(u'First Name'),
236        required = True,
237        )
238
239    middlename = schema.TextLine(
240        title = _(u'Middle Name'),
241        required = False,
242        )
243
244    lastname = schema.TextLine(
245        title = _(u'Last Name (Surname)'),
246        required = True,
247        )
248
249    email = TextLineChoice(
250        title = _(u'Email Address'),
251        required = True,
252        constraint=validate_email,
253        source = contextual_email_source,
254        )
255
256    phone = PhoneNumber(
257        title = _(u'Phone'),
258        description = u'',
259        required = False,
260        )
261
262    perm_address = schema.Text(
263        title = _(u'Home Address'),
264        required = False,
265        readonly = False,
266        )
267
268    lga = schema.Choice(
269        source = LGASource(),
270        title = _(u'State/LGA'),
271        required = False,
272        )
273
274    subj_comb = schema.Choice(
275        title = _(u'Subject Combination'),
276        source = UTPCertificateSource(),
277        required = False,
278        )
279
280    school_utp = schema.Choice(
281        title = _(u'1st Choice UTP and School'),
282        source = UTPSchoolSource(),
283        required = False,
284        )
285
286class ICustomUGApplicant(INigeriaUGApplicant):
287    """An undergraduate applicant.
288
289    This interface defines the least common multiple of all fields
290    in ug application forms. In customized forms, fields can be excluded by
291    adding them to the OMIT* tuples.
292    """
293
294    email = TextLineChoice(
295        title = _(u'Email Address'),
296        required = True,
297        constraint=validate_email,
298        source = contextual_email_source,
299        )
300
301    nationality = schema.Choice(
302        source = nats_vocab,
303        title = _(u'Nationality'),
304        required = True,
305        )
306    lga = schema.Choice(
307        source = LGASource(),
308        title = _(u'State/LGA (Nigerians only)'),
309        required = False,
310        )
311    #perm_address = schema.Text(
312    #    title = _(u'Permanent Address'),
313    #    required = False,
314    #    )
315    course1 = schema.Choice(
316        title = _(u'1st Choice Course of Study'),
317        source = AppCatCertificateSource(),
318        required = False,
319        )
320    course2 = schema.Choice(
321        title = _(u'2nd Choice Course of Study'),
322        source = AppCatCertificateSource(),
323        required = False,
324        )
325    olevel_type = schema.Choice(
326        title = _(u'1st Qualification Obtained'),
327        required = False,
328        readonly = False,
329        vocabulary = exam_types,
330        )
331    olevel_school = schema.TextLine(
332        title = _(u'1st Institution Attended'),
333        required = False,
334        readonly = False,
335        )
336    olevel_exam_number = schema.TextLine(
337        title = _(u'1st Exam Number'),
338        required = False,
339        readonly = False,
340        )
341    olevel_exam_date = FormattedDate(
342        title = _(u'1st Exam Date'),
343        required = False,
344        readonly = False,
345        show_year = True,
346        )
347    olevel_results = schema.List(
348        title = _(u'1st Exam Results'),
349        value_type = ResultEntryField(),
350        required = False,
351        readonly = False,
352        defaultFactory=list,
353        )
354    olevel_type2 = schema.Choice(
355        title = _(u'2nd Qualification Obtained'),
356        required = False,
357        readonly = False,
358        vocabulary = exam_types,
359        )
360    olevel_school2 = schema.TextLine(
361        title = _(u'2nd Institution Attended'),
362        required = False,
363        readonly = False,
364        )
365    olevel_exam_number2 = schema.TextLine(
366        title = _(u'2nd Exam Number'),
367        required = False,
368        readonly = False,
369        )
370    olevel_exam_date2 = FormattedDate(
371        title = _(u'2nd Exam Date'),
372        required = False,
373        readonly = False,
374        show_year = True,
375        )
376    olevel_results2 = schema.List(
377        title = _(u'2nd Exam Results'),
378        value_type = ResultEntryField(),
379        required = False,
380        readonly = False,
381        defaultFactory=list,
382        )
383    hq_type = schema.Choice(
384        title = _(u'Qualification Obtained'),
385        required = False,
386        readonly = False,
387        vocabulary = high_qual,
388        )
389    hq_matric_no = schema.TextLine(
390        title = _(u'Former Matric Number'),
391        required = False,
392        readonly = False,
393        )
394    hq_degree = schema.Choice(
395        title = _(u'Class of Degree'),
396        required = False,
397        readonly = False,
398        vocabulary = high_grade,
399        )
400    hq_school = schema.TextLine(
401        title = _(u'Institution Attended'),
402        required = False,
403        readonly = False,
404        )
405    hq_session = schema.TextLine(
406        title = _(u'Years Attended'),
407        required = False,
408        readonly = False,
409        )
410    hq_disc = schema.TextLine(
411        title = _(u'Discipline'),
412        required = False,
413        readonly = False,
414        )
415    jamb_subjects = schema.Text(
416        title = _(u'Subjects and Scores'),
417        description = _(u'(one subject with score per line)'),
418        required = False,
419        )
420    jamb_score = schema.Int(
421        title = _(u'Total JAMB Score'),
422        required = False,
423        )
424    jamb_reg_number = schema.TextLine(
425        title = _(u'JAMB Registration Number'),
426        required = False,
427        )
428    notice = schema.Text(
429        title = _(u'Notice'),
430        required = False,
431        )
432    screening_venue = schema.TextLine(
433        title = _(u'Screening Venue'),
434        required = False,
435        )
436    screening_date = schema.TextLine(
437        title = _(u'Screening Date'),
438        required = False,
439        )
440    screening_score = schema.Int(
441        title = _(u'Screening Score (%)'),
442        required = False,
443        )
444    aggregate = schema.Int(
445        title = _(u'Aggregate Score (%)'),
446        description = _(u'(average of relative JAMB and PUTME scores)'),
447        required = False,
448        )
449    result_uploaded = schema.Bool(
450        title = _(u'Result uploaded'),
451        default = False,
452        required = False,
453        )
454    student_id = schema.TextLine(
455        title = _(u'Student Id'),
456        required = False,
457        readonly = False,
458        )
459    course_admitted = schema.Choice(
460        title = _(u'Admitted Course of Study'),
461        source = CertificateSource(),
462        required = False,
463        )
464    locked = schema.Bool(
465        title = _(u'Form locked'),
466        default = False,
467        required = False,
468        )
469
470ICustomUGApplicant[
471    'email'].order =  INigeriaUGApplicant['email'].order
472
473class ICustomPGApplicant(INigeriaPGApplicant):
474    """A postgraduate applicant.
475
476    This interface defines the least common multiple of all fields
477    in pg application forms. In customized forms, fields can be excluded by
478    adding them to the PG_OMIT* tuples.
479    """
480
481    email = TextLineChoice(
482        title = _(u'Email Address'),
483        required = True,
484        constraint=validate_email,
485        source = contextual_email_source,
486        )
487
488ICustomPGApplicant[
489    'email'].order =  INigeriaPGApplicant['email'].order
490
491class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant,
492    ITPURegistration, IUTPRegistration):
493    """An interface for all types of applicants.
494
495    Attention: The ICustomPGApplicant field seetings will be overwritten
496    by ICustomPGApplicant field settings. If a field is defined
497    in both interfaces zope.schema validates only against the
498    constraints in ICustomUGApplicant. This does not affect the forms
499    since they are build on either ICustomUGApplicant or ICustomPGApplicant.
500    """
501
502    def writeLogMessage(view, comment):
503        """Adds an INFO message to the log file
504        """
505
506    def createStudent():
507        """Create a student object from applicatnt data
508        and copy applicant object.
509        """
510
511class ICustomUGApplicantEdit(ICustomUGApplicant):
512    """An undergraduate applicant interface for edit forms.
513
514    Here we can repeat the fields from base data and set the
515    `required` and `readonly` attributes to True to further restrict
516    the data access. Or we can allow only certain certificates to be
517    selected by choosing the appropriate source.
518
519    We cannot omit fields here. This has to be done in the
520    respective form page.
521    """
522
523    email = TextLineChoice(
524        title = _(u'Email Address'),
525        required = True,
526        constraint=validate_email,
527        source = contextual_email_source,
528        )
529    date_of_birth = FormattedDate(
530        title = _(u'Date of Birth'),
531        required = True,
532        show_year = True,
533        )
534    jamb_reg_number = schema.TextLine(
535        title = _(u'JAMB Registration Number'),
536        required = True,
537        )
538    course1 = schema.Choice(
539        title = _(u'1st Choice Course of Study'),
540        source = AppCatCertificateSource(),
541        required = True,
542        )
543
544ICustomUGApplicantEdit[
545    'date_of_birth'].order =  ICustomUGApplicant['date_of_birth'].order
546ICustomUGApplicantEdit[
547    'email'].order =  ICustomUGApplicant['email'].order
548ICustomUGApplicantEdit[
549    'jamb_reg_number'].order =  ICustomUGApplicant['jamb_reg_number'].order
550ICustomUGApplicantEdit[
551    'course1'].order =  ICustomUGApplicant['course1'].order
552
553class ICustomPGApplicantEdit(ICustomPGApplicant):
554    """A postgraduate applicant interface for editing.
555
556    Here we can repeat the fields from base data and set the
557    `required` and `readonly` attributes to True to further restrict
558    the data access. Or we can allow only certain certificates to be
559    selected by choosing the appropriate source.
560
561    We cannot omit fields here. This has to be done in the
562    respective form page.
563    """
564
565    email = TextLineChoice(
566        title = _(u'Email Address'),
567        required = True,
568        constraint=validate_email,
569        source = contextual_email_source,
570        )
571    date_of_birth = FormattedDate(
572        title = _(u'Date of Birth'),
573        required = True,
574        show_year = True,
575        )
576
577ICustomPGApplicantEdit[
578    'date_of_birth'].order =  ICustomPGApplicant['date_of_birth'].order
579ICustomPGApplicantEdit[
580    'email'].order =  ICustomPGApplicant['email'].order
581
582
583class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment):
584    """An applicant payment via payment gateways.
585
586    """
587
588class IPUTMEApplicantEdit(IPUTMEApplicantEdit):
589    """An undergraduate applicant interface for editing.
590
591    Here we can repeat the fields from base data and set the
592    `required` and `readonly` attributes to True to further restrict
593    the data access. Or we can allow only certain certificates to be
594    selected by choosing the appropriate source.
595
596    We cannot omit fields here. This has to be done in the
597    respective form page.
598    """
599
600class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo):
601    """Representation of an applicant.
602
603    Skip regular reg_number validation if reg_number is used for finding
604    the applicant object.
605    """
606
607class ICustomApplicantRegisterUpdate(IApplicantRegisterUpdate):
608    """This is a representation of an applicant for first-time registration.
609    This interface is used when applicants use the registration page to
610    update their records.
611    """
612
613    email = TextLineChoice(
614        title = _(u'Email Address'),
615        required = False,
616        constraint=validate_email,
617        source = contextual_email_source,
618        )
619
Note: See TracBrowser for help on using the repository browser.