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

Last change on this file since 16875 was 16872, checked in by Henrik Bettermann, 3 years ago

Adjust exporter and fix tests.

  • Property svn:keywords set to Id
File size: 13.8 KB
Line 
1## $Id: interfaces.py 16872 2022-03-09 20:53:31Z 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 contextual_reg_num_source
34from kofacustom.nigeria.applicants.interfaces import (
35    LGASource, high_qual, high_grade, exam_types,
36    INigeriaUGApplicant, INigeriaPGApplicant,
37    INigeriaApplicantOnlinePayment,
38    INigeriaUGApplicantEdit,
39    INigeriaApplicantUpdateByRegNo,
40    IPUTMEApplicantEdit,
41    OMIT_DISPLAY_FIELDS
42    )
43from waeup.fceokene.applicants.schools_pandemic import SCHOOLS
44from waeup.fceokene.interfaces import MessageFactory as _
45
46BEC_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS
47BEC_OMIT_PDF_FIELDS = BEC_OMIT_DISPLAY_FIELDS + ('phone',)
48BEC_OMIT_MANAGE_FIELDS = ('special_application',)
49BEC_OMIT_EDIT_FIELDS = BEC_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
50    'student_id', 'notice',
51    'screening_score',
52    'screening_venue',
53    'screening_date',
54    #'jamb_subjects',
55    #'jamb_score',
56    'aggregate')
57
58class TPUCertificateSource(AppCatCertificateSource):
59
60    def getValues(self, context):
61        resultlist = super(TPUCertificateSource, self).getValues(context)
62        return [i for i in resultlist if i.title.startswith('NCE')]
63
64class SchoolSource(BasicSourceFactory):
65    """A source that delivers all kinds of schools.
66    """
67    def getValues(self):
68        sorted_items = sorted(
69            SCHOOLS.items(),
70            key=lambda element: element[1][0] + element[1][1] +element[1][2])
71        return [item[0] for item in sorted_items]
72
73    def getToken(self, value):
74        return value
75
76    def getTitle(self, value):
77        if not SCHOOLS.get(value, None):
78            return u"none-existent"
79        return u"%s: %s -- %s" % (
80            SCHOOLS[value][0],
81            SCHOOLS[value][1],
82            SCHOOLS[value][2],)
83
84class ITPURegistration(IKofaObject):
85    """A TPU registrant.
86    """
87
88    suspended = schema.Bool(
89        title = _(u'Account suspended'),
90        default = False,
91        required = False,
92        )
93
94    locked = schema.Bool(
95        title = _(u'Form locked'),
96        default = False,
97        required = False,
98        )
99
100    applicant_id = schema.TextLine(
101        title = _(u'Applicant Id'),
102        required = False,
103        readonly = False,
104        )
105
106    reg_number = schema.TextLine(
107        title = _(u'Registration Number'),
108        required = False,
109        readonly = False,
110        )
111
112    matric_number = schema.TextLine(
113        title = _(u'Matriculation Number'),
114        required = False,
115        readonly = False,
116        )
117
118    firstname = schema.TextLine(
119        title = _(u'First Name'),
120        required = True,
121        )
122
123    middlename = schema.TextLine(
124        title = _(u'Middle Name'),
125        required = False,
126        )
127
128    lastname = schema.TextLine(
129        title = _(u'Last Name (Surname)'),
130        required = True,
131        )
132
133    email = schema.ASCIILine(
134        title = _(u'Email Address'),
135        required = True,
136        constraint=validate_email,
137        )
138
139    phone = PhoneNumber(
140        title = _(u'Phone'),
141        description = u'',
142        required = False,
143        )
144
145    perm_address = schema.Text(
146        title = _(u'Home Address'),
147        required = False,
148        readonly = False,
149        )
150
151    lga = schema.Choice(
152        source = LGASource(),
153        title = _(u'State/LGA'),
154        required = False,
155        )
156
157    subj_comb = schema.Choice(
158        title = _(u'Subject Combination'),
159        source = TPUCertificateSource(),
160        required = True,
161        )
162
163    school1 = schema.Choice(
164        title = _(u'1st Choice TPZ and School'),
165        source = SchoolSource(),
166        required = False,
167        )
168
169class ICustomUGApplicant(INigeriaUGApplicant):
170    """An undergraduate applicant.
171
172    This interface defines the least common multiple of all fields
173    in ug application forms. In customized forms, fields can be excluded by
174    adding them to the OMIT* tuples.
175    """
176
177    nationality = schema.Choice(
178        source = nats_vocab,
179        title = _(u'Nationality'),
180        required = True,
181        )
182    lga = schema.Choice(
183        source = LGASource(),
184        title = _(u'State/LGA (Nigerians only)'),
185        required = False,
186        )
187    #perm_address = schema.Text(
188    #    title = _(u'Permanent Address'),
189    #    required = False,
190    #    )
191    course1 = schema.Choice(
192        title = _(u'1st Choice Course of Study'),
193        source = AppCatCertificateSource(),
194        required = False,
195        )
196    course2 = schema.Choice(
197        title = _(u'2nd Choice Course of Study'),
198        source = AppCatCertificateSource(),
199        required = False,
200        )
201    olevel_type = schema.Choice(
202        title = _(u'1st Qualification Obtained'),
203        required = False,
204        readonly = False,
205        vocabulary = exam_types,
206        )
207    olevel_school = schema.TextLine(
208        title = _(u'1st Institution Attended'),
209        required = False,
210        readonly = False,
211        )
212    olevel_exam_number = schema.TextLine(
213        title = _(u'1st Exam Number'),
214        required = False,
215        readonly = False,
216        )
217    olevel_exam_date = FormattedDate(
218        title = _(u'1st Exam Date'),
219        required = False,
220        readonly = False,
221        show_year = True,
222        )
223    olevel_results = schema.List(
224        title = _(u'1st Exam Results'),
225        value_type = ResultEntryField(),
226        required = False,
227        readonly = False,
228        defaultFactory=list,
229        )
230    olevel_type2 = schema.Choice(
231        title = _(u'2nd Qualification Obtained'),
232        required = False,
233        readonly = False,
234        vocabulary = exam_types,
235        )
236    olevel_school2 = schema.TextLine(
237        title = _(u'2nd Institution Attended'),
238        required = False,
239        readonly = False,
240        )
241    olevel_exam_number2 = schema.TextLine(
242        title = _(u'2nd Exam Number'),
243        required = False,
244        readonly = False,
245        )
246    olevel_exam_date2 = FormattedDate(
247        title = _(u'2nd Exam Date'),
248        required = False,
249        readonly = False,
250        show_year = True,
251        )
252    olevel_results2 = schema.List(
253        title = _(u'2nd Exam Results'),
254        value_type = ResultEntryField(),
255        required = False,
256        readonly = False,
257        defaultFactory=list,
258        )
259    hq_type = schema.Choice(
260        title = _(u'Qualification Obtained'),
261        required = False,
262        readonly = False,
263        vocabulary = high_qual,
264        )
265    hq_matric_no = schema.TextLine(
266        title = _(u'Former Matric Number'),
267        required = False,
268        readonly = False,
269        )
270    hq_degree = schema.Choice(
271        title = _(u'Class of Degree'),
272        required = False,
273        readonly = False,
274        vocabulary = high_grade,
275        )
276    hq_school = schema.TextLine(
277        title = _(u'Institution Attended'),
278        required = False,
279        readonly = False,
280        )
281    hq_session = schema.TextLine(
282        title = _(u'Years Attended'),
283        required = False,
284        readonly = False,
285        )
286    hq_disc = schema.TextLine(
287        title = _(u'Discipline'),
288        required = False,
289        readonly = False,
290        )
291    jamb_subjects = schema.Text(
292        title = _(u'Subjects and Scores'),
293        description = _(u'(one subject with score per line)'),
294        required = False,
295        )
296    jamb_score = schema.Int(
297        title = _(u'Total JAMB Score'),
298        required = False,
299        )
300    jamb_reg_number = schema.TextLine(
301        title = _(u'JAMB Registration Number'),
302        required = False,
303        )
304    notice = schema.Text(
305        title = _(u'Notice'),
306        required = False,
307        )
308    screening_venue = schema.TextLine(
309        title = _(u'Screening Venue'),
310        required = False,
311        )
312    screening_date = schema.TextLine(
313        title = _(u'Screening Date'),
314        required = False,
315        )
316    screening_score = schema.Int(
317        title = _(u'Screening Score (%)'),
318        required = False,
319        )
320    aggregate = schema.Int(
321        title = _(u'Aggregate Score (%)'),
322        description = _(u'(average of relative JAMB and PUTME scores)'),
323        required = False,
324        )
325    result_uploaded = schema.Bool(
326        title = _(u'Result uploaded'),
327        default = False,
328        required = False,
329        )
330    student_id = schema.TextLine(
331        title = _(u'Student Id'),
332        required = False,
333        readonly = False,
334        )
335    course_admitted = schema.Choice(
336        title = _(u'Admitted Course of Study'),
337        source = CertificateSource(),
338        required = False,
339        )
340    locked = schema.Bool(
341        title = _(u'Form locked'),
342        default = False,
343        required = False,
344        )
345
346
347class ICustomPGApplicant(INigeriaPGApplicant):
348    """A postgraduate applicant.
349
350    This interface defines the least common multiple of all fields
351    in pg application forms. In customized forms, fields can be excluded by
352    adding them to the PG_OMIT* tuples.
353    """
354
355class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant,
356    ITPURegistration):
357    """An interface for all types of applicants.
358
359    Attention: The ICustomPGApplicant field seetings will be overwritten
360    by ICustomPGApplicant field settings. If a field is defined
361    in both interfaces zope.schema validates only against the
362    constraints in ICustomUGApplicant. This does not affect the forms
363    since they are build on either ICustomUGApplicant or ICustomPGApplicant.
364    """
365
366    def writeLogMessage(view, comment):
367        """Adds an INFO message to the log file
368        """
369
370    def createStudent():
371        """Create a student object from applicatnt data
372        and copy applicant object.
373        """
374
375class ICustomUGApplicantEdit(ICustomUGApplicant):
376    """An undergraduate applicant interface for edit forms.
377
378    Here we can repeat the fields from base data and set the
379    `required` and `readonly` attributes to True to further restrict
380    the data access. Or we can allow only certain certificates to be
381    selected by choosing the appropriate source.
382
383    We cannot omit fields here. This has to be done in the
384    respective form page.
385    """
386
387
388    email = schema.ASCIILine(
389        title = _(u'Email Address'),
390        required = True,
391        constraint=validate_email,
392        )
393    date_of_birth = FormattedDate(
394        title = _(u'Date of Birth'),
395        required = True,
396        show_year = True,
397        )
398    jamb_reg_number = schema.TextLine(
399        title = _(u'JAMB Registration Number'),
400        required = True,
401        )
402    course1 = schema.Choice(
403        title = _(u'1st Choice Course of Study'),
404        source = AppCatCertificateSource(),
405        required = True,
406        )
407
408ICustomUGApplicantEdit[
409    'date_of_birth'].order =  ICustomUGApplicant['date_of_birth'].order
410ICustomUGApplicantEdit[
411    'email'].order =  ICustomUGApplicant['email'].order
412ICustomUGApplicantEdit[
413    'jamb_reg_number'].order =  ICustomUGApplicant['jamb_reg_number'].order
414ICustomUGApplicantEdit[
415    'course1'].order =  ICustomUGApplicant['course1'].order
416
417class ICustomPGApplicantEdit(ICustomPGApplicant):
418    """A postgraduate applicant interface for editing.
419
420    Here we can repeat the fields from base data and set the
421    `required` and `readonly` attributes to True to further restrict
422    the data access. Or we can allow only certain certificates to be
423    selected by choosing the appropriate source.
424
425    We cannot omit fields here. This has to be done in the
426    respective form page.
427    """
428
429    email = schema.ASCIILine(
430        title = _(u'Email Address'),
431        required = True,
432        constraint=validate_email,
433        )
434    date_of_birth = FormattedDate(
435        title = _(u'Date of Birth'),
436        required = True,
437        show_year = True,
438        )
439
440ICustomPGApplicantEdit[
441    'date_of_birth'].order =  ICustomPGApplicant['date_of_birth'].order
442ICustomPGApplicantEdit[
443    'email'].order =  ICustomPGApplicant['email'].order
444
445
446class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment):
447    """An applicant payment via payment gateways.
448
449    """
450
451class IPUTMEApplicantEdit(IPUTMEApplicantEdit):
452    """An undergraduate applicant interface for editing.
453
454    Here we can repeat the fields from base data and set the
455    `required` and `readonly` attributes to True to further restrict
456    the data access. Or we can allow only certain certificates to be
457    selected by choosing the appropriate source.
458
459    We cannot omit fields here. This has to be done in the
460    respective form page.
461    """
462
463class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo):
464    """Representation of an applicant.
465
466    Skip regular reg_number validation if reg_number is used for finding
467    the applicant object.
468    """
469
Note: See TracBrowser for help on using the repository browser.