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

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

Email addresses of applicants must be unique.

  • Property svn:keywords set to Id
File size: 17.8 KB
RevLine 
[7853]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
[8012]21from zope import schema
[13877]22from zc.sourcefactory.basic import BasicSourceFactory
[8051]23from waeup.kofa.applicants.interfaces import (
[8053]24    IApplicantBaseData,
[8051]25    AppCatCertificateSource, CertificateSource)
26from waeup.kofa.schoolgrades import ResultEntryField
[8531]27from waeup.kofa.interfaces import (
[13877]28    SimpleKofaVocabulary, academic_sessions_vocab, validate_email,
29    IKofaObject)
30from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber
[9465]31from waeup.kofa.schoolgrades import ResultEntryField
[8531]32from waeup.kofa.students.vocabularies import nats_vocab, GenderSource
[17744]33from waeup.kofa.applicants.interfaces import (
34    contextual_reg_num_source,
35    contextual_email_source,
36    IApplicantRegisterUpdate)
[8933]37from kofacustom.nigeria.applicants.interfaces import (
38    LGASource, high_qual, high_grade, exam_types,
39    INigeriaUGApplicant, INigeriaPGApplicant,
40    INigeriaApplicantOnlinePayment,
[9497]41    INigeriaUGApplicantEdit,
[8979]42    INigeriaApplicantUpdateByRegNo,
43    IPUTMEApplicantEdit,
[9463]44    OMIT_DISPLAY_FIELDS
[8933]45    )
[16918]46from waeup.fceokene.applicants.schools_tpu import SCHOOLS_TPU
47from waeup.fceokene.applicants.schools_utp import SCHOOLS_UTP
[8460]48from waeup.fceokene.interfaces import MessageFactory as _
[7853]49
[9463]50BEC_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS
51BEC_OMIT_PDF_FIELDS = BEC_OMIT_DISPLAY_FIELDS + ('phone',)
[10852]52BEC_OMIT_MANAGE_FIELDS = ('special_application',)
[9463]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
[16854]62class TPUCertificateSource(AppCatCertificateSource):
63
64    def getValues(self, context):
65        resultlist = super(TPUCertificateSource, self).getValues(context)
[16924]66        return [i for i in resultlist if i.code.startswith('NCE')]
[16854]67
[16918]68class UTPCertificateSource(AppCatCertificateSource):
69
70    def getValues(self, context):
71        resultlist = super(UTPCertificateSource, self).getValues(context)
[16924]72        return [i for i in resultlist if i.code.startswith('BED')]
[16918]73
74class TPUSchoolSource(BasicSourceFactory):
75    """A source that delivers all kinds of TPU schools.
[13877]76    """
77    def getValues(self):
[14067]78        sorted_items = sorted(
[16918]79            SCHOOLS_TPU.items(),
[14067]80            key=lambda element: element[1][0] + element[1][1] +element[1][2])
[13877]81        return [item[0] for item in sorted_items]
82
[14499]83    def getToken(self, value):
84        return value
85
[13877]86    def getTitle(self, value):
[16918]87        if not SCHOOLS_TPU.get(value, None):
[15594]88            return u"none-existent"
[13877]89        return u"%s: %s -- %s" % (
[16918]90            SCHOOLS_TPU[value][0],
91            SCHOOLS_TPU[value][1],
92            SCHOOLS_TPU[value][2],)
[13877]93
[16918]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
[13877]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
[17744]163    email = TextLineChoice(
[13877]164        title = _(u'Email Address'),
165        required = True,
166        constraint=validate_email,
[17744]167        source = contextual_email_source,
[13877]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
[16844]188    subj_comb = schema.Choice(
[13877]189        title = _(u'Subject Combination'),
[16854]190        source = TPUCertificateSource(),
[17359]191        required = False,
[13877]192        )
193
[16926]194    school_tpu = schema.Choice(
[13877]195        title = _(u'1st Choice TPZ and School'),
[16918]196        source = TPUSchoolSource(),
[17359]197        required = False,
[13877]198        )
199
[16918]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
[17744]249    email = TextLineChoice(
[16918]250        title = _(u'Email Address'),
251        required = True,
252        constraint=validate_email,
[17744]253        source = contextual_email_source,
[16918]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(),
[17359]277        required = False,
[16918]278        )
279
[16927]280    school_utp = schema.Choice(
[16918]281        title = _(u'1st Choice UTP and School'),
282        source = UTPSchoolSource(),
[17359]283        required = False,
[16918]284        )
285
[8933]286class ICustomUGApplicant(INigeriaUGApplicant):
[8012]287    """An undergraduate applicant.
288
[8520]289    This interface defines the least common multiple of all fields
290    in ug application forms. In customized forms, fields can be excluded by
[9463]291    adding them to the OMIT* tuples.
[8012]292    """
293
[17744]294    email = TextLineChoice(
295        title = _(u'Email Address'),
296        required = True,
297        constraint=validate_email,
298        source = contextual_email_source,
299        )
300
[9465]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(),
[13884]318        required = False,
[9465]319        )
320    course2 = schema.Choice(
321        title = _(u'2nd Choice Course of Study'),
322        source = AppCatCertificateSource(),
323        required = False,
324        )
[9463]325    olevel_type = schema.Choice(
[9500]326        title = _(u'1st Qualification Obtained'),
[9463]327        required = False,
328        readonly = False,
[9465]329        vocabulary = exam_types,
330        )
331    olevel_school = schema.TextLine(
[9500]332        title = _(u'1st Institution Attended'),
[9465]333        required = False,
334        readonly = False,
335        )
336    olevel_exam_number = schema.TextLine(
[9500]337        title = _(u'1st Exam Number'),
[9465]338        required = False,
339        readonly = False,
340        )
341    olevel_exam_date = FormattedDate(
[9500]342        title = _(u'1st Exam Date'),
[9465]343        required = False,
344        readonly = False,
345        show_year = True,
346        )
347    olevel_results = schema.List(
[9500]348        title = _(u'1st Exam Results'),
[9465]349        value_type = ResultEntryField(),
350        required = False,
351        readonly = False,
[14018]352        defaultFactory=list,
[9465]353        )
[9500]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,
[14018]381        defaultFactory=list,
[9500]382        )
[9465]383    hq_type = schema.Choice(
384        title = _(u'Qualification Obtained'),
385        required = False,
386        readonly = False,
[9463]387        vocabulary = high_qual,
388        )
[9465]389    hq_matric_no = schema.TextLine(
[9463]390        title = _(u'Former Matric Number'),
391        required = False,
392        readonly = False,
393        )
[9465]394    hq_degree = schema.Choice(
[9463]395        title = _(u'Class of Degree'),
396        required = False,
397        readonly = False,
398        vocabulary = high_grade,
399        )
[9465]400    hq_school = schema.TextLine(
[9463]401        title = _(u'Institution Attended'),
402        required = False,
403        readonly = False,
404        )
[9465]405    hq_session = schema.TextLine(
[9463]406        title = _(u'Years Attended'),
407        required = False,
408        readonly = False,
409        )
[9465]410    hq_disc = schema.TextLine(
[9463]411        title = _(u'Discipline'),
412        required = False,
413        readonly = False,
414        )
[9465]415    jamb_subjects = schema.Text(
416        title = _(u'Subjects and Scores'),
[10533]417        description = _(u'(one subject with score per line)'),
[9465]418        required = False,
419        )
420    jamb_score = schema.Int(
421        title = _(u'Total JAMB Score'),
422        required = False,
423        )
[10500]424    jamb_reg_number = schema.TextLine(
425        title = _(u'JAMB Registration Number'),
426        required = False,
427        )
[9465]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,
[14335]452        required = False,
[9465]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,
[14335]467        required = False,
[9465]468        )
[9463]469
[17744]470ICustomUGApplicant[
471    'email'].order =  INigeriaUGApplicant['email'].order
[9463]472
[8933]473class ICustomPGApplicant(INigeriaPGApplicant):
[7853]474    """A postgraduate applicant.
475
[8520]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.
[7866]479    """
480
[17744]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
[13877]491class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant,
[16918]492    ITPURegistration, IUTPRegistration):
[13877]493    """An interface for all types of applicants.
[8012]494
[8933]495    Attention: The ICustomPGApplicant field seetings will be overwritten
496    by ICustomPGApplicant field settings. If a field is defined
[8729]497    in both interfaces zope.schema validates only against the
[8933]498    constraints in ICustomUGApplicant. This does not affect the forms
499    since they are build on either ICustomUGApplicant or ICustomPGApplicant.
[8012]500    """
501
[8745]502    def writeLogMessage(view, comment):
[8053]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
[9497]511class ICustomUGApplicantEdit(ICustomUGApplicant):
[8729]512    """An undergraduate applicant interface for edit forms.
[8012]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
[17744]523    email = TextLineChoice(
[9497]524        title = _(u'Email Address'),
525        required = True,
526        constraint=validate_email,
[17744]527        source = contextual_email_source,
[9497]528        )
529    date_of_birth = FormattedDate(
530        title = _(u'Date of Birth'),
531        required = True,
532        show_year = True,
533        )
[11776]534    jamb_reg_number = schema.TextLine(
535        title = _(u'JAMB Registration Number'),
536        required = True,
537        )
[13884]538    course1 = schema.Choice(
539        title = _(u'1st Choice Course of Study'),
540        source = AppCatCertificateSource(),
541        required = True,
542        )
[9497]543
[10500]544ICustomUGApplicantEdit[
545    'date_of_birth'].order =  ICustomUGApplicant['date_of_birth'].order
546ICustomUGApplicantEdit[
547    'email'].order =  ICustomUGApplicant['email'].order
548ICustomUGApplicantEdit[
[13238]549    'jamb_reg_number'].order =  ICustomUGApplicant['jamb_reg_number'].order
[13884]550ICustomUGApplicantEdit[
551    'course1'].order =  ICustomUGApplicant['course1'].order
[10500]552
[9497]553class ICustomPGApplicantEdit(ICustomPGApplicant):
[7866]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.
[8017]563    """
[8454]564
[17744]565    email = TextLineChoice(
[9497]566        title = _(u'Email Address'),
567        required = True,
568        constraint=validate_email,
[17744]569        source = contextual_email_source,
[9497]570        )
571    date_of_birth = FormattedDate(
572        title = _(u'Date of Birth'),
573        required = True,
574        show_year = True,
575        )
576
[10500]577ICustomPGApplicantEdit[
578    'date_of_birth'].order =  ICustomPGApplicant['date_of_birth'].order
579ICustomPGApplicantEdit[
580    'email'].order =  ICustomPGApplicant['email'].order
581
582
[8933]583class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment):
[8247]584    """An applicant payment via payment gateways.
585
586    """
[8531]587
[8979]588class IPUTMEApplicantEdit(IPUTMEApplicantEdit):
[8531]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
[8979]600class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo):
[8584]601    """Representation of an applicant.
602
603    Skip regular reg_number validation if reg_number is used for finding
604    the applicant object.
605    """
[8979]606
[17744]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.