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

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

Add disabilities field.

  • Property svn:keywords set to Id
File size: 15.5 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: interfaces.py 15490 2019-07-09 06:17:19Z 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.schoolgrades import ResultEntryField
32from waeup.kofa.interfaces import (
33    SimpleKofaVocabulary, academic_sessions_vocab, validate_email,
34    IKofaObject)
35from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber
36from waeup.kofa.students.vocabularies import (
37    nats_vocab, GenderSource)
38from waeup.kofa.refereeentries import RefereeEntryField
39from waeup.kofa.applicants.interfaces import contextual_reg_num_source
40from kofacustom.nigeria.interfaces import DisabilitiesSource
41from kofacustom.nigeria.applicants.interfaces import (
42    LGASource, high_qual, high_grade, exam_types,
43    programme_types_vocab, jambsubjects,
44    INigeriaUGApplicant, INigeriaPGApplicant,
45    INigeriaApplicantOnlinePayment,
46    INigeriaUGApplicantEdit, INigeriaPGApplicantEdit,
47    INigeriaApplicantUpdateByRegNo,
48    IPUTMEApplicantEdit,
49    IBankAccount,
50    )
51from waeup.uniben.interfaces import MessageFactory as _
52from waeup.uniben.payments.interfaces import ICustomOnlinePayment
53
54
55REGISTRATION_CATS = {
56    'corporate': ('Corporate Registration', 250000, 1),
57    'group': ('Group Registration', 200000, 2),
58    'individual': ('Individual Registration', 45000, 3),
59    'student': ('Student Registration', 5000, 4),
60    'fullpage': ('Full Page Advert', 250000, 5),
61    'halfpage': ('Half Page Advert', 150000, 6),
62    'quarterpage': ('Quarter Page Advert', 100000, 7),
63    }
64
65class RegTypesSource(BasicSourceFactory):
66    """A source that delivers all kinds of registrations.
67    """
68    def getValues(self):
69        sorted_items = sorted(REGISTRATION_CATS.items(),
70                              key=lambda element: element[1][2])
71        return [item[0] for item in sorted_items]
72
73    def getTitle(self, value):
74        return u"%s @ ₦ %s" % (
75            REGISTRATION_CATS[value][0],
76            REGISTRATION_CATS[value][1])
77
78class IUnibenRegistration(IKofaObject):
79    """A Uniben registrant.
80    """
81
82    suspended = schema.Bool(
83        title = _(u'Account suspended'),
84        default = False,
85        required = False,
86        )
87
88    locked = schema.Bool(
89        title = _(u'Form locked'),
90        default = False,
91        required = False,
92        )
93
94    applicant_id = schema.TextLine(
95        title = _(u'Registrant Id'),
96        required = False,
97        readonly = False,
98        )
99
100    firstname = schema.TextLine(
101        title = _(u'First Name'),
102        required = True,
103        )
104
105    middlename = schema.TextLine(
106        title = _(u'Middle Name'),
107        required = False,
108        )
109
110    lastname = schema.TextLine(
111        title = _(u'Last Name (Surname)'),
112        required = True,
113        )
114
115    sex = schema.Choice(
116        title = _(u'Sex'),
117        source = GenderSource(),
118        required = True,
119        )
120
121    nationality = schema.Choice(
122        vocabulary = nats_vocab,
123        title = _(u'Nationality'),
124        required = False,
125        )
126
127    email = schema.ASCIILine(
128        title = _(u'Email Address'),
129        required = True,
130        constraint=validate_email,
131        )
132
133    phone = PhoneNumber(
134        title = _(u'Phone'),
135        description = u'',
136        required = False,
137        )
138
139    #perm_address = schema.Text(
140    #    title = _(u'Current Local Address'),
141    #    required = False,
142    #    readonly = False,
143    #    )
144
145    institution = schema.TextLine(
146        title = _(u'Institution/Organisation'),
147        required = False,
148        readonly = False,
149        )
150
151    city = schema.TextLine(
152        title = _(u'City'),
153        required = False,
154        readonly = False,
155        )
156
157    lga = schema.Choice(
158        source = LGASource(),
159        title = _(u'State/LGA'),
160        required = False,
161        )
162
163    matric_number = schema.TextLine(
164        title = _(u'Uniben Matriculation Number'),
165        required = False,
166        readonly = False,
167        )
168
169    registration_cats = schema.List(
170        title = _(u'Registration Categories'),
171        value_type = schema.Choice(source=RegTypesSource()),
172        required = True,
173        defaultFactory=list,
174        )
175
176#    @invariant
177#    def matric_number_exists(applicant):
178#        if applicant.matric_number:
179#            catalog = getUtility(ICatalog, name='students_catalog')
180#            accommodation_session = getSite()['hostels'].accommodation_session
181#            student = catalog.searchResults(matric_number=(
182#                applicant.matric_number, applicant.matric_number))
183#            if len(student) != 1:
184#                raise Invalid(_("Matriculation number not found."))
185
186class ICustomUGApplicant(IApplicantBaseData, IBankAccount):
187    """An undergraduate applicant.
188
189    This interface defines the least common multiple of all fields
190    in ug application forms. In customized forms, fields can be excluded by
191    adding them to the UG_OMIT* tuples.
192    """
193
194    disabilities = schema.Choice(
195        title = _(u'Disabilities'),
196        source = DisabilitiesSource(),
197        required = False,
198        )
199    nationality = schema.Choice(
200        source = nats_vocab,
201        title = _(u'Nationality'),
202        required = False,
203        )
204    lga = schema.Choice(
205        source = LGASource(),
206        title = _(u'State/LGA (Nigerians only)'),
207        required = False,
208        )
209    #perm_address = schema.Text(
210    #    title = _(u'Permanent Address'),
211    #    required = False,
212    #    )
213    course1 = schema.Choice(
214        title = _(u'1st Choice Course of Study'),
215        source = AppCatCertificateSource(),
216        required = True,
217        )
218    course2 = schema.Choice(
219        title = _(u'2nd Choice Course of Study'),
220        source = AppCatCertificateSource(),
221        required = False,
222        )
223
224    programme_type = schema.Choice(
225        title = _(u'Programme Type'),
226        vocabulary = programme_types_vocab,
227        required = False,
228        )
229
230    hq_type = schema.Choice(
231        title = _(u'Qualification Obtained'),
232        required = False,
233        readonly = False,
234        vocabulary = high_qual,
235        )
236    hq_matric_no = schema.TextLine(
237        title = _(u'Former Matric Number'),
238        required = False,
239        readonly = False,
240        )
241    hq_degree = schema.Choice(
242        title = _(u'Class of Degree'),
243        required = False,
244        readonly = False,
245        vocabulary = high_grade,
246        )
247    hq_school = schema.TextLine(
248        title = _(u'Institution Attended'),
249        required = False,
250        readonly = False,
251        )
252    hq_session = schema.TextLine(
253        title = _(u'Years Attended'),
254        required = False,
255        readonly = False,
256        )
257    hq_disc = schema.TextLine(
258        title = _(u'Discipline'),
259        required = False,
260        readonly = False,
261        )
262    fst_sit_fname = schema.TextLine(
263        title = _(u'Full Name'),
264        required = False,
265        readonly = False,
266        )
267    fst_sit_no = schema.TextLine(
268        title = _(u'Exam Number'),
269        required = False,
270        readonly = False,
271        )
272    fst_sit_date = FormattedDate(
273        title = _(u'Exam Date'),
274        required = False,
275        readonly = False,
276        show_year = True,
277        )
278    fst_sit_type = schema.Choice(
279        title = _(u'Exam Type'),
280        required = False,
281        readonly = False,
282        vocabulary = exam_types,
283        )
284    fst_sit_results = schema.List(
285        title = _(u'Exam Results'),
286        value_type = ResultEntryField(),
287        required = False,
288        readonly = False,
289        defaultFactory=list,
290        )
291    scd_sit_fname = schema.TextLine(
292        title = _(u'Full Name'),
293        required = False,
294        readonly = False,
295        )
296    scd_sit_no = schema.TextLine(
297        title = _(u'Exam Number'),
298        required = False,
299        readonly = False,
300        )
301    scd_sit_date = FormattedDate(
302        title = _(u'Exam Date'),
303        required = False,
304        readonly = False,
305        show_year = True,
306        )
307    scd_sit_type = schema.Choice(
308        title = _(u'Exam Type'),
309        required = False,
310        readonly = False,
311        vocabulary = exam_types,
312        )
313    scd_sit_results = schema.List(
314        title = _(u'Exam Results'),
315        value_type = ResultEntryField(),
316        required = False,
317        readonly = False,
318        defaultFactory=list,
319        )
320    jamb_subjects = schema.Text(
321        title = _(u'Subjects and Scores'),
322        required = False,
323        )
324    jamb_subjects_list = schema.List(
325        title = _(u'JAMB Subjects'),
326        required = False,
327        defaultFactory=list,
328        value_type = schema.Choice(
329            vocabulary = jambsubjects
330            #source = JAMBSubjectSource(),
331            ),
332        )
333    jamb_score = schema.Int(
334        title = _(u'Total JAMB Score'),
335        required = False,
336        )
337    #jamb_age = schema.Int(
338    #    title = _(u'Age (provided by JAMB)'),
339    #    required = False,
340    #    )
341    jamb_reg_number = schema.TextLine(
342        title = _(u'JAMB Registration Number'),
343        required = False,
344        )
345    notice = schema.Text(
346        title = _(u'Notice'),
347        required = False,
348        )
349    screening_venue = schema.TextLine(
350        title = _(u'Screening Venue'),
351        required = False,
352        )
353    screening_date = schema.TextLine(
354        title = _(u'Screening Date'),
355        required = False,
356        )
357    screening_score = schema.Int(
358        title = _(u'Screening Score (%)'),
359        required = False,
360        )
361    aggregate = schema.Int(
362        title = _(u'Aggregate Score (%)'),
363        description = _(u'(average of relative JAMB and PUTME scores)'),
364        required = False,
365        )
366    result_uploaded = schema.Bool(
367        title = _(u'Result uploaded'),
368        default = False,
369        required = False,
370        )
371    student_id = schema.TextLine(
372        title = _(u'Student Id'),
373        required = False,
374        readonly = False,
375        )
376    course_admitted = schema.Choice(
377        title = _(u'Admitted Course of Study'),
378        source = CertificateSource(),
379        required = False,
380        )
381    locked = schema.Bool(
382        title = _(u'Form locked'),
383        default = False,
384        required = False,
385        )
386
387ICustomUGApplicant[
388    'locked'].order =  IApplicantBaseData['suspended'].order
389ICustomUGApplicant[
390    'result_uploaded'].order =  ICustomUGApplicant['suspended'].order
391
392class ICustomPGApplicant(INigeriaPGApplicant):
393    """A postgraduate applicant.
394
395    This interface defines the least common multiple of all fields
396    in pg application forms. In customized forms, fields can be excluded by
397    adding them to the PG_OMIT* tuples.
398    """
399
400    referees = schema.List(
401        title = _(u'Referees'),
402        value_type = RefereeEntryField(),
403        required = False,
404        defaultFactory=list,
405        )
406
407ICustomPGApplicant[
408    'referees'].order =  INigeriaPGApplicant['emp2_reason'].order
409
410class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant,
411    IUnibenRegistration):
412    """An interface for both types of applicants.
413
414    Attention: The ICustomPGApplicant field seetings will be overwritten
415    by ICustomPGApplicant field settings. If a field is defined
416    in both interfaces zope.schema validates only against the
417    constraints in ICustomUGApplicant. This does not affect the forms
418    since they are build on either ICustomUGApplicant or ICustomPGApplicant.
419    """
420
421    def writeLogMessage(view, comment):
422        """Adds an INFO message to the log file
423        """
424
425    def createStudent():
426        """Create a student object from applicant data
427        and copy applicant object.
428        """
429
430class ICustomUGApplicantEdit(ICustomUGApplicant):
431    """An undergraduate applicant interface for edit forms.
432
433    Here we can repeat the fields from base data and set the
434    `required` and `readonly` attributes to True to further restrict
435    the data access. Or we can allow only certain certificates to be
436    selected by choosing the appropriate source.
437
438    We cannot omit fields here. This has to be done in the
439    respective form page.
440    """
441
442    email = schema.ASCIILine(
443        title = _(u'Email Address'),
444        required = True,
445        constraint=validate_email,
446        )
447    date_of_birth = FormattedDate(
448        title = _(u'Date of Birth'),
449        required = True,
450        show_year = True,
451        )
452
453ICustomUGApplicantEdit[
454    'date_of_birth'].order = ICustomUGApplicant['date_of_birth'].order
455ICustomUGApplicantEdit[
456    'email'].order = ICustomUGApplicant['email'].order
457
458class ICustomPGApplicantEdit(INigeriaPGApplicantEdit):
459    """A postgraduate applicant interface for editing.
460
461    Here we can repeat the fields from base data and set the
462    `required` and `readonly` attributes to True to further restrict
463    the data access. Or we can allow only certain certificates to be
464    selected by choosing the appropriate source.
465
466    We cannot omit fields here. This has to be done in the
467    respective form page.
468    """
469
470    referees = schema.List(
471        title = _(u'Referees'),
472        value_type = RefereeEntryField(),
473        required = False,
474        defaultFactory=list,
475        )
476
477ICustomPGApplicantEdit[
478    'referees'].order =  INigeriaPGApplicantEdit['emp2_reason'].order
479
480class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment):
481    """An applicant payment via payment gateways.
482
483    """
484
485class IPUTMEApplicantEdit(ICustomUGApplicant):
486    """An undergraduate applicant interface for editing.
487
488    Here we can repeat the fields from base data and set the
489    `required` and `readonly` attributes to True to further restrict
490    the data access. Or we can allow only certain certificates to be
491    selected by choosing the appropriate source.
492
493    We cannot omit fields here. This has to be done in the
494    respective form page.
495    """
496
497    email = schema.ASCIILine(
498        title = _(u'Email Address'),
499        required = True,
500        constraint=validate_email,
501        )
502    date_of_birth = FormattedDate(
503        title = _(u'Date of Birth'),
504        required = True,
505        show_year = True,
506        )
507    nationality = schema.Choice(
508        source = nats_vocab,
509        title = _(u'Nationality'),
510        required = True,
511        )
512
513IPUTMEApplicantEdit[
514    'date_of_birth'].order =  ICustomUGApplicant['date_of_birth'].order
515IPUTMEApplicantEdit[
516    'email'].order =  ICustomUGApplicant['email'].order
517IPUTMEApplicantEdit[
518    'nationality'].order =  ICustomUGApplicant['nationality'].order
519
520class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo):
521    """Representation of an applicant.
522
523    Skip regular reg_number validation if reg_number is used for finding
524    the applicant object.
525    """
Note: See TracBrowser for help on using the repository browser.