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

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

Configure transcript applications.

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