[5638] | 1 | ## |
---|
| 2 | ## interfaces.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
| 4 | ## Started on Sun Jan 16 15:30:01 2011 Uli Fouquet |
---|
| 5 | ## $Id$ |
---|
[6076] | 6 | ## |
---|
[6087] | 7 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
[5638] | 8 | ## This program is free software; you can redistribute it and/or modify |
---|
| 9 | ## it under the terms of the GNU General Public License as published by |
---|
| 10 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ## (at your option) any later version. |
---|
[6076] | 12 | ## |
---|
[5638] | 13 | ## This program is distributed in the hope that it will be useful, |
---|
| 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | ## GNU General Public License for more details. |
---|
[6076] | 17 | ## |
---|
[5638] | 18 | ## You should have received a copy of the GNU General Public License |
---|
| 19 | ## along with this program; if not, write to the Free Software |
---|
| 20 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 21 | ## |
---|
[5676] | 22 | """Interfaces regarding student applicants and related components. |
---|
[5638] | 23 | """ |
---|
[5753] | 24 | import os |
---|
| 25 | import waeup.sirp.browser |
---|
[6098] | 26 | from datetime import datetime |
---|
[5866] | 27 | from grokcore.content.interfaces import IContainer |
---|
[5758] | 28 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[6248] | 29 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[5638] | 30 | from zope import schema |
---|
[6075] | 31 | from zope.component import getUtility, getUtilitiesFor |
---|
[5758] | 32 | from zope.interface import Interface, Attribute |
---|
[6248] | 33 | from zope.catalog.interfaces import ICatalog |
---|
[5758] | 34 | from zope.pluggableauth.interfaces import IPrincipalInfo |
---|
| 35 | from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal |
---|
[5753] | 36 | from waeup.sirp.image.schema import ImageFile |
---|
[5980] | 37 | from waeup.sirp.image.image import WAeUPImageFile |
---|
[5681] | 38 | from waeup.sirp.interfaces import IWAeUPObject, SimpleWAeUPVocabulary |
---|
[6189] | 39 | from waeup.sirp.university.vocabularies import application_categories |
---|
[6249] | 40 | from waeup.sirp.applicants.lgas import LGAS |
---|
[5638] | 41 | |
---|
[6075] | 42 | |
---|
[5753] | 43 | IMAGE_PATH = os.path.join( |
---|
| 44 | os.path.dirname(waeup.sirp.browser.__file__), |
---|
| 45 | 'static' |
---|
| 46 | ) |
---|
[5980] | 47 | DEFAULT_PASSPORT_IMAGE_MALE = WAeUPImageFile( |
---|
[5753] | 48 | 'passport.jpg', |
---|
| 49 | open(os.path.join(IMAGE_PATH, 'placeholder_m.jpg')).read(), |
---|
| 50 | ) |
---|
[5980] | 51 | DEFAULT_PASSPORT_IMAGE_FEMALE = WAeUPImageFile( |
---|
[5753] | 52 | 'passport.jpg', |
---|
| 53 | open(os.path.join(IMAGE_PATH, 'placeholder_f.jpg')).read(), |
---|
| 54 | ) |
---|
| 55 | |
---|
[6087] | 56 | #: Types of applications we support. |
---|
| 57 | APPLICATION_TYPES = ( |
---|
[6111] | 58 | ('General Studies', 'app','APP'), |
---|
| 59 | ('Pre-NCE Programme', 'prence','PRE'), |
---|
| 60 | ('Post UME Screening Test', 'pume','PUME'), |
---|
| 61 | ('Post UDE Screening', 'pude','PUDE'), |
---|
| 62 | ('Part Time Degree in Education', 'sandwich','SAND'), |
---|
| 63 | ('Part-Time Degree Programmes', 'pt','PTP'), |
---|
| 64 | ('Diploma Programmes', 'dp','DPP'), |
---|
| 65 | ('PCE Screening', 'pce','PCE'), |
---|
| 66 | ('Certificate Programmes', 'ct','CTP'), |
---|
| 67 | ('Common Entry Screening Test', 'cest','CEST'), |
---|
[5681] | 68 | ) |
---|
| 69 | |
---|
| 70 | #: A :class:`waeup.sirp.interfaces.SimpleWAeUPVocabulary` of supported |
---|
[6087] | 71 | #: application or screening types. |
---|
[6158] | 72 | application_types_vocab = SimpleWAeUPVocabulary( |
---|
| 73 | *[(x[0],x[1]) for x in APPLICATION_TYPES]) |
---|
| 74 | application_pins_vocab = SimpleWAeUPVocabulary( |
---|
| 75 | *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES]) |
---|
[6249] | 76 | lgas_vocab = SimpleWAeUPVocabulary( |
---|
| 77 | *sorted([(x[1],x[0]) for x in LGAS])) |
---|
[5681] | 78 | |
---|
[6248] | 79 | class CertificateSource(BasicContextualSourceFactory): |
---|
| 80 | """A certificate source delivers all certificates provided |
---|
| 81 | in the portal. |
---|
| 82 | """ |
---|
| 83 | def getValues(self, context): |
---|
| 84 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 85 | return sorted(list( |
---|
| 86 | catalog.searchResults( |
---|
| 87 | code=('', 'z*'))), |
---|
| 88 | key=lambda value: value.code) |
---|
| 89 | |
---|
| 90 | def getToken(self, context, value): |
---|
| 91 | return value.code |
---|
| 92 | |
---|
| 93 | def getTitle(self, context, value): |
---|
| 94 | return "%s - %s" % (value.code, value.title[:64]) |
---|
| 95 | |
---|
| 96 | class AppCatCertificateSource(CertificateSource): |
---|
| 97 | """An application certificate source delivers all courses which belong to |
---|
| 98 | a certain application_category. |
---|
| 99 | """ |
---|
| 100 | def getValues(self, context): |
---|
| 101 | appcat = context.__parent__.application_category |
---|
| 102 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 103 | return sorted(list( |
---|
| 104 | catalog.searchResults( |
---|
| 105 | code=('', 'z*'), |
---|
| 106 | application_category=(appcat,appcat))), |
---|
| 107 | key=lambda value: value.code) |
---|
| 108 | |
---|
[6158] | 109 | def year_range(): |
---|
[6109] | 110 | curr_year = datetime.now().year |
---|
| 111 | return range(curr_year - 2, curr_year + 5) |
---|
[6097] | 112 | |
---|
[5753] | 113 | class GenderSource(BasicSourceFactory): |
---|
| 114 | """A gender source delivers basically a mapping |
---|
| 115 | ``{'m': 'male', 'f': 'female'}`` |
---|
| 116 | |
---|
| 117 | Using a source, we make sure that the tokens (which are |
---|
| 118 | stored/expected for instance from CSV files) are something one |
---|
| 119 | can expect and not cryptic IntIDs. |
---|
| 120 | """ |
---|
| 121 | def getValues(self): |
---|
| 122 | return ['m', 'f'] |
---|
| 123 | |
---|
| 124 | def getToken(self, value): |
---|
| 125 | return value[0].lower() |
---|
[6076] | 126 | |
---|
[5753] | 127 | def getTitle(self, value): |
---|
| 128 | if value == 'm': |
---|
| 129 | return 'male' |
---|
| 130 | if value == 'f': |
---|
| 131 | return 'female' |
---|
[6076] | 132 | |
---|
[6069] | 133 | class ApplicantContainerProviderSource(BasicSourceFactory): |
---|
[6075] | 134 | """A source offering all available applicants container types. |
---|
| 135 | |
---|
| 136 | The values returned by this source are names of utilities that can |
---|
| 137 | create :class:`ApplicantContainer` instances. So, if you get a |
---|
| 138 | name like ``'myactype'`` from this source, then you can do: |
---|
| 139 | |
---|
| 140 | >>> from zope.component import getUtility |
---|
| 141 | >>> p = getUtility(IApplicantsContainerProvider, name=myactype) |
---|
| 142 | >>> my_applicants_container = p.factory() |
---|
| 143 | |
---|
| 144 | Or you can access class-attributes like |
---|
| 145 | |
---|
| 146 | >>> my_applicants_container.container_title |
---|
| 147 | 'Pretty' |
---|
[6076] | 148 | |
---|
[6069] | 149 | """ |
---|
| 150 | def getValues(self): |
---|
[6075] | 151 | """Returns a list of ``(<name>, <provider>)`` tuples. |
---|
[5753] | 152 | |
---|
[6075] | 153 | Here ``<name>`` is the name under which an |
---|
| 154 | :class:``ApplicantContainerProvider`` was registered as a |
---|
| 155 | utility and ``<provider>`` is the utility itself. |
---|
| 156 | """ |
---|
| 157 | return getUtilitiesFor(IApplicantsContainerProvider) |
---|
| 158 | |
---|
[6069] | 159 | def getToken(self, value): |
---|
[6075] | 160 | """Return the name of the ``(<name>, <provider>)`` tuple. |
---|
| 161 | """ |
---|
| 162 | return value[0] |
---|
| 163 | |
---|
[6069] | 164 | def getTitle(self, value): |
---|
[6075] | 165 | """Get a 'title - description' string for a container type. |
---|
| 166 | """ |
---|
| 167 | factory = value[1].factory |
---|
| 168 | return "%s - %s" % ( |
---|
| 169 | factory.container_title, factory.container_description) |
---|
[6069] | 170 | |
---|
[5753] | 171 | class IResultEntry(IWAeUPObject): |
---|
| 172 | subject = schema.TextLine( |
---|
| 173 | title = u'Subject', |
---|
| 174 | description = u'The subject', |
---|
| 175 | required=False, |
---|
| 176 | ) |
---|
| 177 | score = schema.TextLine( |
---|
| 178 | title = u'Score', |
---|
| 179 | description = u'The score', |
---|
| 180 | required=False, |
---|
| 181 | ) |
---|
| 182 | |
---|
[5866] | 183 | class IApplicantsRoot(IWAeUPObject, IContainer): |
---|
[5676] | 184 | """A container for university applicants containers. |
---|
[5645] | 185 | """ |
---|
[5866] | 186 | pass |
---|
[5638] | 187 | |
---|
[6076] | 188 | |
---|
[5676] | 189 | class IApplicantsContainer(IWAeUPObject): |
---|
| 190 | """An applicants container contains university applicants. |
---|
[5645] | 191 | |
---|
[5638] | 192 | """ |
---|
[6069] | 193 | |
---|
[6075] | 194 | container_title = Attribute( |
---|
| 195 | u'classattribute: title for type of container') |
---|
| 196 | container_description = Attribute( |
---|
| 197 | u'classattribute: description for type of container') |
---|
| 198 | |
---|
[6076] | 199 | |
---|
[6069] | 200 | code = schema.TextLine( |
---|
| 201 | title = u'Code', |
---|
[6087] | 202 | default = u'-', |
---|
[6069] | 203 | required = True, |
---|
| 204 | readonly = True, |
---|
[6076] | 205 | ) |
---|
[6096] | 206 | |
---|
[6087] | 207 | title = schema.TextLine( |
---|
| 208 | title = u'Title', |
---|
| 209 | required = True, |
---|
| 210 | default = u'-', |
---|
| 211 | readonly = True, |
---|
[6096] | 212 | ) |
---|
| 213 | |
---|
[6087] | 214 | prefix = schema.Choice( |
---|
| 215 | title = u'Application target', |
---|
| 216 | required = True, |
---|
| 217 | default = None, |
---|
| 218 | source = application_types_vocab, |
---|
| 219 | readonly = True, |
---|
| 220 | ) |
---|
[6076] | 221 | |
---|
[6087] | 222 | year = schema.Choice( |
---|
| 223 | title = u'Year of entrance', |
---|
| 224 | required = True, |
---|
| 225 | default = None, |
---|
[6158] | 226 | values = year_range(), |
---|
[6087] | 227 | readonly = True, |
---|
[6096] | 228 | ) |
---|
[6087] | 229 | |
---|
[6069] | 230 | provider = schema.Choice( |
---|
[6070] | 231 | title = u'Applicants container type', |
---|
[6069] | 232 | required = True, |
---|
| 233 | default = None, |
---|
| 234 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 235 | readonly = True, |
---|
[6076] | 236 | ) |
---|
[6158] | 237 | |
---|
[6110] | 238 | ac_prefix = schema.Choice( |
---|
| 239 | title = u'Access code prefix', |
---|
| 240 | required = True, |
---|
| 241 | default = None, |
---|
[6111] | 242 | source = application_pins_vocab, |
---|
[6110] | 243 | ) |
---|
[6076] | 244 | |
---|
[6189] | 245 | application_category = schema.Choice( |
---|
| 246 | title = u'Category for the grouping of study courses', |
---|
| 247 | required = True, |
---|
| 248 | default = None, |
---|
| 249 | source = application_categories, |
---|
| 250 | ) |
---|
| 251 | |
---|
[5645] | 252 | description = schema.Text( |
---|
| 253 | title = u'Human readable description in reST format', |
---|
[5638] | 254 | required = False, |
---|
[6070] | 255 | default = u'No description yet.' |
---|
[5638] | 256 | ) |
---|
| 257 | |
---|
| 258 | startdate = schema.Date( |
---|
[5645] | 259 | title = u'Date when the application period starts', |
---|
[5638] | 260 | required = False, |
---|
| 261 | default = None, |
---|
| 262 | ) |
---|
| 263 | |
---|
| 264 | enddate = schema.Date( |
---|
[5645] | 265 | title = u'Date when the application period ends', |
---|
[5638] | 266 | required = False, |
---|
| 267 | default = None, |
---|
| 268 | ) |
---|
| 269 | |
---|
[5645] | 270 | strict_deadline = schema.Bool( |
---|
| 271 | title = u'Forbid additions after deadline (enddate)', |
---|
| 272 | required = True, |
---|
| 273 | default = True, |
---|
| 274 | ) |
---|
[5638] | 275 | |
---|
| 276 | def archive(id=None): |
---|
[5676] | 277 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 278 | |
---|
[5676] | 279 | If id is `None`, all applicants are archived. |
---|
[5638] | 280 | |
---|
| 281 | If id contains a single id string, only the respective |
---|
[5676] | 282 | applicants are archived. |
---|
[5638] | 283 | |
---|
| 284 | If id contains a list of id strings all of the respective |
---|
[5676] | 285 | applicants types are saved to disk. |
---|
[5638] | 286 | """ |
---|
| 287 | |
---|
| 288 | def clear(id=None, archive=True): |
---|
[5676] | 289 | """Remove applicants of type given by 'id'. |
---|
[5638] | 290 | |
---|
[5676] | 291 | Optionally archive the applicants. |
---|
[6076] | 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 | applicant types are saved to disk. |
---|
[5638] | 300 | |
---|
| 301 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 302 | and respective applicants are simply removed from the |
---|
[5638] | 303 | database. |
---|
| 304 | """ |
---|
[6073] | 305 | |
---|
[6069] | 306 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 307 | """An applicants container contains university applicants. |
---|
| 308 | """ |
---|
[6087] | 309 | prefix = schema.Choice( |
---|
| 310 | title = u'Application target', |
---|
[6069] | 311 | required = True, |
---|
[6087] | 312 | default = None, |
---|
| 313 | source = application_types_vocab, |
---|
[6069] | 314 | readonly = False, |
---|
[6076] | 315 | ) |
---|
[6073] | 316 | |
---|
[6087] | 317 | year = schema.Choice( |
---|
| 318 | title = u'Year of entrance', |
---|
| 319 | required = True, |
---|
| 320 | default = None, |
---|
[6158] | 321 | values = year_range(), |
---|
[6087] | 322 | readonly = False, |
---|
[6096] | 323 | ) |
---|
[6073] | 324 | |
---|
[6087] | 325 | provider = schema.Choice( |
---|
| 326 | title = u'Applicants container type', |
---|
| 327 | required = True, |
---|
| 328 | default = None, |
---|
| 329 | source = ApplicantContainerProviderSource(), |
---|
| 330 | readonly = False, |
---|
| 331 | ) |
---|
| 332 | |
---|
[6096] | 333 | IApplicantsContainerAdd[ |
---|
| 334 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 335 | IApplicantsContainerAdd[ |
---|
| 336 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 337 | IApplicantsContainerAdd[ |
---|
| 338 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 339 | |
---|
[5753] | 340 | class IApplicantBaseData(IWAeUPObject): |
---|
| 341 | """The data for an applicant. |
---|
| 342 | |
---|
| 343 | This is a base interface with no field (except ``reg_no``) |
---|
| 344 | required. For use with importers, forms, etc., please use one of |
---|
| 345 | the derived interfaces below, which set more fields to required |
---|
| 346 | state, depending on use-case. |
---|
| 347 | """ |
---|
[6195] | 348 | locked = schema.Bool( |
---|
| 349 | title = u'Form locked', |
---|
| 350 | default = False, |
---|
| 351 | #readonly = True, |
---|
| 352 | ) |
---|
[5753] | 353 | reg_no = schema.TextLine( |
---|
| 354 | title = u'JAMB Registration Number', |
---|
[6195] | 355 | readonly = True, |
---|
[5753] | 356 | ) |
---|
| 357 | access_code = schema.TextLine( |
---|
| 358 | title = u'Access Code', |
---|
| 359 | required = False, |
---|
[6195] | 360 | readonly = True, |
---|
[5753] | 361 | ) |
---|
[6248] | 362 | course1 = schema.Choice( |
---|
[5753] | 363 | title = u'1st Choice Course of Study', |
---|
[6248] | 364 | source = AppCatCertificateSource(), |
---|
[5753] | 365 | required = False, |
---|
| 366 | ) |
---|
[6248] | 367 | course2 = schema.Choice( |
---|
[5753] | 368 | title = u'2nd Choice Course of Study', |
---|
[6248] | 369 | source = AppCatCertificateSource(), |
---|
[5753] | 370 | required = False, |
---|
| 371 | ) |
---|
| 372 | firstname = schema.TextLine( |
---|
| 373 | title = u'First Name', |
---|
| 374 | required = False, |
---|
| 375 | ) |
---|
| 376 | middlenames = schema.TextLine( |
---|
| 377 | title = u'Middle Names', |
---|
| 378 | required = False, |
---|
| 379 | ) |
---|
| 380 | lastname = schema.TextLine( |
---|
[6205] | 381 | title = u'Last Name (Surname)', |
---|
[5753] | 382 | required = False, |
---|
| 383 | ) |
---|
| 384 | date_of_birth = schema.Date( |
---|
| 385 | title = u'Date of Birth', |
---|
| 386 | required = False, |
---|
| 387 | ) |
---|
[6249] | 388 | lga = schema.Choice( |
---|
| 389 | source = lgas_vocab, |
---|
[6205] | 390 | title = u'State/LGA', |
---|
[5753] | 391 | required = False, |
---|
| 392 | ) |
---|
| 393 | sex = schema.Choice( |
---|
| 394 | title = u'Sex', |
---|
| 395 | source = GenderSource(), |
---|
| 396 | default = u'm', |
---|
| 397 | required = False, |
---|
| 398 | ) |
---|
| 399 | email = schema.TextLine( |
---|
| 400 | title = u'Email', |
---|
| 401 | required = False, |
---|
| 402 | ) |
---|
| 403 | phone = schema.TextLine( |
---|
| 404 | title = u'Phone', |
---|
| 405 | required = False, |
---|
| 406 | ) |
---|
| 407 | passport = ImageFile( |
---|
| 408 | title = u'Passport Photograph', |
---|
| 409 | default = DEFAULT_PASSPORT_IMAGE_MALE, |
---|
| 410 | required = True, |
---|
[6184] | 411 | #max_size = 20480, |
---|
[5753] | 412 | ) |
---|
[6195] | 413 | confirm_passport = schema.Bool( |
---|
[6205] | 414 | title = u"Passport picture confirmed", |
---|
[6195] | 415 | default = False, |
---|
| 416 | required = True, |
---|
[5753] | 417 | ) |
---|
| 418 | # |
---|
[6195] | 419 | # Process Data |
---|
[5753] | 420 | # |
---|
| 421 | application_date = schema.Date( |
---|
| 422 | title = u'Application Date', |
---|
| 423 | required = False, |
---|
[6195] | 424 | readonly = True, |
---|
[5753] | 425 | ) |
---|
| 426 | status = schema.TextLine( |
---|
| 427 | # XXX: should be 'status' type |
---|
| 428 | title = u'Application Status', |
---|
| 429 | required = False, |
---|
[6195] | 430 | readonly = True, |
---|
[5753] | 431 | ) |
---|
| 432 | screening_score = schema.TextLine( |
---|
| 433 | title = u'Screening Score', |
---|
| 434 | required = False, |
---|
| 435 | ) |
---|
| 436 | screening_venue = schema.TextLine( |
---|
| 437 | title = u'Screening Venue', |
---|
| 438 | required = False, |
---|
| 439 | ) |
---|
[6248] | 440 | course_admitted = schema.Choice( |
---|
[5753] | 441 | # XXX: should be choice |
---|
| 442 | title = u'Admitted Course of Study', |
---|
[6248] | 443 | source = CertificateSource(), |
---|
[5753] | 444 | required = False, |
---|
| 445 | ) |
---|
| 446 | entry_session = schema.TextLine( |
---|
[6195] | 447 | # XXX: should be choice |
---|
[5753] | 448 | title = u'Entry Session', |
---|
| 449 | required = False, |
---|
| 450 | ) |
---|
| 451 | notice = schema.Text( |
---|
| 452 | title = u'Notice', |
---|
| 453 | required = False, |
---|
| 454 | ) |
---|
| 455 | student_id = schema.TextLine( |
---|
| 456 | title = u'Student ID', |
---|
| 457 | required = False, |
---|
[6195] | 458 | readonly = True, |
---|
[5753] | 459 | ) |
---|
| 460 | |
---|
| 461 | class IApplicant(IApplicantBaseData): |
---|
| 462 | """An applicant. |
---|
| 463 | |
---|
| 464 | This is basically the applicant base data. Here we repeat the |
---|
[6195] | 465 | fields from base data if we have to set the `required` attribute |
---|
| 466 | to True (which is the default). |
---|
[5753] | 467 | """ |
---|
| 468 | |
---|
[6195] | 469 | class IApplicantEdit(IApplicantBaseData): |
---|
| 470 | """An applicant. |
---|
[5753] | 471 | |
---|
[6195] | 472 | Here we can repeat the fields from base data and set the `required` and |
---|
| 473 | `readonly` attributes to True to further restrict the data access. We cannot |
---|
| 474 | omit fields. This has to be done in the respective form page. |
---|
| 475 | """ |
---|
[5753] | 476 | screening_score = schema.TextLine( |
---|
| 477 | title = u'Screening Score', |
---|
[6195] | 478 | required = False, |
---|
[5941] | 479 | readonly = True, |
---|
| 480 | ) |
---|
[6195] | 481 | screening_venue = schema.TextLine( |
---|
| 482 | title = u'Screening Venue', |
---|
[5753] | 483 | required = False, |
---|
| 484 | readonly = True, |
---|
| 485 | ) |
---|
[6195] | 486 | course_admitted = schema.TextLine( |
---|
[5753] | 487 | # XXX: should be choice |
---|
[6195] | 488 | title = u'Admitted Course of Study', |
---|
[5753] | 489 | required = False, |
---|
[6195] | 490 | readonly = True, |
---|
[5753] | 491 | ) |
---|
[6195] | 492 | entry_session = schema.TextLine( |
---|
[5753] | 493 | # XXX: should be choice |
---|
[6195] | 494 | title = u'Entry Session', |
---|
[5753] | 495 | required = False, |
---|
| 496 | readonly = True, |
---|
| 497 | ) |
---|
[6195] | 498 | notice = schema.Text( |
---|
| 499 | title = u'Notice', |
---|
[5753] | 500 | required = False, |
---|
| 501 | readonly = True, |
---|
| 502 | ) |
---|
[5952] | 503 | confirm_passport = schema.Bool( |
---|
[6195] | 504 | title = u"I confirm that the Passport Photograph uploaded on this form is a true picture of me.", |
---|
[5952] | 505 | default = False, |
---|
| 506 | required = True, |
---|
| 507 | ) |
---|
[5758] | 508 | |
---|
| 509 | class IApplicantPrincipalInfo(IPrincipalInfo): |
---|
| 510 | """Infos about principals that are applicants. |
---|
| 511 | """ |
---|
| 512 | access_code = Attribute("The Access Code the user purchased") |
---|
| 513 | |
---|
| 514 | class IApplicantPrincipal(IPrincipal): |
---|
| 515 | """A principal that is an applicant. |
---|
| 516 | |
---|
| 517 | This interface extends zope.security.interfaces.IPrincipal and |
---|
| 518 | requires also an `id` and other attributes defined there. |
---|
| 519 | """ |
---|
| 520 | access_code = schema.TextLine( |
---|
| 521 | title = u'Access Code', |
---|
| 522 | description = u'The access code purchased by the user.', |
---|
| 523 | required = True, |
---|
| 524 | readonly = True) |
---|
| 525 | |
---|
| 526 | class IApplicantsFormChallenger(Interface): |
---|
| 527 | """A challenger that uses a browser form to collect applicant |
---|
| 528 | credentials. |
---|
| 529 | """ |
---|
| 530 | loginpagename = schema.TextLine( |
---|
| 531 | title = u'Loginpagename', |
---|
| 532 | description = u"""Name of the login form used by challenger. |
---|
| 533 | |
---|
| 534 | The form must provide an ``access_code`` input field. |
---|
| 535 | """) |
---|
| 536 | |
---|
| 537 | accesscode_field = schema.TextLine( |
---|
| 538 | title = u'Access code field', |
---|
| 539 | description = u'''Field of the login page which is looked up for |
---|
| 540 | access_code''', |
---|
| 541 | default = u'access_code', |
---|
| 542 | ) |
---|
| 543 | |
---|
| 544 | |
---|
| 545 | class IApplicantSessionCredentials(Interface): |
---|
| 546 | """Interface for storing and accessing applicant credentials in a |
---|
| 547 | session. |
---|
| 548 | """ |
---|
| 549 | |
---|
| 550 | def __init__(access_code): |
---|
| 551 | """Create applicant session credentials.""" |
---|
| 552 | |
---|
| 553 | def getAccessCode(): |
---|
| 554 | """Return the access code.""" |
---|
| 555 | |
---|
| 556 | |
---|
[5846] | 557 | class IApplicantsContainerProvider(Interface): |
---|
[5820] | 558 | """A provider for applicants containers. |
---|
| 559 | |
---|
| 560 | Applicants container providers are meant to be looked up as |
---|
| 561 | utilities. This way we can find all applicant container types |
---|
| 562 | defined somewhere. |
---|
| 563 | |
---|
| 564 | Each applicants container provider registered as utility provides |
---|
| 565 | one container type and one should be able to call the `factory` |
---|
| 566 | attribute to create an instance of the requested container type. |
---|
| 567 | |
---|
| 568 | .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested) |
---|
[6076] | 569 | |
---|
[5820] | 570 | Samples |
---|
| 571 | ******* |
---|
[6076] | 572 | |
---|
[5820] | 573 | Given, you had an IApplicantsContainer implementation somewhere |
---|
| 574 | and you would like to make it findable on request, then you would |
---|
| 575 | normally create an appropriate provider utility like this:: |
---|
| 576 | |
---|
| 577 | import grok |
---|
[5846] | 578 | from waeup.sirp.applicants.interfaces import IApplicantsContainerProvider |
---|
[5820] | 579 | |
---|
| 580 | class MyContainerProvider(grok.GlobalUtility): |
---|
[5846] | 581 | grok.implements(IApplicantsContainerProvider) |
---|
[5820] | 582 | grok.name('MyContainerProvider') # Must be unique |
---|
| 583 | factory = MyContainer # A class implementing IApplicantsContainer |
---|
| 584 | # or derivations thereof. |
---|
| 585 | |
---|
| 586 | This utility would be registered on startup and could then be used |
---|
| 587 | like this: |
---|
| 588 | |
---|
| 589 | >>> from zope.component import getAllUtilitiesRegisteredFor |
---|
| 590 | >>> from waeup.sirp.applicants.interfaces import ( |
---|
[5846] | 591 | ... IApplicantsContainerProvider) |
---|
[5820] | 592 | >>> all_providers = getAllUtilitiesRegisteredFor( |
---|
[5846] | 593 | ... IApplicantsContainerProvider) |
---|
[5820] | 594 | >>> all_providers |
---|
| 595 | [<MyContainerProvider object at 0x...>] |
---|
| 596 | |
---|
| 597 | You could look up this specific provider by name: |
---|
| 598 | |
---|
| 599 | >>> from zope.component import getUtility |
---|
[5846] | 600 | >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider') |
---|
[5820] | 601 | >>> p |
---|
| 602 | <MyContainerProvider object at 0x...> |
---|
[6076] | 603 | |
---|
[5820] | 604 | An applicants container would then be created like this: |
---|
| 605 | |
---|
| 606 | >>> provider = all_providers[0] |
---|
| 607 | >>> container = provider.factory() |
---|
| 608 | >>> container |
---|
| 609 | <MyContainer object at 0x...> |
---|
| 610 | |
---|
| 611 | """ |
---|
| 612 | factory = Attribute("A class that can create instances of the " |
---|
| 613 | "requested container type") |
---|