[5638] | 1 | ## $Id: interfaces.py 7984 2012-03-26 10:53:00Z 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 | """ |
---|
[5866] | 20 | from grokcore.content.interfaces import IContainer |
---|
[7795] | 21 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
| 22 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[5638] | 23 | from zope import schema |
---|
[7683] | 24 | from zope.component import getUtilitiesFor, queryUtility, getUtility |
---|
[7263] | 25 | from zope.catalog.interfaces import ICatalog |
---|
[7795] | 26 | from zope.interface import Interface, Attribute, implements, directlyProvides |
---|
[7317] | 27 | from zope.schema.interfaces import ( |
---|
| 28 | ValidationError, ISource, IContextSourceBinder) |
---|
[7811] | 29 | from waeup.kofa.schema import TextLineChoice |
---|
| 30 | from waeup.kofa.interfaces import ( |
---|
[7819] | 31 | IKofaObject, year_range, validate_email, academic_sessions_vocab) |
---|
[7811] | 32 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 33 | from waeup.kofa.payments.interfaces import IOnlinePayment |
---|
| 34 | from waeup.kofa.schoolgrades import ResultEntryField |
---|
| 35 | from waeup.kofa.students.vocabularies import ( |
---|
[7915] | 36 | lgas_vocab, GenderSource) |
---|
[7811] | 37 | from waeup.kofa.university.vocabularies import ( |
---|
[7915] | 38 | course_levels, AppCatSource, CertificateSource) |
---|
[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 | |
---|
[7795] | 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( |
---|
[7844] | 107 | IApplicantsUtils).APP_TYPES_DICT |
---|
[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( |
---|
[7844] | 115 | IApplicantsUtils).APP_TYPES_DICT |
---|
[7688] | 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( |
---|
[7844] | 125 | # IApplicantsUtils).APP_TYPES_DICT |
---|
[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( |
---|
[7844] | 133 | # IApplicantsUtils).APP_TYPES_DICT |
---|
[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 | """ |
---|
| 178 | |
---|
[7844] | 179 | APP_TYPES_DICT = Attribute(' dict of application types') |
---|
| 180 | |
---|
[7819] | 181 | class IApplicantsRoot(IKofaObject, IContainer): |
---|
[5676] | 182 | """A container for university applicants containers. |
---|
[5645] | 183 | """ |
---|
[5866] | 184 | pass |
---|
[5638] | 185 | |
---|
[7819] | 186 | class IApplicantsContainer(IKofaObject): |
---|
[5676] | 187 | """An applicants container contains university applicants. |
---|
[5645] | 188 | |
---|
[5638] | 189 | """ |
---|
[6069] | 190 | |
---|
[6075] | 191 | container_title = Attribute( |
---|
| 192 | u'classattribute: title for type of container') |
---|
| 193 | container_description = Attribute( |
---|
| 194 | u'classattribute: description for type of container') |
---|
| 195 | |
---|
[6076] | 196 | |
---|
[6069] | 197 | code = schema.TextLine( |
---|
[7708] | 198 | title = _(u'Code'), |
---|
[7984] | 199 | #default = u'-', |
---|
[6069] | 200 | required = True, |
---|
| 201 | readonly = True, |
---|
[6076] | 202 | ) |
---|
[6096] | 203 | |
---|
[6087] | 204 | title = schema.TextLine( |
---|
[7708] | 205 | title = _(u'Title'), |
---|
[6087] | 206 | required = True, |
---|
[7984] | 207 | #default = u'-', |
---|
[6087] | 208 | readonly = True, |
---|
[6096] | 209 | ) |
---|
| 210 | |
---|
[6087] | 211 | prefix = schema.Choice( |
---|
[7708] | 212 | title = _(u'Application Target'), |
---|
[6087] | 213 | required = True, |
---|
[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, |
---|
[7984] | 221 | #default = 100, |
---|
[7436] | 222 | required = True, |
---|
| 223 | ) |
---|
| 224 | |
---|
[6087] | 225 | year = schema.Choice( |
---|
[7708] | 226 | title = _(u'Year of Entrance'), |
---|
[6087] | 227 | required = True, |
---|
[6158] | 228 | values = year_range(), |
---|
[6087] | 229 | readonly = True, |
---|
[6096] | 230 | ) |
---|
[6087] | 231 | |
---|
[6069] | 232 | provider = schema.Choice( |
---|
[7708] | 233 | title = _(u'Applicants Container Type'), |
---|
[6069] | 234 | required = True, |
---|
| 235 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 236 | readonly = True, |
---|
[6076] | 237 | ) |
---|
[6158] | 238 | |
---|
[7683] | 239 | # Maybe Uniben still needs this ... |
---|
[7376] | 240 | #ac_prefix = schema.Choice( |
---|
| 241 | # title = u'Activation code prefix', |
---|
| 242 | # required = True, |
---|
| 243 | # default = None, |
---|
[7683] | 244 | # source = ApplicationPinSource(), |
---|
[7376] | 245 | # ) |
---|
[6076] | 246 | |
---|
[6189] | 247 | application_category = schema.Choice( |
---|
[7708] | 248 | title = _(u'Category for the grouping of certificates'), |
---|
[6189] | 249 | required = True, |
---|
[7681] | 250 | source = AppCatSource(), |
---|
[6189] | 251 | ) |
---|
| 252 | |
---|
[5645] | 253 | description = schema.Text( |
---|
[7708] | 254 | title = _(u'Human readable description in reST format'), |
---|
[5638] | 255 | required = False, |
---|
[6518] | 256 | default = u'''This text can been seen by anonymous users. |
---|
[7708] | 257 | Here we put mult-lingual information about the study courses provided, the application procedure and deadlines. |
---|
| 258 | >>de<< |
---|
| 259 | Dieser Text kann von anonymen Benutzern gelesen werden. |
---|
| 260 | Hier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.''' |
---|
[5638] | 261 | ) |
---|
| 262 | |
---|
[7903] | 263 | description_dict = Attribute( |
---|
| 264 | """Content as language dictionary with values in HTML format.""") |
---|
[7708] | 265 | |
---|
[5638] | 266 | startdate = schema.Date( |
---|
[7708] | 267 | title = _(u'Application Start Date'), |
---|
[5638] | 268 | required = False, |
---|
| 269 | ) |
---|
| 270 | |
---|
| 271 | enddate = schema.Date( |
---|
[7708] | 272 | title = _(u'Application Closing Date'), |
---|
[5638] | 273 | required = False, |
---|
| 274 | ) |
---|
| 275 | |
---|
[5645] | 276 | strict_deadline = schema.Bool( |
---|
[7708] | 277 | title = _(u'Forbid additions after deadline (enddate)'), |
---|
[7984] | 278 | required = False, |
---|
[5645] | 279 | default = True, |
---|
| 280 | ) |
---|
[5638] | 281 | |
---|
| 282 | def archive(id=None): |
---|
[5676] | 283 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 284 | |
---|
[5676] | 285 | If id is `None`, all applicants are archived. |
---|
[5638] | 286 | |
---|
| 287 | If id contains a single id string, only the respective |
---|
[5676] | 288 | applicants are archived. |
---|
[5638] | 289 | |
---|
| 290 | If id contains a list of id strings all of the respective |
---|
[5676] | 291 | applicants types are saved to disk. |
---|
[5638] | 292 | """ |
---|
| 293 | |
---|
| 294 | def clear(id=None, archive=True): |
---|
[5676] | 295 | """Remove applicants of type given by 'id'. |
---|
[5638] | 296 | |
---|
[5676] | 297 | Optionally archive the applicants. |
---|
[6076] | 298 | |
---|
[5676] | 299 | If id is `None`, all applicants are archived. |
---|
[5638] | 300 | |
---|
| 301 | If id contains a single id string, only the respective |
---|
[5676] | 302 | applicants are archived. |
---|
[5638] | 303 | |
---|
| 304 | If id contains a list of id strings all of the respective |
---|
[5676] | 305 | applicant types are saved to disk. |
---|
[5638] | 306 | |
---|
| 307 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 308 | and respective applicants are simply removed from the |
---|
[5638] | 309 | database. |
---|
| 310 | """ |
---|
[6073] | 311 | |
---|
[6069] | 312 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 313 | """An applicants container contains university applicants. |
---|
| 314 | """ |
---|
[6087] | 315 | prefix = schema.Choice( |
---|
[7708] | 316 | title = _(u'Application Target'), |
---|
[6069] | 317 | required = True, |
---|
[7683] | 318 | source = ApplicationTypeSource(), |
---|
[6069] | 319 | readonly = False, |
---|
[6076] | 320 | ) |
---|
[6073] | 321 | |
---|
[6087] | 322 | year = schema.Choice( |
---|
[7708] | 323 | title = _(u'Year of Entrance'), |
---|
[6087] | 324 | required = True, |
---|
[6158] | 325 | values = year_range(), |
---|
[6087] | 326 | readonly = False, |
---|
[6096] | 327 | ) |
---|
[6073] | 328 | |
---|
[6087] | 329 | provider = schema.Choice( |
---|
[7708] | 330 | title = _(u'Applicants Container Type'), |
---|
[6087] | 331 | required = True, |
---|
| 332 | source = ApplicantContainerProviderSource(), |
---|
| 333 | readonly = False, |
---|
| 334 | ) |
---|
| 335 | |
---|
[6096] | 336 | IApplicantsContainerAdd[ |
---|
| 337 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 338 | IApplicantsContainerAdd[ |
---|
| 339 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 340 | IApplicantsContainerAdd[ |
---|
| 341 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 342 | |
---|
[7819] | 343 | class IApplicantBaseData(IKofaObject): |
---|
[5753] | 344 | """The data for an applicant. |
---|
| 345 | |
---|
[7240] | 346 | This is a base interface with no field |
---|
[7933] | 347 | required. For use with processors, forms, etc., please use one of |
---|
[5753] | 348 | the derived interfaces below, which set more fields to required |
---|
| 349 | state, depending on use-case. |
---|
[7338] | 350 | |
---|
[7795] | 351 | This base interface is also implemented by the |
---|
[7811] | 352 | :class:`waeup.kofa.students.StudentApplication` class in the |
---|
[7795] | 353 | students package. Thus, these are the data which are saved after |
---|
| 354 | admission. |
---|
[5753] | 355 | """ |
---|
[7240] | 356 | applicant_id = schema.TextLine( |
---|
[7708] | 357 | title = _(u'Applicant Id'), |
---|
[7240] | 358 | required = False, |
---|
[7260] | 359 | readonly = False, |
---|
[7240] | 360 | ) |
---|
[7270] | 361 | reg_number = TextLineChoice( |
---|
[7708] | 362 | title = _(u'JAMB Registration Number'), |
---|
[7263] | 363 | readonly = False, |
---|
| 364 | required = True, |
---|
| 365 | source = contextual_reg_num_source, |
---|
[5753] | 366 | ) |
---|
[7376] | 367 | #access_code = schema.TextLine( |
---|
| 368 | # title = u'Activation Code', |
---|
| 369 | # required = False, |
---|
| 370 | # readonly = True, |
---|
| 371 | # ) |
---|
[5753] | 372 | firstname = schema.TextLine( |
---|
[7708] | 373 | title = _(u'First Name'), |
---|
[6352] | 374 | required = True, |
---|
[5753] | 375 | ) |
---|
[7356] | 376 | middlename = schema.TextLine( |
---|
[7708] | 377 | title = _(u'Middle Name'), |
---|
[5753] | 378 | required = False, |
---|
| 379 | ) |
---|
| 380 | lastname = schema.TextLine( |
---|
[7708] | 381 | title = _(u'Last Name (Surname)'), |
---|
[6352] | 382 | required = True, |
---|
[5753] | 383 | ) |
---|
| 384 | date_of_birth = schema.Date( |
---|
[7708] | 385 | title = _(u'Date of Birth'), |
---|
[6352] | 386 | required = True, |
---|
[5753] | 387 | ) |
---|
[6249] | 388 | lga = schema.Choice( |
---|
| 389 | source = lgas_vocab, |
---|
[7708] | 390 | title = _(u'State/LGA'), |
---|
[6254] | 391 | default = 'foreigner', |
---|
[7984] | 392 | required = False, |
---|
[5753] | 393 | ) |
---|
| 394 | sex = schema.Choice( |
---|
[7708] | 395 | title = _(u'Sex'), |
---|
[5753] | 396 | source = GenderSource(), |
---|
[6352] | 397 | required = True, |
---|
[5753] | 398 | ) |
---|
[6341] | 399 | email = schema.ASCIILine( |
---|
[7708] | 400 | title = _(u'Email Address'), |
---|
[7240] | 401 | required = True, |
---|
[6343] | 402 | constraint=validate_email, |
---|
[5753] | 403 | ) |
---|
[7324] | 404 | phone = schema.TextLine( |
---|
[7708] | 405 | title = _(u'Phone'), |
---|
[7331] | 406 | description = u'', |
---|
[5753] | 407 | required = False, |
---|
| 408 | ) |
---|
[7262] | 409 | course1 = schema.Choice( |
---|
[7708] | 410 | title = _(u'1st Choice Course of Study'), |
---|
[7347] | 411 | source = CertificateSource(), |
---|
[7262] | 412 | required = True, |
---|
| 413 | ) |
---|
| 414 | course2 = schema.Choice( |
---|
[7708] | 415 | title = _(u'2nd Choice Course of Study'), |
---|
[7347] | 416 | source = CertificateSource(), |
---|
[7262] | 417 | required = False, |
---|
| 418 | ) |
---|
[7795] | 419 | school_grades = schema.List( |
---|
| 420 | title = _(u'School Grades'), |
---|
| 421 | value_type = ResultEntryField(), |
---|
[7984] | 422 | required = False, |
---|
[7795] | 423 | default = [], |
---|
| 424 | ) |
---|
[6322] | 425 | |
---|
[5753] | 426 | # |
---|
[7338] | 427 | # Data to be imported after screening |
---|
[5753] | 428 | # |
---|
[6255] | 429 | screening_score = schema.Int( |
---|
[7708] | 430 | title = _(u'Screening Score'), |
---|
[5753] | 431 | required = False, |
---|
| 432 | ) |
---|
| 433 | screening_venue = schema.TextLine( |
---|
[7708] | 434 | title = _(u'Screening Venue'), |
---|
[5753] | 435 | required = False, |
---|
| 436 | ) |
---|
[6248] | 437 | course_admitted = schema.Choice( |
---|
[7708] | 438 | title = _(u'Admitted Course of Study'), |
---|
[7347] | 439 | source = CertificateSource(), |
---|
[5753] | 440 | required = False, |
---|
| 441 | ) |
---|
[7347] | 442 | notice = schema.Text( |
---|
[7708] | 443 | title = _(u'Notice'), |
---|
[7347] | 444 | required = False, |
---|
| 445 | ) |
---|
[7338] | 446 | |
---|
| 447 | class IApplicantProcessData(IApplicantBaseData): |
---|
| 448 | """An applicant. |
---|
| 449 | |
---|
| 450 | Here we add process attributes and methods to the base data. |
---|
| 451 | """ |
---|
| 452 | |
---|
[7844] | 453 | history = Attribute('Object history, a list of messages') |
---|
[7338] | 454 | state = Attribute('The application state of an applicant') |
---|
[7364] | 455 | display_fullname = Attribute('The fullname of an applicant') |
---|
[7338] | 456 | application_date = Attribute('Date of submission, used for export only') |
---|
| 457 | password = Attribute('Encrypted password of a applicant') |
---|
| 458 | application_number = Attribute('The key under which the record is stored') |
---|
| 459 | |
---|
| 460 | def loggerInfo(ob_class, comment): |
---|
| 461 | """Adds an INFO message to the log file |
---|
| 462 | """ |
---|
| 463 | |
---|
[5753] | 464 | student_id = schema.TextLine( |
---|
[7708] | 465 | title = _(u'Student Id'), |
---|
[5753] | 466 | required = False, |
---|
[7351] | 467 | readonly = False, |
---|
[5753] | 468 | ) |
---|
[6302] | 469 | locked = schema.Bool( |
---|
[7708] | 470 | title = _(u'Form locked'), |
---|
[6302] | 471 | default = False, |
---|
| 472 | ) |
---|
[5753] | 473 | |
---|
[7338] | 474 | class IApplicant(IApplicantProcessData): |
---|
[5753] | 475 | """An applicant. |
---|
| 476 | |
---|
| 477 | This is basically the applicant base data. Here we repeat the |
---|
[6195] | 478 | fields from base data if we have to set the `required` attribute |
---|
| 479 | to True (which is the default). |
---|
[5753] | 480 | """ |
---|
| 481 | |
---|
[7338] | 482 | class IApplicantEdit(IApplicantProcessData): |
---|
[7867] | 483 | """An applicant interface for editing. |
---|
[5753] | 484 | |
---|
[6339] | 485 | Here we can repeat the fields from base data and set the |
---|
| 486 | `required` and `readonly` attributes to True to further restrict |
---|
[7262] | 487 | the data access. Or we can allow only certain certificates to be |
---|
| 488 | selected by choosing the appropriate source. |
---|
| 489 | |
---|
| 490 | We cannot omit fields here. This has to be done in the |
---|
[6339] | 491 | respective form page. |
---|
[6195] | 492 | """ |
---|
[7262] | 493 | |
---|
| 494 | course1 = schema.Choice( |
---|
[7708] | 495 | title = _(u'1st Choice Course of Study'), |
---|
[7347] | 496 | source = AppCatCertificateSource(), |
---|
[7262] | 497 | required = True, |
---|
| 498 | ) |
---|
| 499 | course2 = schema.Choice( |
---|
[7708] | 500 | title = _(u'2nd Choice Course of Study'), |
---|
[7347] | 501 | source = AppCatCertificateSource(), |
---|
[7262] | 502 | required = False, |
---|
| 503 | ) |
---|
[6255] | 504 | screening_score = schema.Int( |
---|
[7708] | 505 | title = _(u'Screening Score'), |
---|
[6195] | 506 | required = False, |
---|
[5941] | 507 | readonly = True, |
---|
| 508 | ) |
---|
[6195] | 509 | screening_venue = schema.TextLine( |
---|
[7708] | 510 | title = _(u'Screening Venue'), |
---|
[5753] | 511 | required = False, |
---|
| 512 | readonly = True, |
---|
| 513 | ) |
---|
[6301] | 514 | course_admitted = schema.Choice( |
---|
[7708] | 515 | title = _(u'Admitted Course of Study'), |
---|
[7347] | 516 | source = CertificateSource(), |
---|
[5753] | 517 | required = False, |
---|
[6195] | 518 | readonly = True, |
---|
[5753] | 519 | ) |
---|
[6195] | 520 | notice = schema.Text( |
---|
[7708] | 521 | title = _(u'Notice'), |
---|
[5753] | 522 | required = False, |
---|
| 523 | readonly = True, |
---|
| 524 | ) |
---|
[5758] | 525 | |
---|
[7338] | 526 | def createStudent(): |
---|
| 527 | """Create a student object from applicatnt data |
---|
| 528 | and copy applicant object. |
---|
| 529 | """ |
---|
| 530 | |
---|
[7268] | 531 | class IApplicantUpdateByRegNo(IApplicant): |
---|
| 532 | """Representation of an applicant. |
---|
| 533 | |
---|
[7270] | 534 | Skip regular reg_number validation if reg_number is used for finding |
---|
[7268] | 535 | the applicant object. |
---|
| 536 | """ |
---|
[7270] | 537 | reg_number = schema.TextLine( |
---|
[7268] | 538 | title = u'Registration Number', |
---|
| 539 | required = False, |
---|
| 540 | ) |
---|
| 541 | |
---|
[7250] | 542 | class IApplicantOnlinePayment(IOnlinePayment): |
---|
| 543 | """An applicant payment via payment gateways. |
---|
| 544 | |
---|
| 545 | """ |
---|
| 546 | p_year = schema.Choice( |
---|
[7708] | 547 | title = _(u'Payment Session'), |
---|
[7250] | 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 |
---|
[7811] | 575 | from waeup.kofa.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 |
---|
[7811] | 587 | >>> from waeup.kofa.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") |
---|