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

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

Add referee fields.

  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: interfaces.py 14106 2016-08-22 09:10: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    INigeriaUGApplicant, INigeriaPGApplicant,
42    INigeriaApplicantOnlinePayment,
43    INigeriaUGApplicantEdit, INigeriaPGApplicantEdit,
44    INigeriaApplicantUpdateByRegNo,
45    IPUTMEApplicantEdit,
46    )
47from waeup.uniben.interfaces import MessageFactory as _
48from waeup.uniben.payments.interfaces import ICustomOnlinePayment
49
50
51REGISTRATION_CATS = {
52    'corporate': ('Corporate Registration', 250000, 1),
53    'group': ('Group Registration', 200000, 2),
54    'individual': ('Individual Registration', 45000, 3),
55    'student': ('Student Registration', 5000, 4),
56    'fullpage': ('Full Page Advert', 250000, 5),
57    'halfpage': ('Half Page Advert', 150000, 6),
58    'quarterpage': ('Quarter Page Advert', 100000, 7),
59    }
60
61class RegTypesSource(BasicSourceFactory):
62    """A source that delivers all kinds of registrations.
63    """
64    def getValues(self):
65        sorted_items = sorted(REGISTRATION_CATS.items(),
66                              key=lambda element: element[1][2])
67        return [item[0] for item in sorted_items]
68
69    def getTitle(self, value):
70        return u"%s @ ₦ %s" % (
71            REGISTRATION_CATS[value][0],
72            REGISTRATION_CATS[value][1])
73
74class IUnibenRegistration(IKofaObject):
75    """A Uniben registrant.
76    """
77
78    suspended = schema.Bool(
79        title = _(u'Account suspended'),
80        default = False,
81        required = False,
82        )
83
84    locked = schema.Bool(
85        title = _(u'Form locked'),
86        default = False,
87        required = False,
88        )
89
90    applicant_id = schema.TextLine(
91        title = _(u'Registrant Id'),
92        required = False,
93        readonly = False,
94        )
95
96    firstname = schema.TextLine(
97        title = _(u'First Name'),
98        required = True,
99        )
100
101    middlename = schema.TextLine(
102        title = _(u'Middle Name'),
103        required = False,
104        )
105
106    lastname = schema.TextLine(
107        title = _(u'Last Name (Surname)'),
108        required = True,
109        )
110
111    sex = schema.Choice(
112        title = _(u'Sex'),
113        source = GenderSource(),
114        required = True,
115        )
116
117    nationality = schema.Choice(
118        vocabulary = nats_vocab,
119        title = _(u'Nationality'),
120        required = False,
121        )
122
123    email = schema.ASCIILine(
124        title = _(u'Email Address'),
125        required = True,
126        constraint=validate_email,
127        )
128
129    phone = PhoneNumber(
130        title = _(u'Phone'),
131        description = u'',
132        required = False,
133        )
134
135    #perm_address = schema.Text(
136    #    title = _(u'Current Local Address'),
137    #    required = False,
138    #    readonly = False,
139    #    )
140
141    institution = schema.TextLine(
142        title = _(u'Institution/Organisation'),
143        required = False,
144        readonly = False,
145        )
146
147    city = schema.TextLine(
148        title = _(u'City'),
149        required = False,
150        readonly = False,
151        )
152
153    lga = schema.Choice(
154        source = LGASource(),
155        title = _(u'State/LGA'),
156        required = False,
157        )
158
159    matric_number = schema.TextLine(
160        title = _(u'Uniben Matriculation Number'),
161        required = False,
162        readonly = False,
163        )
164
165    registration_cats = schema.List(
166        title = _(u'Registration Categories'),
167        value_type = schema.Choice(source=RegTypesSource()),
168        required = True,
169        defaultFactory=list,
170        )
171
172#    @invariant
173#    def matric_number_exists(applicant):
174#        if applicant.matric_number:
175#            catalog = getUtility(ICatalog, name='students_catalog')
176#            accommodation_session = getSite()['hostels'].accommodation_session
177#            student = catalog.searchResults(matric_number=(
178#                applicant.matric_number, applicant.matric_number))
179#            if len(student) != 1:
180#                raise Invalid(_("Matriculation number not found."))
181
182class ICustomUGApplicant(INigeriaUGApplicant):
183    """An undergraduate applicant.
184
185    This interface defines the least common multiple of all fields
186    in ug application forms. In customized forms, fields can be excluded by
187    adding them to the UG_OMIT* tuples.
188    """
189
190class ICustomPGApplicant(INigeriaPGApplicant):
191    """A postgraduate applicant.
192
193    This interface defines the least common multiple of all fields
194    in pg application forms. In customized forms, fields can be excluded by
195    adding them to the PG_OMIT* tuples.
196    """
197
198    referees = schema.List(
199        title = _(u'Referees'),
200        value_type = RefereeEntryField(),
201        required = False,
202        defaultFactory=list,
203        )
204
205ICustomPGApplicant[
206    'referees'].order =  INigeriaPGApplicant['emp2_reason'].order
207
208class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant,
209    IUnibenRegistration):
210    """An interface for both types of applicants.
211
212    Attention: The ICustomPGApplicant field seetings will be overwritten
213    by ICustomPGApplicant field settings. If a field is defined
214    in both interfaces zope.schema validates only against the
215    constraints in ICustomUGApplicant. This does not affect the forms
216    since they are build on either ICustomUGApplicant or ICustomPGApplicant.
217    """
218
219    def writeLogMessage(view, comment):
220        """Adds an INFO message to the log file
221        """
222
223    def createStudent():
224        """Create a student object from applicant data
225        and copy applicant object.
226        """
227
228class ICustomUGApplicantEdit(INigeriaUGApplicantEdit):
229    """An undergraduate applicant interface for edit forms.
230
231    Here we can repeat the fields from base data and set the
232    `required` and `readonly` attributes to True to further restrict
233    the data access. Or we can allow only certain certificates to be
234    selected by choosing the appropriate source.
235
236    We cannot omit fields here. This has to be done in the
237    respective form page.
238    """
239
240class ICustomPGApplicantEdit(INigeriaPGApplicantEdit):
241    """A postgraduate applicant interface for editing.
242
243    Here we can repeat the fields from base data and set the
244    `required` and `readonly` attributes to True to further restrict
245    the data access. Or we can allow only certain certificates to be
246    selected by choosing the appropriate source.
247
248    We cannot omit fields here. This has to be done in the
249    respective form page.
250    """
251
252    referees = schema.List(
253        title = _(u'Referees'),
254        value_type = RefereeEntryField(),
255        required = False,
256        defaultFactory=list,
257        )
258
259ICustomPGApplicantEdit[
260    'referees'].order =  INigeriaPGApplicantEdit['emp2_reason'].order
261
262class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment):
263    """An applicant payment via payment gateways.
264
265    """
266
267class IPUTMEApplicantEdit(IPUTMEApplicantEdit):
268    """An undergraduate applicant interface for editing.
269
270    Here we can repeat the fields from base data and set the
271    `required` and `readonly` attributes to True to further restrict
272    the data access. Or we can allow only certain certificates to be
273    selected by choosing the appropriate source.
274
275    We cannot omit fields here. This has to be done in the
276    respective form page.
277    """
278
279class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo):
280    """Representation of an applicant.
281
282    Skip regular reg_number validation if reg_number is used for finding
283    the applicant object.
284    """
Note: See TracBrowser for help on using the repository browser.