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

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

Add matric_number.

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