source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/interfaces.py @ 16124

Last change on this file since 16124 was 16078, checked in by Henrik Bettermann, 5 years ago

Implement transcript applications.

  • Property svn:keywords set to Id
File size: 19.5 KB
RevLine 
[13814]1# -*- coding: utf-8 -*-
[7853]2## $Id: interfaces.py 16078 2020-05-02 20:07:43Z henrik $
3##
4## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
5## This program is free software; you can redistribute it and/or modify
6## it under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 2 of the License, or
8## (at your option) any later version.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with this program; if not, write to the Free Software
17## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18##
19"""Customized interfaces of the university application package.
20"""
21
[13831]22#from grok import getSite
[8012]23from zope import schema
[13831]24#from zope.interface import invariant, Invalid
25#from zope.component import getUtility
26#from zope.catalog.interfaces import ICatalog
[13814]27from zc.sourcefactory.basic import BasicSourceFactory
[8051]28from waeup.kofa.applicants.interfaces import (
[8053]29    IApplicantBaseData,
[8051]30    AppCatCertificateSource, CertificateSource)
[16078]31from waeup.kofa.university.vocabularies import StudyModeSource
32from waeup.kofa.students.vocabularies import (
33    nats_vocab, GenderSource, StudyLevelSource)
[8051]34from waeup.kofa.schoolgrades import ResultEntryField
[8530]35from waeup.kofa.interfaces import (
[13814]36    SimpleKofaVocabulary, academic_sessions_vocab, validate_email,
[15490]37    IKofaObject)
[13814]38from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber
[15490]39from waeup.kofa.students.vocabularies import (
40    nats_vocab, GenderSource)
[14106]41from waeup.kofa.refereeentries import RefereeEntryField
[8530]42from waeup.kofa.applicants.interfaces import contextual_reg_num_source
[15490]43from kofacustom.nigeria.interfaces import DisabilitiesSource
[8928]44from kofacustom.nigeria.applicants.interfaces import (
45    LGASource, high_qual, high_grade, exam_types,
[14140]46    programme_types_vocab, jambsubjects,
[8928]47    INigeriaUGApplicant, INigeriaPGApplicant,
48    INigeriaApplicantOnlinePayment,
[9006]49    INigeriaUGApplicantEdit, INigeriaPGApplicantEdit,
50    INigeriaApplicantUpdateByRegNo,
51    IPUTMEApplicantEdit,
[14140]52    IBankAccount,
[8928]53    )
[8020]54from waeup.uniben.interfaces import MessageFactory as _
[8247]55from waeup.uniben.payments.interfaces import ICustomOnlinePayment
[7853]56
[13814]57
58REGISTRATION_CATS = {
59    'corporate': ('Corporate Registration', 250000, 1),
60    'group': ('Group Registration', 200000, 2),
61    'individual': ('Individual Registration', 45000, 3),
62    'student': ('Student Registration', 5000, 4),
[13824]63    'fullpage': ('Full Page Advert', 250000, 5),
64    'halfpage': ('Half Page Advert', 150000, 6),
65    'quarterpage': ('Quarter Page Advert', 100000, 7),
[13814]66    }
67
68class RegTypesSource(BasicSourceFactory):
69    """A source that delivers all kinds of registrations.
70    """
71    def getValues(self):
72        sorted_items = sorted(REGISTRATION_CATS.items(),
73                              key=lambda element: element[1][2])
74        return [item[0] for item in sorted_items]
75
76    def getTitle(self, value):
77        return u"%s @ ₦ %s" % (
78            REGISTRATION_CATS[value][0],
79            REGISTRATION_CATS[value][1])
80
81class IUnibenRegistration(IKofaObject):
82    """A Uniben registrant.
83    """
84
85    suspended = schema.Bool(
86        title = _(u'Account suspended'),
87        default = False,
88        required = False,
89        )
90
91    locked = schema.Bool(
92        title = _(u'Form locked'),
93        default = False,
94        required = False,
95        )
96
97    applicant_id = schema.TextLine(
98        title = _(u'Registrant Id'),
99        required = False,
100        readonly = False,
101        )
102
103    firstname = schema.TextLine(
104        title = _(u'First Name'),
105        required = True,
106        )
107
108    middlename = schema.TextLine(
109        title = _(u'Middle Name'),
110        required = False,
111        )
112
113    lastname = schema.TextLine(
114        title = _(u'Last Name (Surname)'),
115        required = True,
116        )
117
[13819]118    sex = schema.Choice(
119        title = _(u'Sex'),
120        source = GenderSource(),
121        required = True,
[13814]122        )
123
124    nationality = schema.Choice(
125        vocabulary = nats_vocab,
126        title = _(u'Nationality'),
127        required = False,
128        )
129
130    email = schema.ASCIILine(
131        title = _(u'Email Address'),
132        required = True,
133        constraint=validate_email,
134        )
135
136    phone = PhoneNumber(
137        title = _(u'Phone'),
138        description = u'',
139        required = False,
140        )
141
[13819]142    #perm_address = schema.Text(
143    #    title = _(u'Current Local Address'),
144    #    required = False,
145    #    readonly = False,
146    #    )
147
148    institution = schema.TextLine(
149        title = _(u'Institution/Organisation'),
[13814]150        required = False,
151        readonly = False,
152        )
153
[13828]154    city = schema.TextLine(
155        title = _(u'City'),
156        required = False,
157        readonly = False,
158        )
159
[13819]160    lga = schema.Choice(
161        source = LGASource(),
162        title = _(u'State/LGA'),
163        required = False,
164        )
165
[13831]166    matric_number = schema.TextLine(
167        title = _(u'Uniben Matriculation Number'),
168        required = False,
169        readonly = False,
170        )
171
[13814]172    registration_cats = schema.List(
173        title = _(u'Registration Categories'),
174        value_type = schema.Choice(source=RegTypesSource()),
175        required = True,
[14020]176        defaultFactory=list,
[13814]177        )
178
[13831]179#    @invariant
180#    def matric_number_exists(applicant):
181#        if applicant.matric_number:
182#            catalog = getUtility(ICatalog, name='students_catalog')
183#            accommodation_session = getSite()['hostels'].accommodation_session
184#            student = catalog.searchResults(matric_number=(
185#                applicant.matric_number, applicant.matric_number))
186#            if len(student) != 1:
187#                raise Invalid(_("Matriculation number not found."))
[13814]188
[16078]189class ITranscriptApplicant(IKofaObject):
190    """A transcript applicant.
191    """
192
193    suspended = schema.Bool(
194        title = _(u'Account suspended'),
195        default = False,
196        required = False,
197        )
198
199    locked = schema.Bool(
200        title = _(u'Form locked'),
201        default = False,
202        required = False,
203        )
204
205    applicant_id = schema.TextLine(
206        title = _(u'Application Id'),
207        required = False,
208        readonly = False,
209        )
210
211    reg_number = TextLineChoice(
212        title = _(u'Kofa Registration Number'),
213        readonly = False,
214        required = True,
215        source = contextual_reg_num_source,
216        )
217
218    firstname = schema.TextLine(
219        title = _(u'First Name'),
220        required = True,
221        )
222
223    middlename = schema.TextLine(
224        title = _(u'Middle Name'),
225        required = False,
226        )
227
228    lastname = schema.TextLine(
229        title = _(u'Last Name (Surname)'),
230        required = True,
231        )
232
233    matric_number = schema.TextLine(
234        title = _(u'Matriculation Number'),
235        readonly = False,
236        required = True,
237        )
238
239    date_of_birth = FormattedDate(
240        title = _(u'Date of Birth'),
241        required = False,
242        #date_format = u'%d/%m/%Y', # Use grok-instance-wide default
243        show_year = True,
244        )
245
246    sex = schema.Choice(
247        title = _(u'Gender'),
248        source = GenderSource(),
249        required = True,
250        )
251
252    place_of_birth = schema.TextLine(
253        title = _(u'Place of Birth'),
254        readonly = False,
255        required = False,
256        )
257
258    nationality = schema.Choice(
259        vocabulary = nats_vocab,
260        title = _(u'Nationality'),
261        required = False,
262        )
263
264    email = schema.ASCIILine(
265        title = _(u'Email Address'),
266        required = True,
267        constraint=validate_email,
268        )
269
270    phone = PhoneNumber(
271        title = _(u'Phone'),
272        description = u'',
273        required = False,
274        )
275
276    perm_address = schema.Text(
277        title = _(u'Current Local Address'),
278        required = False,
279        readonly = False,
280        )
281
282    dispatch_address = schema.Text(
283        title = _(u'Dispatch Addresses'),
284        description = u'Addresses to which transcript should be posted.',
285        required = False,
286        readonly = False,
287        )
288
289    entry_mode = schema.Choice(
290        title = _(u'Entry Mode'),
291        source = StudyModeSource(),
292        required = False,
293        readonly = False,
294        )
295
296    entry_session = schema.Choice(
297        title = _(u'Entry Session'),
298        source = academic_sessions_vocab,
299        required = False,
300        readonly = False,
301        )
302
303    end_session = schema.Choice(
304        title = _(u'End Session'),
305        source = academic_sessions_vocab,
306        required = False,
307        readonly = False,
308        )
309
310    course_studied = schema.Choice(
311        title = _(u'Course of Study / Degree'),
312        source = CertificateSource(),
313        required = False,
314        readonly = False,
315        )
316
317    purpose = schema.TextLine(
318        title = _(u'Purpose of this Application'),
319        readonly = False,
320        required = False,
321        )
322
323    course_changed = schema.Choice(
324        title = _(u'Change of Study Course'),
325        description = u'If yes, select previous course of study.',
326        source = CertificateSource(),
327        readonly = False,
328        required = False,
329        )
330
331    change_level = schema.Choice(
332        title = _(u'Change Level'),
333        description = u'If yes, select level at which you changed course of study.',
334        source = StudyLevelSource(),
335        required = False,
336        readonly = False,
337        )
338
339    no_copies = schema.Choice(
340        title = _(u'Number of Copies'),
341        description = u'Must correspond with the number of dispatch addresses above.',
342        values=[1, 2, 3, 4],
343        required = False,
344        readonly = False,
345        default = 1,
346        )
347
[14140]348class ICustomUGApplicant(IApplicantBaseData, IBankAccount):
[8012]349    """An undergraduate applicant.
350
[8519]351    This interface defines the least common multiple of all fields
352    in ug application forms. In customized forms, fields can be excluded by
353    adding them to the UG_OMIT* tuples.
[8012]354    """
355
[15490]356    disabilities = schema.Choice(
357        title = _(u'Disabilities'),
358        source = DisabilitiesSource(),
359        required = False,
360        )
[14140]361    nationality = schema.Choice(
362        source = nats_vocab,
363        title = _(u'Nationality'),
364        required = False,
365        )
366    lga = schema.Choice(
367        source = LGASource(),
368        title = _(u'State/LGA (Nigerians only)'),
369        required = False,
370        )
371    #perm_address = schema.Text(
372    #    title = _(u'Permanent Address'),
373    #    required = False,
374    #    )
375    course1 = schema.Choice(
376        title = _(u'1st Choice Course of Study'),
377        source = AppCatCertificateSource(),
378        required = True,
379        )
380    course2 = schema.Choice(
381        title = _(u'2nd Choice Course of Study'),
382        source = AppCatCertificateSource(),
383        required = False,
384        )
385
386    programme_type = schema.Choice(
387        title = _(u'Programme Type'),
388        vocabulary = programme_types_vocab,
389        required = False,
390        )
391
392    hq_type = schema.Choice(
393        title = _(u'Qualification Obtained'),
394        required = False,
395        readonly = False,
396        vocabulary = high_qual,
397        )
398    hq_matric_no = schema.TextLine(
399        title = _(u'Former Matric Number'),
400        required = False,
401        readonly = False,
402        )
403    hq_degree = schema.Choice(
404        title = _(u'Class of Degree'),
405        required = False,
406        readonly = False,
407        vocabulary = high_grade,
408        )
409    hq_school = schema.TextLine(
410        title = _(u'Institution Attended'),
411        required = False,
412        readonly = False,
413        )
414    hq_session = schema.TextLine(
415        title = _(u'Years Attended'),
416        required = False,
417        readonly = False,
418        )
419    hq_disc = schema.TextLine(
420        title = _(u'Discipline'),
421        required = False,
422        readonly = False,
423        )
[14141]424    fst_sit_fname = schema.TextLine(
425        title = _(u'Full Name'),
426        required = False,
427        readonly = False,
428        )
429    fst_sit_no = schema.TextLine(
430        title = _(u'Exam Number'),
431        required = False,
432        readonly = False,
433        )
434    fst_sit_date = FormattedDate(
435        title = _(u'Exam Date'),
436        required = False,
437        readonly = False,
438        show_year = True,
439        )
440    fst_sit_type = schema.Choice(
441        title = _(u'Exam Type'),
442        required = False,
443        readonly = False,
444        vocabulary = exam_types,
445        )
446    fst_sit_results = schema.List(
447        title = _(u'Exam Results'),
448        value_type = ResultEntryField(),
449        required = False,
450        readonly = False,
451        defaultFactory=list,
452        )
453    scd_sit_fname = schema.TextLine(
454        title = _(u'Full Name'),
455        required = False,
456        readonly = False,
457        )
458    scd_sit_no = schema.TextLine(
459        title = _(u'Exam Number'),
460        required = False,
461        readonly = False,
462        )
463    scd_sit_date = FormattedDate(
464        title = _(u'Exam Date'),
465        required = False,
466        readonly = False,
467        show_year = True,
468        )
469    scd_sit_type = schema.Choice(
470        title = _(u'Exam Type'),
471        required = False,
472        readonly = False,
473        vocabulary = exam_types,
474        )
475    scd_sit_results = schema.List(
476        title = _(u'Exam Results'),
477        value_type = ResultEntryField(),
478        required = False,
479        readonly = False,
480        defaultFactory=list,
481        )
[14140]482    jamb_subjects = schema.Text(
483        title = _(u'Subjects and Scores'),
484        required = False,
485        )
486    jamb_subjects_list = schema.List(
487        title = _(u'JAMB Subjects'),
488        required = False,
489        defaultFactory=list,
490        value_type = schema.Choice(
491            vocabulary = jambsubjects
492            #source = JAMBSubjectSource(),
493            ),
494        )
495    jamb_score = schema.Int(
496        title = _(u'Total JAMB Score'),
497        required = False,
498        )
499    #jamb_age = schema.Int(
500    #    title = _(u'Age (provided by JAMB)'),
501    #    required = False,
502    #    )
503    jamb_reg_number = schema.TextLine(
504        title = _(u'JAMB Registration Number'),
505        required = False,
506        )
507    notice = schema.Text(
508        title = _(u'Notice'),
509        required = False,
510        )
511    screening_venue = schema.TextLine(
512        title = _(u'Screening Venue'),
513        required = False,
514        )
515    screening_date = schema.TextLine(
516        title = _(u'Screening Date'),
517        required = False,
518        )
519    screening_score = schema.Int(
520        title = _(u'Screening Score (%)'),
521        required = False,
522        )
523    aggregate = schema.Int(
524        title = _(u'Aggregate Score (%)'),
525        description = _(u'(average of relative JAMB and PUTME scores)'),
526        required = False,
527        )
528    result_uploaded = schema.Bool(
529        title = _(u'Result uploaded'),
530        default = False,
531        required = False,
532        )
533    student_id = schema.TextLine(
534        title = _(u'Student Id'),
535        required = False,
536        readonly = False,
537        )
538    course_admitted = schema.Choice(
539        title = _(u'Admitted Course of Study'),
540        source = CertificateSource(),
541        required = False,
542        )
543    locked = schema.Bool(
544        title = _(u'Form locked'),
545        default = False,
546        required = False,
547        )
548
549ICustomUGApplicant[
550    'locked'].order =  IApplicantBaseData['suspended'].order
551ICustomUGApplicant[
552    'result_uploaded'].order =  ICustomUGApplicant['suspended'].order
553
[8928]554class ICustomPGApplicant(INigeriaPGApplicant):
[7853]555    """A postgraduate applicant.
556
[8519]557    This interface defines the least common multiple of all fields
558    in pg application forms. In customized forms, fields can be excluded by
559    adding them to the PG_OMIT* tuples.
[7866]560    """
561
[14106]562    referees = schema.List(
563        title = _(u'Referees'),
564        value_type = RefereeEntryField(),
565        required = False,
566        defaultFactory=list,
567        )
[8012]568
[14106]569ICustomPGApplicant[
570    'referees'].order =  INigeriaPGApplicant['emp2_reason'].order
571
[13814]572class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant,
[16078]573    IUnibenRegistration, ITranscriptApplicant):
[8012]574    """An interface for both types of applicants.
575
[8928]576    Attention: The ICustomPGApplicant field seetings will be overwritten
577    by ICustomPGApplicant field settings. If a field is defined
[8727]578    in both interfaces zope.schema validates only against the
[8928]579    constraints in ICustomUGApplicant. This does not affect the forms
580    since they are build on either ICustomUGApplicant or ICustomPGApplicant.
[8012]581    """
582
[8743]583    def writeLogMessage(view, comment):
[8053]584        """Adds an INFO message to the log file
585        """
586
587    def createStudent():
[8668]588        """Create a student object from applicant data
[8053]589        and copy applicant object.
590        """
591
[14212]592class ICustomUGApplicantEdit(ICustomUGApplicant):
[8727]593    """An undergraduate applicant interface for edit forms.
[8012]594
595    Here we can repeat the fields from base data and set the
596    `required` and `readonly` attributes to True to further restrict
597    the data access. Or we can allow only certain certificates to be
598    selected by choosing the appropriate source.
599
600    We cannot omit fields here. This has to be done in the
601    respective form page.
602    """
603
[14212]604    email = schema.ASCIILine(
605        title = _(u'Email Address'),
606        required = True,
607        constraint=validate_email,
608        )
609    date_of_birth = FormattedDate(
610        title = _(u'Date of Birth'),
611        required = True,
612        show_year = True,
613        )
614
615ICustomUGApplicantEdit[
616    'date_of_birth'].order = ICustomUGApplicant['date_of_birth'].order
617ICustomUGApplicantEdit[
618    'email'].order = ICustomUGApplicant['email'].order
619
[9056]620class ICustomPGApplicantEdit(INigeriaPGApplicantEdit):
[7866]621    """A postgraduate applicant interface for editing.
622
623    Here we can repeat the fields from base data and set the
624    `required` and `readonly` attributes to True to further restrict
625    the data access. Or we can allow only certain certificates to be
626    selected by choosing the appropriate source.
627
628    We cannot omit fields here. This has to be done in the
629    respective form page.
[8017]630    """
[8454]631
[14106]632    referees = schema.List(
633        title = _(u'Referees'),
634        value_type = RefereeEntryField(),
635        required = False,
636        defaultFactory=list,
637        )
[13814]638
[14106]639ICustomPGApplicantEdit[
640    'referees'].order =  INigeriaPGApplicantEdit['emp2_reason'].order
641
[8928]642class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment):
[8247]643    """An applicant payment via payment gateways.
644
645    """
[8530]646
[14153]647class IPUTMEApplicantEdit(ICustomUGApplicant):
[8530]648    """An undergraduate applicant interface for editing.
649
650    Here we can repeat the fields from base data and set the
651    `required` and `readonly` attributes to True to further restrict
652    the data access. Or we can allow only certain certificates to be
653    selected by choosing the appropriate source.
654
655    We cannot omit fields here. This has to be done in the
656    respective form page.
657    """
658
[14153]659    email = schema.ASCIILine(
660        title = _(u'Email Address'),
661        required = True,
662        constraint=validate_email,
663        )
664    date_of_birth = FormattedDate(
665        title = _(u'Date of Birth'),
666        required = True,
667        show_year = True,
668        )
669    nationality = schema.Choice(
670        source = nats_vocab,
671        title = _(u'Nationality'),
672        required = True,
673        )
674
675IPUTMEApplicantEdit[
676    'date_of_birth'].order =  ICustomUGApplicant['date_of_birth'].order
677IPUTMEApplicantEdit[
678    'email'].order =  ICustomUGApplicant['email'].order
679IPUTMEApplicantEdit[
680    'nationality'].order =  ICustomUGApplicant['nationality'].order
681
[9056]682class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo):
[8582]683    """Representation of an applicant.
684
685    Skip regular reg_number validation if reg_number is used for finding
686    the applicant object.
687    """
Note: See TracBrowser for help on using the repository browser.