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

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

Fix ICustomUGApplicantEdit.

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