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