[5638] | 1 | ## $Id: interfaces.py 7708 2012-02-27 11:52:23Z henrik $ |
---|
[6076] | 2 | ## |
---|
[6087] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
[5638] | 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
[6076] | 8 | ## |
---|
[5638] | 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
[6076] | 13 | ## |
---|
[5638] | 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[6500] | 18 | """Interfaces of the university application package. |
---|
[5638] | 19 | """ |
---|
[6256] | 20 | |
---|
[5866] | 21 | from grokcore.content.interfaces import IContainer |
---|
[6256] | 22 | |
---|
[5638] | 23 | from zope import schema |
---|
[7263] | 24 | from zope.interface import Interface, Attribute, implements, directlyProvides |
---|
[7683] | 25 | from zope.component import getUtilitiesFor, queryUtility, getUtility |
---|
[7263] | 26 | from zope.catalog.interfaces import ICatalog |
---|
[7317] | 27 | from zope.schema.interfaces import ( |
---|
| 28 | ValidationError, ISource, IContextSourceBinder) |
---|
[6256] | 29 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[7683] | 30 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[7263] | 31 | from waeup.sirp.schema import TextLineChoice |
---|
[7250] | 32 | from waeup.sirp.interfaces import ( |
---|
[7321] | 33 | ISIRPObject, year_range, validate_email, academic_sessions_vocab) |
---|
[7708] | 34 | from waeup.sirp.interfaces import MessageFactory as _ |
---|
[7436] | 35 | from waeup.sirp.university.vocabularies import ( |
---|
[7681] | 36 | course_levels, AppCatSource) |
---|
[7347] | 37 | from waeup.sirp.students.vocabularies import ( |
---|
[7436] | 38 | lgas_vocab, CertificateSource, GenderSource) |
---|
[7250] | 39 | from waeup.sirp.payments.interfaces import IOnlinePayment |
---|
[5638] | 40 | |
---|
[7075] | 41 | #: Maximum upload size for applicant passport photographs (in bytes) |
---|
[7086] | 42 | MAX_UPLOAD_SIZE = 1024 * 20 |
---|
[7075] | 43 | |
---|
[7263] | 44 | class RegNumInSource(ValidationError): |
---|
| 45 | """Registration number exists already |
---|
| 46 | """ |
---|
| 47 | # The docstring of ValidationErrors is used as error description |
---|
| 48 | # by zope.formlib. |
---|
| 49 | pass |
---|
| 50 | |
---|
| 51 | class RegNumberSource(object): |
---|
| 52 | implements(ISource) |
---|
| 53 | cat_name = 'applicants_catalog' |
---|
[7270] | 54 | field_name = 'reg_number' |
---|
[7263] | 55 | validation_error = RegNumInSource |
---|
| 56 | def __init__(self, context): |
---|
| 57 | self.context = context |
---|
| 58 | return |
---|
| 59 | |
---|
| 60 | def __contains__(self, value): |
---|
| 61 | cat = queryUtility(ICatalog, self.cat_name) |
---|
| 62 | if cat is None: |
---|
| 63 | return True |
---|
| 64 | kw = {self.field_name: (value, value)} |
---|
| 65 | results = cat.searchResults(**kw) |
---|
| 66 | for entry in results: |
---|
| 67 | if entry.applicant_id != self.context.applicant_id: |
---|
| 68 | # XXX: sources should simply return False. |
---|
| 69 | # But then we get some stupid error message in forms |
---|
| 70 | # when validation fails. |
---|
| 71 | raise self.validation_error(value) |
---|
| 72 | #return False |
---|
| 73 | return True |
---|
| 74 | |
---|
| 75 | def contextual_reg_num_source(context): |
---|
| 76 | source = RegNumberSource(context) |
---|
| 77 | return source |
---|
| 78 | directlyProvides(contextual_reg_num_source, IContextSourceBinder) |
---|
| 79 | |
---|
[7683] | 80 | class AppCatCertificateSource(CertificateSource): |
---|
| 81 | """An application certificate source delivers all courses which belong to |
---|
| 82 | a certain application_category. |
---|
| 83 | """ |
---|
| 84 | def getValues(self, context): |
---|
| 85 | # appliction category not available when certificate was deleted. |
---|
| 86 | # shouldn't that info be part of applicant info instead? |
---|
| 87 | # when we cannot determine the appcat, we will display all courses. |
---|
| 88 | appcat = getattr(getattr(context, '__parent__', None), |
---|
| 89 | 'application_category', None) |
---|
| 90 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 91 | result = catalog.searchResults( |
---|
| 92 | application_category=(appcat,appcat)) |
---|
| 93 | result = sorted(result, key=lambda value: value.code) |
---|
| 94 | curr_course = context.course1 |
---|
| 95 | if curr_course is not None and curr_course not in result: |
---|
| 96 | # display also current course even if it is not catalogued |
---|
| 97 | # (any more) |
---|
| 98 | result = [curr_course,] + result |
---|
| 99 | return result |
---|
| 100 | |
---|
| 101 | class ApplicationTypeSource(BasicContextualSourceFactory): |
---|
| 102 | """An application type source delivers screening types defined in the |
---|
| 103 | portal. |
---|
| 104 | """ |
---|
| 105 | def getValues(self, context): |
---|
[7688] | 106 | appcats_dict = getUtility( |
---|
[7683] | 107 | IApplicantsUtils).getApplicationTypeDict() |
---|
[7688] | 108 | return sorted(appcats_dict.keys()) |
---|
[7683] | 109 | |
---|
| 110 | def getToken(self, context, value): |
---|
| 111 | return value |
---|
| 112 | |
---|
| 113 | def getTitle(self, context, value): |
---|
[7688] | 114 | appcats_dict = getUtility( |
---|
| 115 | IApplicantsUtils).getApplicationTypeDict() |
---|
| 116 | return appcats_dict[value][0] |
---|
[7683] | 117 | |
---|
| 118 | # Maybe Uniben still needs this ... |
---|
| 119 | #class ApplicationPinSource(BasicContextualSourceFactory): |
---|
| 120 | # """An application pin source delivers PIN prefixes for application |
---|
| 121 | # defined in the portal. |
---|
| 122 | # """ |
---|
| 123 | # def getValues(self, context): |
---|
[7688] | 124 | # apppins_dict = getUtility( |
---|
[7683] | 125 | # IApplicantsUtils).getApplicationTypeDict() |
---|
[7688] | 126 | # return sorted(appcats_dict.keys()) |
---|
[7683] | 127 | # |
---|
| 128 | # def getToken(self, context, value): |
---|
| 129 | # return value |
---|
| 130 | # |
---|
| 131 | # def getTitle(self, context, value): |
---|
[7688] | 132 | # apppins_dict = getUtility( |
---|
| 133 | # IApplicantsUtils).getApplicationTypeDict() |
---|
[7683] | 134 | # return u"%s (%s)" % ( |
---|
[7688] | 135 | # apppins_dict[value][1],self.apppins_dict[value][0]) |
---|
[7683] | 136 | |
---|
[6069] | 137 | class ApplicantContainerProviderSource(BasicSourceFactory): |
---|
[6075] | 138 | """A source offering all available applicants container types. |
---|
| 139 | |
---|
| 140 | The values returned by this source are names of utilities that can |
---|
| 141 | create :class:`ApplicantContainer` instances. So, if you get a |
---|
| 142 | name like ``'myactype'`` from this source, then you can do: |
---|
| 143 | |
---|
| 144 | >>> from zope.component import getUtility |
---|
| 145 | >>> p = getUtility(IApplicantsContainerProvider, name=myactype) |
---|
| 146 | >>> my_applicants_container = p.factory() |
---|
| 147 | |
---|
| 148 | Or you can access class-attributes like |
---|
| 149 | |
---|
| 150 | >>> my_applicants_container.container_title |
---|
| 151 | 'Pretty' |
---|
[6076] | 152 | |
---|
[6069] | 153 | """ |
---|
| 154 | def getValues(self): |
---|
[6075] | 155 | """Returns a list of ``(<name>, <provider>)`` tuples. |
---|
[5753] | 156 | |
---|
[6075] | 157 | Here ``<name>`` is the name under which an |
---|
| 158 | :class:``ApplicantContainerProvider`` was registered as a |
---|
| 159 | utility and ``<provider>`` is the utility itself. |
---|
| 160 | """ |
---|
| 161 | return getUtilitiesFor(IApplicantsContainerProvider) |
---|
| 162 | |
---|
[6069] | 163 | def getToken(self, value): |
---|
[6075] | 164 | """Return the name of the ``(<name>, <provider>)`` tuple. |
---|
| 165 | """ |
---|
| 166 | return value[0] |
---|
| 167 | |
---|
[6069] | 168 | def getTitle(self, value): |
---|
[6075] | 169 | """Get a 'title - description' string for a container type. |
---|
| 170 | """ |
---|
| 171 | factory = value[1].factory |
---|
| 172 | return "%s - %s" % ( |
---|
| 173 | factory.container_title, factory.container_description) |
---|
[6069] | 174 | |
---|
[7682] | 175 | class IApplicantsUtils(Interface): |
---|
| 176 | """A collection of methods which are subject to customization. |
---|
| 177 | """ |
---|
[7683] | 178 | pass |
---|
[7682] | 179 | |
---|
[7321] | 180 | class IApplicantsRoot(ISIRPObject, IContainer): |
---|
[5676] | 181 | """A container for university applicants containers. |
---|
[5645] | 182 | """ |
---|
[5866] | 183 | pass |
---|
[5638] | 184 | |
---|
[7321] | 185 | class IApplicantsContainer(ISIRPObject): |
---|
[5676] | 186 | """An applicants container contains university applicants. |
---|
[5645] | 187 | |
---|
[5638] | 188 | """ |
---|
[6069] | 189 | |
---|
[6075] | 190 | container_title = Attribute( |
---|
| 191 | u'classattribute: title for type of container') |
---|
| 192 | container_description = Attribute( |
---|
| 193 | u'classattribute: description for type of container') |
---|
| 194 | |
---|
[6076] | 195 | |
---|
[6069] | 196 | code = schema.TextLine( |
---|
[7708] | 197 | title = _(u'Code'), |
---|
[6087] | 198 | default = u'-', |
---|
[6069] | 199 | required = True, |
---|
| 200 | readonly = True, |
---|
[6076] | 201 | ) |
---|
[6096] | 202 | |
---|
[6087] | 203 | title = schema.TextLine( |
---|
[7708] | 204 | title = _(u'Title'), |
---|
[6087] | 205 | required = True, |
---|
| 206 | default = u'-', |
---|
| 207 | readonly = True, |
---|
[6096] | 208 | ) |
---|
| 209 | |
---|
[6087] | 210 | prefix = schema.Choice( |
---|
[7708] | 211 | title = _(u'Application Target'), |
---|
[6087] | 212 | required = True, |
---|
| 213 | default = None, |
---|
[7683] | 214 | source = ApplicationTypeSource(), |
---|
[6087] | 215 | readonly = True, |
---|
| 216 | ) |
---|
[6076] | 217 | |
---|
[7436] | 218 | entry_level = schema.Choice( |
---|
[7708] | 219 | title = _(u'Entry Level'), |
---|
[7436] | 220 | vocabulary = course_levels, |
---|
| 221 | default = 100, |
---|
| 222 | required = True, |
---|
| 223 | ) |
---|
| 224 | |
---|
[6087] | 225 | year = schema.Choice( |
---|
[7708] | 226 | title = _(u'Year of Entrance'), |
---|
[6087] | 227 | required = True, |
---|
| 228 | default = None, |
---|
[6158] | 229 | values = year_range(), |
---|
[6087] | 230 | readonly = True, |
---|
[6096] | 231 | ) |
---|
[6087] | 232 | |
---|
[6069] | 233 | provider = schema.Choice( |
---|
[7708] | 234 | title = _(u'Applicants Container Type'), |
---|
[6069] | 235 | required = True, |
---|
| 236 | default = None, |
---|
| 237 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 238 | readonly = True, |
---|
[6076] | 239 | ) |
---|
[6158] | 240 | |
---|
[7683] | 241 | # Maybe Uniben still needs this ... |
---|
[7376] | 242 | #ac_prefix = schema.Choice( |
---|
| 243 | # title = u'Activation code prefix', |
---|
| 244 | # required = True, |
---|
| 245 | # default = None, |
---|
[7683] | 246 | # source = ApplicationPinSource(), |
---|
[7376] | 247 | # ) |
---|
[6076] | 248 | |
---|
[6189] | 249 | application_category = schema.Choice( |
---|
[7708] | 250 | title = _(u'Category for the grouping of certificates'), |
---|
[6189] | 251 | required = True, |
---|
| 252 | default = None, |
---|
[7681] | 253 | source = AppCatSource(), |
---|
[6189] | 254 | ) |
---|
| 255 | |
---|
[5645] | 256 | description = schema.Text( |
---|
[7708] | 257 | title = _(u'Human readable description in reST format'), |
---|
[5638] | 258 | required = False, |
---|
[6518] | 259 | default = u'''This text can been seen by anonymous users. |
---|
[7708] | 260 | Here we put mult-lingual information about the study courses provided, the application procedure and deadlines. |
---|
| 261 | >>de<< |
---|
| 262 | Dieser Text kann von anonymen Benutzern gelesen werden. |
---|
| 263 | Hier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.''' |
---|
[5638] | 264 | ) |
---|
| 265 | |
---|
[7708] | 266 | description_dict = schema.Dict( |
---|
| 267 | title = u'Content as language dictionary with values in html format', |
---|
| 268 | required = False, |
---|
| 269 | default = {}, |
---|
| 270 | ) |
---|
| 271 | |
---|
[5638] | 272 | startdate = schema.Date( |
---|
[7708] | 273 | title = _(u'Application Start Date'), |
---|
[5638] | 274 | required = False, |
---|
| 275 | default = None, |
---|
| 276 | ) |
---|
| 277 | |
---|
| 278 | enddate = schema.Date( |
---|
[7708] | 279 | title = _(u'Application Closing Date'), |
---|
[5638] | 280 | required = False, |
---|
| 281 | default = None, |
---|
| 282 | ) |
---|
| 283 | |
---|
[5645] | 284 | strict_deadline = schema.Bool( |
---|
[7708] | 285 | title = _(u'Forbid additions after deadline (enddate)'), |
---|
[5645] | 286 | required = True, |
---|
| 287 | default = True, |
---|
| 288 | ) |
---|
[5638] | 289 | |
---|
| 290 | def archive(id=None): |
---|
[5676] | 291 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 292 | |
---|
[5676] | 293 | If id is `None`, all applicants are archived. |
---|
[5638] | 294 | |
---|
| 295 | If id contains a single id string, only the respective |
---|
[5676] | 296 | applicants are archived. |
---|
[5638] | 297 | |
---|
| 298 | If id contains a list of id strings all of the respective |
---|
[5676] | 299 | applicants types are saved to disk. |
---|
[5638] | 300 | """ |
---|
| 301 | |
---|
| 302 | def clear(id=None, archive=True): |
---|
[5676] | 303 | """Remove applicants of type given by 'id'. |
---|
[5638] | 304 | |
---|
[5676] | 305 | Optionally archive the applicants. |
---|
[6076] | 306 | |
---|
[5676] | 307 | If id is `None`, all applicants are archived. |
---|
[5638] | 308 | |
---|
| 309 | If id contains a single id string, only the respective |
---|
[5676] | 310 | applicants are archived. |
---|
[5638] | 311 | |
---|
| 312 | If id contains a list of id strings all of the respective |
---|
[5676] | 313 | applicant types are saved to disk. |
---|
[5638] | 314 | |
---|
| 315 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 316 | and respective applicants are simply removed from the |
---|
[5638] | 317 | database. |
---|
| 318 | """ |
---|
[6073] | 319 | |
---|
[6069] | 320 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 321 | """An applicants container contains university applicants. |
---|
| 322 | """ |
---|
[6087] | 323 | prefix = schema.Choice( |
---|
[7708] | 324 | title = _(u'Application Target'), |
---|
[6069] | 325 | required = True, |
---|
[6087] | 326 | default = None, |
---|
[7683] | 327 | source = ApplicationTypeSource(), |
---|
[6069] | 328 | readonly = False, |
---|
[6076] | 329 | ) |
---|
[6073] | 330 | |
---|
[6087] | 331 | year = schema.Choice( |
---|
[7708] | 332 | title = _(u'Year of Entrance'), |
---|
[6087] | 333 | required = True, |
---|
| 334 | default = None, |
---|
[6158] | 335 | values = year_range(), |
---|
[6087] | 336 | readonly = False, |
---|
[6096] | 337 | ) |
---|
[6073] | 338 | |
---|
[6087] | 339 | provider = schema.Choice( |
---|
[7708] | 340 | title = _(u'Applicants Container Type'), |
---|
[6087] | 341 | required = True, |
---|
| 342 | default = None, |
---|
| 343 | source = ApplicantContainerProviderSource(), |
---|
| 344 | readonly = False, |
---|
| 345 | ) |
---|
| 346 | |
---|
[6096] | 347 | IApplicantsContainerAdd[ |
---|
| 348 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 349 | IApplicantsContainerAdd[ |
---|
| 350 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 351 | IApplicantsContainerAdd[ |
---|
| 352 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 353 | |
---|
[7321] | 354 | class IApplicantBaseData(ISIRPObject): |
---|
[5753] | 355 | """The data for an applicant. |
---|
| 356 | |
---|
[7240] | 357 | This is a base interface with no field |
---|
[5753] | 358 | required. For use with importers, forms, etc., please use one of |
---|
| 359 | the derived interfaces below, which set more fields to required |
---|
| 360 | state, depending on use-case. |
---|
[7338] | 361 | |
---|
| 362 | This base interface is also implemented by the StudentApplication |
---|
| 363 | class in the students package. Thus, these are the data which are saved |
---|
| 364 | after admission. |
---|
[5753] | 365 | """ |
---|
[6304] | 366 | |
---|
[7240] | 367 | applicant_id = schema.TextLine( |
---|
[7708] | 368 | title = _(u'Applicant Id'), |
---|
[7240] | 369 | required = False, |
---|
[7260] | 370 | readonly = False, |
---|
[7240] | 371 | ) |
---|
[7270] | 372 | reg_number = TextLineChoice( |
---|
[7708] | 373 | title = _(u'JAMB Registration Number'), |
---|
[7263] | 374 | readonly = False, |
---|
| 375 | required = True, |
---|
| 376 | default = None, |
---|
| 377 | source = contextual_reg_num_source, |
---|
[5753] | 378 | ) |
---|
[7376] | 379 | #access_code = schema.TextLine( |
---|
| 380 | # title = u'Activation Code', |
---|
| 381 | # required = False, |
---|
| 382 | # readonly = True, |
---|
| 383 | # ) |
---|
[5753] | 384 | firstname = schema.TextLine( |
---|
[7708] | 385 | title = _(u'First Name'), |
---|
[6352] | 386 | required = True, |
---|
[5753] | 387 | ) |
---|
[7356] | 388 | middlename = schema.TextLine( |
---|
[7708] | 389 | title = _(u'Middle Name'), |
---|
[5753] | 390 | required = False, |
---|
| 391 | ) |
---|
| 392 | lastname = schema.TextLine( |
---|
[7708] | 393 | title = _(u'Last Name (Surname)'), |
---|
[6352] | 394 | required = True, |
---|
[5753] | 395 | ) |
---|
| 396 | date_of_birth = schema.Date( |
---|
[7708] | 397 | title = _(u'Date of Birth'), |
---|
[6352] | 398 | required = True, |
---|
[5753] | 399 | ) |
---|
[6249] | 400 | lga = schema.Choice( |
---|
| 401 | source = lgas_vocab, |
---|
[7708] | 402 | title = _(u'State/LGA'), |
---|
[6254] | 403 | default = 'foreigner', |
---|
| 404 | required = True, |
---|
[5753] | 405 | ) |
---|
| 406 | sex = schema.Choice( |
---|
[7708] | 407 | title = _(u'Sex'), |
---|
[5753] | 408 | source = GenderSource(), |
---|
| 409 | default = u'm', |
---|
[6352] | 410 | required = True, |
---|
[5753] | 411 | ) |
---|
[6341] | 412 | email = schema.ASCIILine( |
---|
[7708] | 413 | title = _(u'Email Address'), |
---|
[7240] | 414 | required = True, |
---|
[6343] | 415 | constraint=validate_email, |
---|
[5753] | 416 | ) |
---|
[7324] | 417 | phone = schema.TextLine( |
---|
[7708] | 418 | title = _(u'Phone'), |
---|
[7331] | 419 | description = u'', |
---|
[5753] | 420 | required = False, |
---|
| 421 | ) |
---|
[7262] | 422 | course1 = schema.Choice( |
---|
[7708] | 423 | title = _(u'1st Choice Course of Study'), |
---|
[7347] | 424 | source = CertificateSource(), |
---|
[7262] | 425 | required = True, |
---|
| 426 | ) |
---|
| 427 | course2 = schema.Choice( |
---|
[7708] | 428 | title = _(u'2nd Choice Course of Study'), |
---|
[7347] | 429 | source = CertificateSource(), |
---|
[7262] | 430 | required = False, |
---|
| 431 | ) |
---|
[6322] | 432 | |
---|
[5753] | 433 | # |
---|
[7338] | 434 | # Data to be imported after screening |
---|
[5753] | 435 | # |
---|
[6255] | 436 | screening_score = schema.Int( |
---|
[7708] | 437 | title = _(u'Screening Score'), |
---|
[5753] | 438 | required = False, |
---|
| 439 | ) |
---|
| 440 | screening_venue = schema.TextLine( |
---|
[7708] | 441 | title = _(u'Screening Venue'), |
---|
[5753] | 442 | required = False, |
---|
| 443 | ) |
---|
[6248] | 444 | course_admitted = schema.Choice( |
---|
[7708] | 445 | title = _(u'Admitted Course of Study'), |
---|
[7347] | 446 | source = CertificateSource(), |
---|
[6254] | 447 | default = None, |
---|
[5753] | 448 | required = False, |
---|
| 449 | ) |
---|
[7347] | 450 | notice = schema.Text( |
---|
[7708] | 451 | title = _(u'Notice'), |
---|
[7347] | 452 | required = False, |
---|
| 453 | ) |
---|
[7338] | 454 | |
---|
| 455 | class IApplicantProcessData(IApplicantBaseData): |
---|
| 456 | """An applicant. |
---|
| 457 | |
---|
| 458 | Here we add process attributes and methods to the base data. |
---|
| 459 | """ |
---|
| 460 | |
---|
| 461 | history = Attribute('Object history, a list of messages.') |
---|
| 462 | state = Attribute('The application state of an applicant') |
---|
[7364] | 463 | display_fullname = Attribute('The fullname of an applicant') |
---|
[7338] | 464 | application_date = Attribute('Date of submission, used for export only') |
---|
| 465 | password = Attribute('Encrypted password of a applicant') |
---|
| 466 | application_number = Attribute('The key under which the record is stored') |
---|
| 467 | |
---|
| 468 | def loggerInfo(ob_class, comment): |
---|
| 469 | """Adds an INFO message to the log file |
---|
| 470 | """ |
---|
| 471 | |
---|
[5753] | 472 | student_id = schema.TextLine( |
---|
[7708] | 473 | title = _(u'Student Id'), |
---|
[5753] | 474 | required = False, |
---|
[7351] | 475 | readonly = False, |
---|
[5753] | 476 | ) |
---|
[6302] | 477 | locked = schema.Bool( |
---|
[7708] | 478 | title = _(u'Form locked'), |
---|
[6302] | 479 | default = False, |
---|
| 480 | ) |
---|
[5753] | 481 | |
---|
[7338] | 482 | class IApplicant(IApplicantProcessData): |
---|
[5753] | 483 | """An applicant. |
---|
| 484 | |
---|
| 485 | This is basically the applicant base data. Here we repeat the |
---|
[6195] | 486 | fields from base data if we have to set the `required` attribute |
---|
| 487 | to True (which is the default). |
---|
[5753] | 488 | """ |
---|
| 489 | |
---|
[7338] | 490 | class IApplicantEdit(IApplicantProcessData): |
---|
[6195] | 491 | """An applicant. |
---|
[5753] | 492 | |
---|
[6339] | 493 | Here we can repeat the fields from base data and set the |
---|
| 494 | `required` and `readonly` attributes to True to further restrict |
---|
[7262] | 495 | the data access. Or we can allow only certain certificates to be |
---|
| 496 | selected by choosing the appropriate source. |
---|
| 497 | |
---|
| 498 | We cannot omit fields here. This has to be done in the |
---|
[6339] | 499 | respective form page. |
---|
[6195] | 500 | """ |
---|
[7262] | 501 | |
---|
| 502 | course1 = schema.Choice( |
---|
[7708] | 503 | title = _(u'1st Choice Course of Study'), |
---|
[7347] | 504 | source = AppCatCertificateSource(), |
---|
[7262] | 505 | required = True, |
---|
| 506 | ) |
---|
| 507 | course2 = schema.Choice( |
---|
[7708] | 508 | title = _(u'2nd Choice Course of Study'), |
---|
[7347] | 509 | source = AppCatCertificateSource(), |
---|
[7262] | 510 | required = False, |
---|
| 511 | ) |
---|
[6255] | 512 | screening_score = schema.Int( |
---|
[7708] | 513 | title = _(u'Screening Score'), |
---|
[6195] | 514 | required = False, |
---|
[5941] | 515 | readonly = True, |
---|
| 516 | ) |
---|
[6195] | 517 | screening_venue = schema.TextLine( |
---|
[7708] | 518 | title = _(u'Screening Venue'), |
---|
[5753] | 519 | required = False, |
---|
| 520 | readonly = True, |
---|
| 521 | ) |
---|
[6301] | 522 | course_admitted = schema.Choice( |
---|
[7708] | 523 | title = _(u'Admitted Course of Study'), |
---|
[7347] | 524 | source = CertificateSource(), |
---|
[6301] | 525 | default = None, |
---|
[5753] | 526 | required = False, |
---|
[6195] | 527 | readonly = True, |
---|
[5753] | 528 | ) |
---|
[6195] | 529 | notice = schema.Text( |
---|
[7708] | 530 | title = _(u'Notice'), |
---|
[5753] | 531 | required = False, |
---|
| 532 | readonly = True, |
---|
| 533 | ) |
---|
[5758] | 534 | |
---|
[7338] | 535 | def createStudent(): |
---|
| 536 | """Create a student object from applicatnt data |
---|
| 537 | and copy applicant object. |
---|
| 538 | """ |
---|
| 539 | |
---|
[7268] | 540 | class IApplicantUpdateByRegNo(IApplicant): |
---|
| 541 | """Representation of an applicant. |
---|
| 542 | |
---|
[7270] | 543 | Skip regular reg_number validation if reg_number is used for finding |
---|
[7268] | 544 | the applicant object. |
---|
| 545 | """ |
---|
[7270] | 546 | reg_number = schema.TextLine( |
---|
[7268] | 547 | title = u'Registration Number', |
---|
| 548 | default = None, |
---|
| 549 | required = False, |
---|
| 550 | ) |
---|
| 551 | |
---|
[7250] | 552 | class IApplicantOnlinePayment(IOnlinePayment): |
---|
| 553 | """An applicant payment via payment gateways. |
---|
| 554 | |
---|
| 555 | """ |
---|
| 556 | p_year = schema.Choice( |
---|
[7708] | 557 | title = _(u'Payment Session'), |
---|
[7250] | 558 | source = academic_sessions_vocab, |
---|
| 559 | required = False, |
---|
| 560 | ) |
---|
| 561 | |
---|
| 562 | IApplicantOnlinePayment['p_year'].order = IApplicantOnlinePayment[ |
---|
| 563 | 'p_year'].order |
---|
| 564 | |
---|
[5846] | 565 | class IApplicantsContainerProvider(Interface): |
---|
[5820] | 566 | """A provider for applicants containers. |
---|
| 567 | |
---|
| 568 | Applicants container providers are meant to be looked up as |
---|
| 569 | utilities. This way we can find all applicant container types |
---|
| 570 | defined somewhere. |
---|
| 571 | |
---|
| 572 | Each applicants container provider registered as utility provides |
---|
| 573 | one container type and one should be able to call the `factory` |
---|
| 574 | attribute to create an instance of the requested container type. |
---|
| 575 | |
---|
| 576 | .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested) |
---|
[6076] | 577 | |
---|
[6500] | 578 | Samples: |
---|
[6076] | 579 | |
---|
[5820] | 580 | Given, you had an IApplicantsContainer implementation somewhere |
---|
| 581 | and you would like to make it findable on request, then you would |
---|
| 582 | normally create an appropriate provider utility like this:: |
---|
| 583 | |
---|
| 584 | import grok |
---|
[5846] | 585 | from waeup.sirp.applicants.interfaces import IApplicantsContainerProvider |
---|
[5820] | 586 | |
---|
| 587 | class MyContainerProvider(grok.GlobalUtility): |
---|
[5846] | 588 | grok.implements(IApplicantsContainerProvider) |
---|
[5820] | 589 | grok.name('MyContainerProvider') # Must be unique |
---|
| 590 | factory = MyContainer # A class implementing IApplicantsContainer |
---|
| 591 | # or derivations thereof. |
---|
| 592 | |
---|
| 593 | This utility would be registered on startup and could then be used |
---|
| 594 | like this: |
---|
| 595 | |
---|
| 596 | >>> from zope.component import getAllUtilitiesRegisteredFor |
---|
| 597 | >>> from waeup.sirp.applicants.interfaces import ( |
---|
[5846] | 598 | ... IApplicantsContainerProvider) |
---|
[5820] | 599 | >>> all_providers = getAllUtilitiesRegisteredFor( |
---|
[5846] | 600 | ... IApplicantsContainerProvider) |
---|
[5820] | 601 | >>> all_providers |
---|
| 602 | [<MyContainerProvider object at 0x...>] |
---|
| 603 | |
---|
| 604 | You could look up this specific provider by name: |
---|
| 605 | |
---|
| 606 | >>> from zope.component import getUtility |
---|
[5846] | 607 | >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider') |
---|
[5820] | 608 | >>> p |
---|
| 609 | <MyContainerProvider object at 0x...> |
---|
[6076] | 610 | |
---|
[5820] | 611 | An applicants container would then be created like this: |
---|
| 612 | |
---|
| 613 | >>> provider = all_providers[0] |
---|
| 614 | >>> container = provider.factory() |
---|
| 615 | >>> container |
---|
| 616 | <MyContainer object at 0x...> |
---|
| 617 | |
---|
| 618 | """ |
---|
| 619 | factory = Attribute("A class that can create instances of the " |
---|
| 620 | "requested container type") |
---|