[13814] | 1 | # -*- coding: utf-8 -*- |
---|
[7853] | 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 | |
---|
[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 |
---|
[14106] | 37 | from waeup.kofa.refereeentries import RefereeEntryField |
---|
[8530] | 38 | from waeup.kofa.applicants.interfaces import contextual_reg_num_source |
---|
[8928] | 39 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 40 | LGASource, high_qual, high_grade, exam_types, |
---|
| 41 | INigeriaUGApplicant, INigeriaPGApplicant, |
---|
| 42 | INigeriaApplicantOnlinePayment, |
---|
[9006] | 43 | INigeriaUGApplicantEdit, INigeriaPGApplicantEdit, |
---|
| 44 | INigeriaApplicantUpdateByRegNo, |
---|
| 45 | IPUTMEApplicantEdit, |
---|
[8928] | 46 | ) |
---|
[8020] | 47 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[8247] | 48 | from waeup.uniben.payments.interfaces import ICustomOnlinePayment |
---|
[7853] | 49 | |
---|
[13814] | 50 | |
---|
| 51 | REGISTRATION_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), |
---|
[13824] | 56 | 'fullpage': ('Full Page Advert', 250000, 5), |
---|
| 57 | 'halfpage': ('Half Page Advert', 150000, 6), |
---|
| 58 | 'quarterpage': ('Quarter Page Advert', 100000, 7), |
---|
[13814] | 59 | } |
---|
| 60 | |
---|
| 61 | class 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 | |
---|
| 74 | class 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 | |
---|
[13819] | 111 | sex = schema.Choice( |
---|
| 112 | title = _(u'Sex'), |
---|
| 113 | source = GenderSource(), |
---|
| 114 | required = True, |
---|
[13814] | 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 | |
---|
[13819] | 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'), |
---|
[13814] | 143 | required = False, |
---|
| 144 | readonly = False, |
---|
| 145 | ) |
---|
| 146 | |
---|
[13828] | 147 | city = schema.TextLine( |
---|
| 148 | title = _(u'City'), |
---|
| 149 | required = False, |
---|
| 150 | readonly = False, |
---|
| 151 | ) |
---|
| 152 | |
---|
[13819] | 153 | lga = schema.Choice( |
---|
| 154 | source = LGASource(), |
---|
| 155 | title = _(u'State/LGA'), |
---|
| 156 | required = False, |
---|
| 157 | ) |
---|
| 158 | |
---|
[13831] | 159 | matric_number = schema.TextLine( |
---|
| 160 | title = _(u'Uniben Matriculation Number'), |
---|
| 161 | required = False, |
---|
| 162 | readonly = False, |
---|
| 163 | ) |
---|
| 164 | |
---|
[13814] | 165 | registration_cats = schema.List( |
---|
| 166 | title = _(u'Registration Categories'), |
---|
| 167 | value_type = schema.Choice(source=RegTypesSource()), |
---|
| 168 | required = True, |
---|
[14020] | 169 | defaultFactory=list, |
---|
[13814] | 170 | ) |
---|
| 171 | |
---|
[13831] | 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.")) |
---|
[13814] | 181 | |
---|
[8928] | 182 | class ICustomUGApplicant(INigeriaUGApplicant): |
---|
[8012] | 183 | """An undergraduate applicant. |
---|
| 184 | |
---|
[8519] | 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. |
---|
[8012] | 188 | """ |
---|
| 189 | |
---|
[8928] | 190 | class ICustomPGApplicant(INigeriaPGApplicant): |
---|
[7853] | 191 | """A postgraduate applicant. |
---|
| 192 | |
---|
[8519] | 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. |
---|
[7866] | 196 | """ |
---|
| 197 | |
---|
[14106] | 198 | referees = schema.List( |
---|
| 199 | title = _(u'Referees'), |
---|
| 200 | value_type = RefereeEntryField(), |
---|
| 201 | required = False, |
---|
| 202 | defaultFactory=list, |
---|
| 203 | ) |
---|
[8012] | 204 | |
---|
[14106] | 205 | ICustomPGApplicant[ |
---|
| 206 | 'referees'].order = INigeriaPGApplicant['emp2_reason'].order |
---|
| 207 | |
---|
[13814] | 208 | class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant, |
---|
| 209 | IUnibenRegistration): |
---|
[8012] | 210 | """An interface for both types of applicants. |
---|
| 211 | |
---|
[8928] | 212 | Attention: The ICustomPGApplicant field seetings will be overwritten |
---|
| 213 | by ICustomPGApplicant field settings. If a field is defined |
---|
[8727] | 214 | in both interfaces zope.schema validates only against the |
---|
[8928] | 215 | constraints in ICustomUGApplicant. This does not affect the forms |
---|
| 216 | since they are build on either ICustomUGApplicant or ICustomPGApplicant. |
---|
[8012] | 217 | """ |
---|
| 218 | |
---|
[8743] | 219 | def writeLogMessage(view, comment): |
---|
[8053] | 220 | """Adds an INFO message to the log file |
---|
| 221 | """ |
---|
| 222 | |
---|
| 223 | def createStudent(): |
---|
[8668] | 224 | """Create a student object from applicant data |
---|
[8053] | 225 | and copy applicant object. |
---|
| 226 | """ |
---|
| 227 | |
---|
[9056] | 228 | class ICustomUGApplicantEdit(INigeriaUGApplicantEdit): |
---|
[8727] | 229 | """An undergraduate applicant interface for edit forms. |
---|
[8012] | 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 | |
---|
[9056] | 240 | class ICustomPGApplicantEdit(INigeriaPGApplicantEdit): |
---|
[7866] | 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. |
---|
[8017] | 250 | """ |
---|
[8454] | 251 | |
---|
[14106] | 252 | referees = schema.List( |
---|
| 253 | title = _(u'Referees'), |
---|
| 254 | value_type = RefereeEntryField(), |
---|
| 255 | required = False, |
---|
| 256 | defaultFactory=list, |
---|
| 257 | ) |
---|
[13814] | 258 | |
---|
[14106] | 259 | ICustomPGApplicantEdit[ |
---|
| 260 | 'referees'].order = INigeriaPGApplicantEdit['emp2_reason'].order |
---|
| 261 | |
---|
[8928] | 262 | class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment): |
---|
[8247] | 263 | """An applicant payment via payment gateways. |
---|
| 264 | |
---|
| 265 | """ |
---|
[8530] | 266 | |
---|
[9056] | 267 | class IPUTMEApplicantEdit(IPUTMEApplicantEdit): |
---|
[8530] | 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 | |
---|
[9056] | 279 | class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo): |
---|
[8582] | 280 | """Representation of an applicant. |
---|
| 281 | |
---|
| 282 | Skip regular reg_number validation if reg_number is used for finding |
---|
| 283 | the applicant object. |
---|
| 284 | """ |
---|