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