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

Last change on this file since 14395 was 14335, checked in by Henrik Bettermann, 8 years ago

Set required attribute.

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