[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 |
---|
[6343] | 25 | import re |
---|
[5753] | 26 | import waeup.sirp.browser |
---|
[6256] | 27 | |
---|
[5866] | 28 | from grokcore.content.interfaces import IContainer |
---|
[6256] | 29 | |
---|
[5638] | 30 | from zope import schema |
---|
[6290] | 31 | from zope.interface import Interface, Attribute, provider |
---|
[6075] | 32 | from zope.component import getUtility, getUtilitiesFor |
---|
[5758] | 33 | from zope.pluggableauth.interfaces import IPrincipalInfo |
---|
| 34 | from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal |
---|
[6256] | 35 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[5753] | 36 | from waeup.sirp.image.schema import ImageFile |
---|
[5980] | 37 | from waeup.sirp.image.image import WAeUPImageFile |
---|
[6256] | 38 | from waeup.sirp.interfaces import IWAeUPObject |
---|
[6189] | 39 | from waeup.sirp.university.vocabularies import application_categories |
---|
[6256] | 40 | from waeup.sirp.applicants.vocabularies import ( |
---|
| 41 | year_range, application_types_vocab, application_pins_vocab, |
---|
| 42 | lgas_vocab, CertificateSource, AppCatCertificateSource, |
---|
| 43 | GenderSource, entry_session_vocab |
---|
| 44 | ) |
---|
[5638] | 45 | |
---|
[5753] | 46 | IMAGE_PATH = os.path.join( |
---|
| 47 | os.path.dirname(waeup.sirp.browser.__file__), |
---|
| 48 | 'static' |
---|
| 49 | ) |
---|
[6313] | 50 | DEFAULT_PASSPORT_IMAGE_MALE = open( |
---|
| 51 | os.path.join(IMAGE_PATH, 'placeholder_m.jpg')).read() |
---|
| 52 | DEFAULT_PASSPORT_IMAGE_FEMALE = open( |
---|
| 53 | os.path.join(IMAGE_PATH, 'placeholder_f.jpg')).read() |
---|
[5753] | 54 | |
---|
[6343] | 55 | # Define a valiation method for email addresses |
---|
| 56 | class NotAnEmailAddress(schema.ValidationError): |
---|
| 57 | __doc__ = u"Invalid email address" |
---|
| 58 | |
---|
| 59 | check_email = re.compile(r"[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match |
---|
| 60 | def validate_email(value): |
---|
| 61 | if not check_email(value): |
---|
| 62 | raise NotAnEmailAddress(value) |
---|
| 63 | return True |
---|
| 64 | |
---|
[6290] | 65 | @provider(schema.interfaces.IContextAwareDefaultFactory) |
---|
| 66 | def default_passport_image(context): |
---|
| 67 | """A default value factory for ImageFile fields. |
---|
| 68 | |
---|
| 69 | Returns some default image as WAeUPImageFile. We cannot set the |
---|
| 70 | default directly in ImageFile fields, as, if we want to set |
---|
| 71 | max_size or min_size as well, some utility lookups are needed |
---|
| 72 | which are not possible during startup. |
---|
| 73 | |
---|
| 74 | Developers which use IContextAwareDefaultFactories like this one |
---|
| 75 | always should make sure that the delivered default meets all |
---|
| 76 | constraints of the field that makes use of this default value |
---|
| 77 | provider. |
---|
| 78 | """ |
---|
[6313] | 79 | return WAeUPImageFile( |
---|
| 80 | 'placeholder_m.jpg', DEFAULT_PASSPORT_IMAGE_MALE) |
---|
[6290] | 81 | |
---|
[6069] | 82 | class ApplicantContainerProviderSource(BasicSourceFactory): |
---|
[6075] | 83 | """A source offering all available applicants container types. |
---|
| 84 | |
---|
| 85 | The values returned by this source are names of utilities that can |
---|
| 86 | create :class:`ApplicantContainer` instances. So, if you get a |
---|
| 87 | name like ``'myactype'`` from this source, then you can do: |
---|
| 88 | |
---|
| 89 | >>> from zope.component import getUtility |
---|
| 90 | >>> p = getUtility(IApplicantsContainerProvider, name=myactype) |
---|
| 91 | >>> my_applicants_container = p.factory() |
---|
| 92 | |
---|
| 93 | Or you can access class-attributes like |
---|
| 94 | |
---|
| 95 | >>> my_applicants_container.container_title |
---|
| 96 | 'Pretty' |
---|
[6076] | 97 | |
---|
[6069] | 98 | """ |
---|
| 99 | def getValues(self): |
---|
[6075] | 100 | """Returns a list of ``(<name>, <provider>)`` tuples. |
---|
[5753] | 101 | |
---|
[6075] | 102 | Here ``<name>`` is the name under which an |
---|
| 103 | :class:``ApplicantContainerProvider`` was registered as a |
---|
| 104 | utility and ``<provider>`` is the utility itself. |
---|
| 105 | """ |
---|
| 106 | return getUtilitiesFor(IApplicantsContainerProvider) |
---|
| 107 | |
---|
[6069] | 108 | def getToken(self, value): |
---|
[6075] | 109 | """Return the name of the ``(<name>, <provider>)`` tuple. |
---|
| 110 | """ |
---|
| 111 | return value[0] |
---|
| 112 | |
---|
[6069] | 113 | def getTitle(self, value): |
---|
[6075] | 114 | """Get a 'title - description' string for a container type. |
---|
| 115 | """ |
---|
| 116 | factory = value[1].factory |
---|
| 117 | return "%s - %s" % ( |
---|
| 118 | factory.container_title, factory.container_description) |
---|
[6069] | 119 | |
---|
[5753] | 120 | class IResultEntry(IWAeUPObject): |
---|
| 121 | subject = schema.TextLine( |
---|
| 122 | title = u'Subject', |
---|
| 123 | description = u'The subject', |
---|
| 124 | required=False, |
---|
| 125 | ) |
---|
| 126 | score = schema.TextLine( |
---|
| 127 | title = u'Score', |
---|
| 128 | description = u'The score', |
---|
| 129 | required=False, |
---|
| 130 | ) |
---|
| 131 | |
---|
[5866] | 132 | class IApplicantsRoot(IWAeUPObject, IContainer): |
---|
[5676] | 133 | """A container for university applicants containers. |
---|
[5645] | 134 | """ |
---|
[5866] | 135 | pass |
---|
[5638] | 136 | |
---|
[5676] | 137 | class IApplicantsContainer(IWAeUPObject): |
---|
| 138 | """An applicants container contains university applicants. |
---|
[5645] | 139 | |
---|
[5638] | 140 | """ |
---|
[6069] | 141 | |
---|
[6075] | 142 | container_title = Attribute( |
---|
| 143 | u'classattribute: title for type of container') |
---|
| 144 | container_description = Attribute( |
---|
| 145 | u'classattribute: description for type of container') |
---|
| 146 | |
---|
[6076] | 147 | |
---|
[6069] | 148 | code = schema.TextLine( |
---|
| 149 | title = u'Code', |
---|
[6087] | 150 | default = u'-', |
---|
[6069] | 151 | required = True, |
---|
| 152 | readonly = True, |
---|
[6076] | 153 | ) |
---|
[6096] | 154 | |
---|
[6087] | 155 | title = schema.TextLine( |
---|
| 156 | title = u'Title', |
---|
| 157 | required = True, |
---|
| 158 | default = u'-', |
---|
| 159 | readonly = True, |
---|
[6096] | 160 | ) |
---|
| 161 | |
---|
[6087] | 162 | prefix = schema.Choice( |
---|
| 163 | title = u'Application target', |
---|
| 164 | required = True, |
---|
| 165 | default = None, |
---|
| 166 | source = application_types_vocab, |
---|
| 167 | readonly = True, |
---|
| 168 | ) |
---|
[6076] | 169 | |
---|
[6087] | 170 | year = schema.Choice( |
---|
| 171 | title = u'Year of entrance', |
---|
| 172 | required = True, |
---|
| 173 | default = None, |
---|
[6158] | 174 | values = year_range(), |
---|
[6087] | 175 | readonly = True, |
---|
[6096] | 176 | ) |
---|
[6087] | 177 | |
---|
[6069] | 178 | provider = schema.Choice( |
---|
[6070] | 179 | title = u'Applicants container type', |
---|
[6069] | 180 | required = True, |
---|
| 181 | default = None, |
---|
| 182 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 183 | readonly = True, |
---|
[6076] | 184 | ) |
---|
[6158] | 185 | |
---|
[6110] | 186 | ac_prefix = schema.Choice( |
---|
| 187 | title = u'Access code prefix', |
---|
| 188 | required = True, |
---|
| 189 | default = None, |
---|
[6111] | 190 | source = application_pins_vocab, |
---|
[6110] | 191 | ) |
---|
[6076] | 192 | |
---|
[6189] | 193 | application_category = schema.Choice( |
---|
| 194 | title = u'Category for the grouping of study courses', |
---|
| 195 | required = True, |
---|
| 196 | default = None, |
---|
| 197 | source = application_categories, |
---|
| 198 | ) |
---|
| 199 | |
---|
[5645] | 200 | description = schema.Text( |
---|
| 201 | title = u'Human readable description in reST format', |
---|
[5638] | 202 | required = False, |
---|
[6070] | 203 | default = u'No description yet.' |
---|
[5638] | 204 | ) |
---|
| 205 | |
---|
| 206 | startdate = schema.Date( |
---|
[5645] | 207 | title = u'Date when the application period starts', |
---|
[5638] | 208 | required = False, |
---|
| 209 | default = None, |
---|
| 210 | ) |
---|
| 211 | |
---|
| 212 | enddate = schema.Date( |
---|
[5645] | 213 | title = u'Date when the application period ends', |
---|
[5638] | 214 | required = False, |
---|
| 215 | default = None, |
---|
| 216 | ) |
---|
| 217 | |
---|
[5645] | 218 | strict_deadline = schema.Bool( |
---|
| 219 | title = u'Forbid additions after deadline (enddate)', |
---|
| 220 | required = True, |
---|
| 221 | default = True, |
---|
| 222 | ) |
---|
[5638] | 223 | |
---|
| 224 | def archive(id=None): |
---|
[5676] | 225 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 226 | |
---|
[5676] | 227 | If id is `None`, all applicants are archived. |
---|
[5638] | 228 | |
---|
| 229 | If id contains a single id string, only the respective |
---|
[5676] | 230 | applicants are archived. |
---|
[5638] | 231 | |
---|
| 232 | If id contains a list of id strings all of the respective |
---|
[5676] | 233 | applicants types are saved to disk. |
---|
[5638] | 234 | """ |
---|
| 235 | |
---|
| 236 | def clear(id=None, archive=True): |
---|
[5676] | 237 | """Remove applicants of type given by 'id'. |
---|
[5638] | 238 | |
---|
[5676] | 239 | Optionally archive the applicants. |
---|
[6076] | 240 | |
---|
[5676] | 241 | If id is `None`, all applicants are archived. |
---|
[5638] | 242 | |
---|
| 243 | If id contains a single id string, only the respective |
---|
[5676] | 244 | applicants are archived. |
---|
[5638] | 245 | |
---|
| 246 | If id contains a list of id strings all of the respective |
---|
[5676] | 247 | applicant types are saved to disk. |
---|
[5638] | 248 | |
---|
| 249 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 250 | and respective applicants are simply removed from the |
---|
[5638] | 251 | database. |
---|
| 252 | """ |
---|
[6073] | 253 | |
---|
[6069] | 254 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 255 | """An applicants container contains university applicants. |
---|
| 256 | """ |
---|
[6087] | 257 | prefix = schema.Choice( |
---|
| 258 | title = u'Application target', |
---|
[6069] | 259 | required = True, |
---|
[6087] | 260 | default = None, |
---|
| 261 | source = application_types_vocab, |
---|
[6069] | 262 | readonly = False, |
---|
[6076] | 263 | ) |
---|
[6073] | 264 | |
---|
[6087] | 265 | year = schema.Choice( |
---|
| 266 | title = u'Year of entrance', |
---|
| 267 | required = True, |
---|
| 268 | default = None, |
---|
[6158] | 269 | values = year_range(), |
---|
[6087] | 270 | readonly = False, |
---|
[6096] | 271 | ) |
---|
[6073] | 272 | |
---|
[6087] | 273 | provider = schema.Choice( |
---|
| 274 | title = u'Applicants container type', |
---|
| 275 | required = True, |
---|
| 276 | default = None, |
---|
| 277 | source = ApplicantContainerProviderSource(), |
---|
| 278 | readonly = False, |
---|
| 279 | ) |
---|
| 280 | |
---|
[6096] | 281 | IApplicantsContainerAdd[ |
---|
| 282 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 283 | IApplicantsContainerAdd[ |
---|
| 284 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 285 | IApplicantsContainerAdd[ |
---|
| 286 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 287 | |
---|
[5753] | 288 | class IApplicantBaseData(IWAeUPObject): |
---|
| 289 | """The data for an applicant. |
---|
| 290 | |
---|
| 291 | This is a base interface with no field (except ``reg_no``) |
---|
| 292 | required. For use with importers, forms, etc., please use one of |
---|
| 293 | the derived interfaces below, which set more fields to required |
---|
| 294 | state, depending on use-case. |
---|
| 295 | """ |
---|
[6339] | 296 | history = Attribute('Object history, a list of messages.') |
---|
[6332] | 297 | state = Attribute('Returns the application state of an applicant') |
---|
[6304] | 298 | |
---|
[6348] | 299 | def getApplicantsRootLogger(): |
---|
| 300 | """Returns the logger from the applicants root object |
---|
| 301 | """ |
---|
| 302 | |
---|
[5753] | 303 | reg_no = schema.TextLine( |
---|
| 304 | title = u'JAMB Registration Number', |
---|
[6195] | 305 | readonly = True, |
---|
[5753] | 306 | ) |
---|
| 307 | access_code = schema.TextLine( |
---|
| 308 | title = u'Access Code', |
---|
| 309 | required = False, |
---|
[6195] | 310 | readonly = True, |
---|
[5753] | 311 | ) |
---|
[6248] | 312 | course1 = schema.Choice( |
---|
[5753] | 313 | title = u'1st Choice Course of Study', |
---|
[6248] | 314 | source = AppCatCertificateSource(), |
---|
[6352] | 315 | required = True, |
---|
[5753] | 316 | ) |
---|
[6248] | 317 | course2 = schema.Choice( |
---|
[5753] | 318 | title = u'2nd Choice Course of Study', |
---|
[6248] | 319 | source = AppCatCertificateSource(), |
---|
[5753] | 320 | required = False, |
---|
| 321 | ) |
---|
| 322 | firstname = schema.TextLine( |
---|
| 323 | title = u'First Name', |
---|
[6352] | 324 | required = True, |
---|
[5753] | 325 | ) |
---|
| 326 | middlenames = schema.TextLine( |
---|
| 327 | title = u'Middle Names', |
---|
| 328 | required = False, |
---|
| 329 | ) |
---|
| 330 | lastname = schema.TextLine( |
---|
[6205] | 331 | title = u'Last Name (Surname)', |
---|
[6352] | 332 | required = True, |
---|
[5753] | 333 | ) |
---|
| 334 | date_of_birth = schema.Date( |
---|
| 335 | title = u'Date of Birth', |
---|
[6352] | 336 | required = True, |
---|
[5753] | 337 | ) |
---|
[6249] | 338 | lga = schema.Choice( |
---|
| 339 | source = lgas_vocab, |
---|
[6205] | 340 | title = u'State/LGA', |
---|
[6254] | 341 | default = 'foreigner', |
---|
| 342 | required = True, |
---|
[5753] | 343 | ) |
---|
| 344 | sex = schema.Choice( |
---|
| 345 | title = u'Sex', |
---|
| 346 | source = GenderSource(), |
---|
| 347 | default = u'm', |
---|
[6352] | 348 | required = True, |
---|
[5753] | 349 | ) |
---|
[6341] | 350 | email = schema.ASCIILine( |
---|
[5753] | 351 | title = u'Email', |
---|
| 352 | required = False, |
---|
[6343] | 353 | constraint=validate_email, |
---|
[5753] | 354 | ) |
---|
[6341] | 355 | phone = schema.Int( |
---|
[5753] | 356 | title = u'Phone', |
---|
[6341] | 357 | description = u'Enter phone number with country code and without spaces.', |
---|
[5753] | 358 | required = False, |
---|
| 359 | ) |
---|
| 360 | passport = ImageFile( |
---|
| 361 | title = u'Passport Photograph', |
---|
[6290] | 362 | #default = DEFAULT_PASSPORT_IMAGE_MALE, |
---|
| 363 | defaultFactory = default_passport_image, |
---|
[6341] | 364 | description = u'Maximun file size is 20 kB.', |
---|
[5753] | 365 | required = True, |
---|
[6285] | 366 | max_size = 20480, |
---|
[5753] | 367 | ) |
---|
[6322] | 368 | |
---|
[5753] | 369 | # |
---|
[6195] | 370 | # Process Data |
---|
[5753] | 371 | # |
---|
| 372 | application_date = schema.Date( |
---|
| 373 | title = u'Application Date', |
---|
| 374 | required = False, |
---|
[6195] | 375 | readonly = True, |
---|
[5753] | 376 | ) |
---|
[6255] | 377 | screening_score = schema.Int( |
---|
[5753] | 378 | title = u'Screening Score', |
---|
| 379 | required = False, |
---|
| 380 | ) |
---|
| 381 | screening_venue = schema.TextLine( |
---|
| 382 | title = u'Screening Venue', |
---|
| 383 | required = False, |
---|
| 384 | ) |
---|
[6248] | 385 | course_admitted = schema.Choice( |
---|
[5753] | 386 | title = u'Admitted Course of Study', |
---|
[6248] | 387 | source = CertificateSource(), |
---|
[6254] | 388 | default = None, |
---|
[5753] | 389 | required = False, |
---|
| 390 | ) |
---|
[6337] | 391 | # entry_session is inherited from the container |
---|
| 392 | #entry_session = schema.Choice( |
---|
| 393 | # source = entry_session_vocab, |
---|
| 394 | # title = u'Entry Session', |
---|
| 395 | # required = False, |
---|
| 396 | # ) |
---|
[5753] | 397 | notice = schema.Text( |
---|
| 398 | title = u'Notice', |
---|
| 399 | required = False, |
---|
| 400 | ) |
---|
| 401 | student_id = schema.TextLine( |
---|
| 402 | title = u'Student ID', |
---|
| 403 | required = False, |
---|
[6195] | 404 | readonly = True, |
---|
[5753] | 405 | ) |
---|
[6302] | 406 | locked = schema.Bool( |
---|
| 407 | title = u'Form locked', |
---|
| 408 | default = False, |
---|
| 409 | ) |
---|
[5753] | 410 | |
---|
| 411 | class IApplicant(IApplicantBaseData): |
---|
| 412 | """An applicant. |
---|
| 413 | |
---|
| 414 | This is basically the applicant base data. Here we repeat the |
---|
[6195] | 415 | fields from base data if we have to set the `required` attribute |
---|
| 416 | to True (which is the default). |
---|
[5753] | 417 | """ |
---|
| 418 | |
---|
[6195] | 419 | class IApplicantEdit(IApplicantBaseData): |
---|
| 420 | """An applicant. |
---|
[5753] | 421 | |
---|
[6339] | 422 | Here we can repeat the fields from base data and set the |
---|
| 423 | `required` and `readonly` attributes to True to further restrict |
---|
| 424 | the data access. We cannot omit fields. This has to be done in the |
---|
| 425 | respective form page. |
---|
[6195] | 426 | """ |
---|
[6255] | 427 | screening_score = schema.Int( |
---|
[5753] | 428 | title = u'Screening Score', |
---|
[6195] | 429 | required = False, |
---|
[5941] | 430 | readonly = True, |
---|
| 431 | ) |
---|
[6195] | 432 | screening_venue = schema.TextLine( |
---|
| 433 | title = u'Screening Venue', |
---|
[5753] | 434 | required = False, |
---|
| 435 | readonly = True, |
---|
| 436 | ) |
---|
[6301] | 437 | course_admitted = schema.Choice( |
---|
[6195] | 438 | title = u'Admitted Course of Study', |
---|
[6301] | 439 | source = CertificateSource(), |
---|
| 440 | default = None, |
---|
[5753] | 441 | required = False, |
---|
[6195] | 442 | readonly = True, |
---|
[5753] | 443 | ) |
---|
[6337] | 444 | # entry_session is inherited from the container |
---|
| 445 | #entry_session = schema.Choice( |
---|
| 446 | # source = entry_session_vocab, |
---|
| 447 | # title = u'Entry Session', |
---|
| 448 | # required = False, |
---|
| 449 | # readonly = True |
---|
| 450 | # ) |
---|
[6195] | 451 | notice = schema.Text( |
---|
| 452 | title = u'Notice', |
---|
[5753] | 453 | required = False, |
---|
| 454 | readonly = True, |
---|
| 455 | ) |
---|
[5758] | 456 | |
---|
| 457 | class IApplicantPrincipalInfo(IPrincipalInfo): |
---|
| 458 | """Infos about principals that are applicants. |
---|
| 459 | """ |
---|
| 460 | access_code = Attribute("The Access Code the user purchased") |
---|
| 461 | |
---|
| 462 | class IApplicantPrincipal(IPrincipal): |
---|
| 463 | """A principal that is an applicant. |
---|
| 464 | |
---|
| 465 | This interface extends zope.security.interfaces.IPrincipal and |
---|
| 466 | requires also an `id` and other attributes defined there. |
---|
| 467 | """ |
---|
| 468 | access_code = schema.TextLine( |
---|
| 469 | title = u'Access Code', |
---|
| 470 | description = u'The access code purchased by the user.', |
---|
| 471 | required = True, |
---|
| 472 | readonly = True) |
---|
| 473 | |
---|
| 474 | class IApplicantsFormChallenger(Interface): |
---|
| 475 | """A challenger that uses a browser form to collect applicant |
---|
| 476 | credentials. |
---|
| 477 | """ |
---|
| 478 | loginpagename = schema.TextLine( |
---|
| 479 | title = u'Loginpagename', |
---|
| 480 | description = u"""Name of the login form used by challenger. |
---|
| 481 | |
---|
| 482 | The form must provide an ``access_code`` input field. |
---|
| 483 | """) |
---|
| 484 | |
---|
| 485 | accesscode_field = schema.TextLine( |
---|
| 486 | title = u'Access code field', |
---|
| 487 | description = u'''Field of the login page which is looked up for |
---|
| 488 | access_code''', |
---|
| 489 | default = u'access_code', |
---|
| 490 | ) |
---|
| 491 | |
---|
| 492 | |
---|
| 493 | class IApplicantSessionCredentials(Interface): |
---|
| 494 | """Interface for storing and accessing applicant credentials in a |
---|
| 495 | session. |
---|
| 496 | """ |
---|
| 497 | |
---|
| 498 | def __init__(access_code): |
---|
| 499 | """Create applicant session credentials.""" |
---|
| 500 | |
---|
| 501 | def getAccessCode(): |
---|
| 502 | """Return the access code.""" |
---|
| 503 | |
---|
| 504 | |
---|
[5846] | 505 | class IApplicantsContainerProvider(Interface): |
---|
[5820] | 506 | """A provider for applicants containers. |
---|
| 507 | |
---|
| 508 | Applicants container providers are meant to be looked up as |
---|
| 509 | utilities. This way we can find all applicant container types |
---|
| 510 | defined somewhere. |
---|
| 511 | |
---|
| 512 | Each applicants container provider registered as utility provides |
---|
| 513 | one container type and one should be able to call the `factory` |
---|
| 514 | attribute to create an instance of the requested container type. |
---|
| 515 | |
---|
| 516 | .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested) |
---|
[6076] | 517 | |
---|
[5820] | 518 | Samples |
---|
| 519 | ******* |
---|
[6076] | 520 | |
---|
[5820] | 521 | Given, you had an IApplicantsContainer implementation somewhere |
---|
| 522 | and you would like to make it findable on request, then you would |
---|
| 523 | normally create an appropriate provider utility like this:: |
---|
| 524 | |
---|
| 525 | import grok |
---|
[5846] | 526 | from waeup.sirp.applicants.interfaces import IApplicantsContainerProvider |
---|
[5820] | 527 | |
---|
| 528 | class MyContainerProvider(grok.GlobalUtility): |
---|
[5846] | 529 | grok.implements(IApplicantsContainerProvider) |
---|
[5820] | 530 | grok.name('MyContainerProvider') # Must be unique |
---|
| 531 | factory = MyContainer # A class implementing IApplicantsContainer |
---|
| 532 | # or derivations thereof. |
---|
| 533 | |
---|
| 534 | This utility would be registered on startup and could then be used |
---|
| 535 | like this: |
---|
| 536 | |
---|
| 537 | >>> from zope.component import getAllUtilitiesRegisteredFor |
---|
| 538 | >>> from waeup.sirp.applicants.interfaces import ( |
---|
[5846] | 539 | ... IApplicantsContainerProvider) |
---|
[5820] | 540 | >>> all_providers = getAllUtilitiesRegisteredFor( |
---|
[5846] | 541 | ... IApplicantsContainerProvider) |
---|
[5820] | 542 | >>> all_providers |
---|
| 543 | [<MyContainerProvider object at 0x...>] |
---|
| 544 | |
---|
| 545 | You could look up this specific provider by name: |
---|
| 546 | |
---|
| 547 | >>> from zope.component import getUtility |
---|
[5846] | 548 | >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider') |
---|
[5820] | 549 | >>> p |
---|
| 550 | <MyContainerProvider object at 0x...> |
---|
[6076] | 551 | |
---|
[5820] | 552 | An applicants container would then be created like this: |
---|
| 553 | |
---|
| 554 | >>> provider = all_providers[0] |
---|
| 555 | >>> container = provider.factory() |
---|
| 556 | >>> container |
---|
| 557 | <MyContainer object at 0x...> |
---|
| 558 | |
---|
| 559 | """ |
---|
| 560 | factory = Attribute("A class that can create instances of the " |
---|
| 561 | "requested container type") |
---|