[13814] | 1 | # -*- coding: utf-8 -*- |
---|
[7853] | 2 | ## $Id: interfaces.py 14020 2016-07-07 06:44:36Z 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 | |
---|
[13831] | 22 | #from grok import getSite |
---|
[8012] | 23 | from zope import schema |
---|
[13831] | 24 | #from zope.interface import invariant, Invalid |
---|
| 25 | #from zope.component import getUtility |
---|
| 26 | #from zope.catalog.interfaces import ICatalog |
---|
[13814] | 27 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[8051] | 28 | from waeup.kofa.applicants.interfaces import ( |
---|
[8053] | 29 | IApplicantBaseData, |
---|
[8051] | 30 | AppCatCertificateSource, CertificateSource) |
---|
| 31 | from waeup.kofa.schoolgrades import ResultEntryField |
---|
[8530] | 32 | from waeup.kofa.interfaces import ( |
---|
[13814] | 33 | SimpleKofaVocabulary, academic_sessions_vocab, validate_email, |
---|
| 34 | IKofaObject, ContextualDictSourceFactoryBase) |
---|
| 35 | from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber |
---|
[8530] | 36 | from waeup.kofa.students.vocabularies import nats_vocab, GenderSource |
---|
| 37 | from waeup.kofa.applicants.interfaces import contextual_reg_num_source |
---|
[8928] | 38 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 39 | LGASource, high_qual, high_grade, exam_types, |
---|
| 40 | INigeriaUGApplicant, INigeriaPGApplicant, |
---|
| 41 | INigeriaApplicantOnlinePayment, |
---|
[9006] | 42 | INigeriaUGApplicantEdit, INigeriaPGApplicantEdit, |
---|
| 43 | INigeriaApplicantUpdateByRegNo, |
---|
| 44 | IPUTMEApplicantEdit, |
---|
[8928] | 45 | ) |
---|
[8020] | 46 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[8247] | 47 | from waeup.uniben.payments.interfaces import ICustomOnlinePayment |
---|
[7853] | 48 | |
---|
[13814] | 49 | |
---|
| 50 | REGISTRATION_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), |
---|
[13824] | 55 | 'fullpage': ('Full Page Advert', 250000, 5), |
---|
| 56 | 'halfpage': ('Half Page Advert', 150000, 6), |
---|
| 57 | 'quarterpage': ('Quarter Page Advert', 100000, 7), |
---|
[13814] | 58 | } |
---|
| 59 | |
---|
| 60 | class 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 | |
---|
| 73 | class 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 | |
---|
[13819] | 110 | sex = schema.Choice( |
---|
| 111 | title = _(u'Sex'), |
---|
| 112 | source = GenderSource(), |
---|
| 113 | required = True, |
---|
[13814] | 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 | |
---|
[13819] | 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'), |
---|
[13814] | 142 | required = False, |
---|
| 143 | readonly = False, |
---|
| 144 | ) |
---|
| 145 | |
---|
[13828] | 146 | city = schema.TextLine( |
---|
| 147 | title = _(u'City'), |
---|
| 148 | required = False, |
---|
| 149 | readonly = False, |
---|
| 150 | ) |
---|
| 151 | |
---|
[13819] | 152 | lga = schema.Choice( |
---|
| 153 | source = LGASource(), |
---|
| 154 | title = _(u'State/LGA'), |
---|
| 155 | required = False, |
---|
| 156 | ) |
---|
| 157 | |
---|
[13831] | 158 | matric_number = schema.TextLine( |
---|
| 159 | title = _(u'Uniben Matriculation Number'), |
---|
| 160 | required = False, |
---|
| 161 | readonly = False, |
---|
| 162 | ) |
---|
| 163 | |
---|
[13814] | 164 | registration_cats = schema.List( |
---|
| 165 | title = _(u'Registration Categories'), |
---|
| 166 | value_type = schema.Choice(source=RegTypesSource()), |
---|
| 167 | required = True, |
---|
[14020] | 168 | defaultFactory=list, |
---|
[13814] | 169 | ) |
---|
| 170 | |
---|
[13831] | 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.")) |
---|
[13814] | 180 | |
---|
[8928] | 181 | class ICustomUGApplicant(INigeriaUGApplicant): |
---|
[8012] | 182 | """An undergraduate applicant. |
---|
| 183 | |
---|
[8519] | 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. |
---|
[8012] | 187 | """ |
---|
| 188 | |
---|
[8928] | 189 | class ICustomPGApplicant(INigeriaPGApplicant): |
---|
[7853] | 190 | """A postgraduate applicant. |
---|
| 191 | |
---|
[8519] | 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. |
---|
[7866] | 195 | """ |
---|
| 196 | |
---|
[8012] | 197 | |
---|
[13814] | 198 | class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant, |
---|
| 199 | IUnibenRegistration): |
---|
[8012] | 200 | """An interface for both types of applicants. |
---|
| 201 | |
---|
[8928] | 202 | Attention: The ICustomPGApplicant field seetings will be overwritten |
---|
| 203 | by ICustomPGApplicant field settings. If a field is defined |
---|
[8727] | 204 | in both interfaces zope.schema validates only against the |
---|
[8928] | 205 | constraints in ICustomUGApplicant. This does not affect the forms |
---|
| 206 | since they are build on either ICustomUGApplicant or ICustomPGApplicant. |
---|
[8012] | 207 | """ |
---|
| 208 | |
---|
[8743] | 209 | def writeLogMessage(view, comment): |
---|
[8053] | 210 | """Adds an INFO message to the log file |
---|
| 211 | """ |
---|
| 212 | |
---|
| 213 | def createStudent(): |
---|
[8668] | 214 | """Create a student object from applicant data |
---|
[8053] | 215 | and copy applicant object. |
---|
| 216 | """ |
---|
| 217 | |
---|
[9056] | 218 | class ICustomUGApplicantEdit(INigeriaUGApplicantEdit): |
---|
[8727] | 219 | """An undergraduate applicant interface for edit forms. |
---|
[8012] | 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 | |
---|
[9056] | 230 | class ICustomPGApplicantEdit(INigeriaPGApplicantEdit): |
---|
[7866] | 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. |
---|
[8017] | 240 | """ |
---|
[8454] | 241 | |
---|
[13814] | 242 | |
---|
[8928] | 243 | class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment): |
---|
[8247] | 244 | """An applicant payment via payment gateways. |
---|
| 245 | |
---|
| 246 | """ |
---|
[8530] | 247 | |
---|
[9056] | 248 | class IPUTMEApplicantEdit(IPUTMEApplicantEdit): |
---|
[8530] | 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 | |
---|
[9056] | 260 | class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo): |
---|
[8582] | 261 | """Representation of an applicant. |
---|
| 262 | |
---|
| 263 | Skip regular reg_number validation if reg_number is used for finding |
---|
| 264 | the applicant object. |
---|
| 265 | """ |
---|