[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 | ## |
---|
[6500] | 22 | """Interfaces of the university application package. |
---|
[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 | """ |
---|
[6538] | 78 | from waeup.sirp.image import createWAeUPImageFile |
---|
| 79 | imagefile = createWAeUPImageFile( |
---|
| 80 | 'placeholder_m.jpg', |
---|
| 81 | open(os.path.join(IMAGE_PATH, 'placeholder_m.jpg'), 'r') |
---|
| 82 | ) |
---|
| 83 | return imagefile |
---|
[6313] | 84 | return WAeUPImageFile( |
---|
| 85 | 'placeholder_m.jpg', DEFAULT_PASSPORT_IMAGE_MALE) |
---|
[6290] | 86 | |
---|
[6069] | 87 | class ApplicantContainerProviderSource(BasicSourceFactory): |
---|
[6075] | 88 | """A source offering all available applicants container types. |
---|
| 89 | |
---|
| 90 | The values returned by this source are names of utilities that can |
---|
| 91 | create :class:`ApplicantContainer` instances. So, if you get a |
---|
| 92 | name like ``'myactype'`` from this source, then you can do: |
---|
| 93 | |
---|
| 94 | >>> from zope.component import getUtility |
---|
| 95 | >>> p = getUtility(IApplicantsContainerProvider, name=myactype) |
---|
| 96 | >>> my_applicants_container = p.factory() |
---|
| 97 | |
---|
| 98 | Or you can access class-attributes like |
---|
| 99 | |
---|
| 100 | >>> my_applicants_container.container_title |
---|
| 101 | 'Pretty' |
---|
[6076] | 102 | |
---|
[6069] | 103 | """ |
---|
| 104 | def getValues(self): |
---|
[6075] | 105 | """Returns a list of ``(<name>, <provider>)`` tuples. |
---|
[5753] | 106 | |
---|
[6075] | 107 | Here ``<name>`` is the name under which an |
---|
| 108 | :class:``ApplicantContainerProvider`` was registered as a |
---|
| 109 | utility and ``<provider>`` is the utility itself. |
---|
| 110 | """ |
---|
| 111 | return getUtilitiesFor(IApplicantsContainerProvider) |
---|
| 112 | |
---|
[6069] | 113 | def getToken(self, value): |
---|
[6075] | 114 | """Return the name of the ``(<name>, <provider>)`` tuple. |
---|
| 115 | """ |
---|
| 116 | return value[0] |
---|
| 117 | |
---|
[6069] | 118 | def getTitle(self, value): |
---|
[6075] | 119 | """Get a 'title - description' string for a container type. |
---|
| 120 | """ |
---|
| 121 | factory = value[1].factory |
---|
| 122 | return "%s - %s" % ( |
---|
| 123 | factory.container_title, factory.container_description) |
---|
[6069] | 124 | |
---|
[5753] | 125 | class IResultEntry(IWAeUPObject): |
---|
| 126 | subject = schema.TextLine( |
---|
| 127 | title = u'Subject', |
---|
| 128 | description = u'The subject', |
---|
| 129 | required=False, |
---|
| 130 | ) |
---|
| 131 | score = schema.TextLine( |
---|
| 132 | title = u'Score', |
---|
| 133 | description = u'The score', |
---|
| 134 | required=False, |
---|
| 135 | ) |
---|
| 136 | |
---|
[5866] | 137 | class IApplicantsRoot(IWAeUPObject, IContainer): |
---|
[5676] | 138 | """A container for university applicants containers. |
---|
[5645] | 139 | """ |
---|
[5866] | 140 | pass |
---|
[5638] | 141 | |
---|
[5676] | 142 | class IApplicantsContainer(IWAeUPObject): |
---|
| 143 | """An applicants container contains university applicants. |
---|
[5645] | 144 | |
---|
[5638] | 145 | """ |
---|
[6069] | 146 | |
---|
[6075] | 147 | container_title = Attribute( |
---|
| 148 | u'classattribute: title for type of container') |
---|
| 149 | container_description = Attribute( |
---|
| 150 | u'classattribute: description for type of container') |
---|
| 151 | |
---|
[6076] | 152 | |
---|
[6069] | 153 | code = schema.TextLine( |
---|
| 154 | title = u'Code', |
---|
[6087] | 155 | default = u'-', |
---|
[6069] | 156 | required = True, |
---|
| 157 | readonly = True, |
---|
[6076] | 158 | ) |
---|
[6096] | 159 | |
---|
[6087] | 160 | title = schema.TextLine( |
---|
| 161 | title = u'Title', |
---|
| 162 | required = True, |
---|
| 163 | default = u'-', |
---|
| 164 | readonly = True, |
---|
[6096] | 165 | ) |
---|
| 166 | |
---|
[6087] | 167 | prefix = schema.Choice( |
---|
| 168 | title = u'Application target', |
---|
| 169 | required = True, |
---|
| 170 | default = None, |
---|
| 171 | source = application_types_vocab, |
---|
| 172 | readonly = True, |
---|
| 173 | ) |
---|
[6076] | 174 | |
---|
[6087] | 175 | year = schema.Choice( |
---|
| 176 | title = u'Year of entrance', |
---|
| 177 | required = True, |
---|
| 178 | default = None, |
---|
[6158] | 179 | values = year_range(), |
---|
[6087] | 180 | readonly = True, |
---|
[6096] | 181 | ) |
---|
[6087] | 182 | |
---|
[6069] | 183 | provider = schema.Choice( |
---|
[6070] | 184 | title = u'Applicants container type', |
---|
[6069] | 185 | required = True, |
---|
| 186 | default = None, |
---|
| 187 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 188 | readonly = True, |
---|
[6076] | 189 | ) |
---|
[6158] | 190 | |
---|
[6110] | 191 | ac_prefix = schema.Choice( |
---|
| 192 | title = u'Access code prefix', |
---|
| 193 | required = True, |
---|
| 194 | default = None, |
---|
[6111] | 195 | source = application_pins_vocab, |
---|
[6110] | 196 | ) |
---|
[6076] | 197 | |
---|
[6189] | 198 | application_category = schema.Choice( |
---|
[6477] | 199 | title = u'Category for the grouping of certificates', |
---|
[6189] | 200 | required = True, |
---|
| 201 | default = None, |
---|
| 202 | source = application_categories, |
---|
| 203 | ) |
---|
| 204 | |
---|
[5645] | 205 | description = schema.Text( |
---|
| 206 | title = u'Human readable description in reST format', |
---|
[5638] | 207 | required = False, |
---|
[6518] | 208 | default = u'''This text can been seen by anonymous users. |
---|
| 209 | Here we put information about the study courses provided, the application procedure and deadlines.''' |
---|
[5638] | 210 | ) |
---|
| 211 | |
---|
| 212 | startdate = schema.Date( |
---|
[6509] | 213 | title = u'Application start date', |
---|
[5638] | 214 | required = False, |
---|
| 215 | default = None, |
---|
| 216 | ) |
---|
| 217 | |
---|
| 218 | enddate = schema.Date( |
---|
[6509] | 219 | title = u'Application closing date', |
---|
[5638] | 220 | required = False, |
---|
| 221 | default = None, |
---|
| 222 | ) |
---|
| 223 | |
---|
[5645] | 224 | strict_deadline = schema.Bool( |
---|
| 225 | title = u'Forbid additions after deadline (enddate)', |
---|
| 226 | required = True, |
---|
| 227 | default = True, |
---|
| 228 | ) |
---|
[5638] | 229 | |
---|
| 230 | def archive(id=None): |
---|
[5676] | 231 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 232 | |
---|
[5676] | 233 | If id is `None`, all applicants are archived. |
---|
[5638] | 234 | |
---|
| 235 | If id contains a single id string, only the respective |
---|
[5676] | 236 | applicants are archived. |
---|
[5638] | 237 | |
---|
| 238 | If id contains a list of id strings all of the respective |
---|
[5676] | 239 | applicants types are saved to disk. |
---|
[5638] | 240 | """ |
---|
| 241 | |
---|
| 242 | def clear(id=None, archive=True): |
---|
[5676] | 243 | """Remove applicants of type given by 'id'. |
---|
[5638] | 244 | |
---|
[5676] | 245 | Optionally archive the applicants. |
---|
[6076] | 246 | |
---|
[5676] | 247 | If id is `None`, all applicants are archived. |
---|
[5638] | 248 | |
---|
| 249 | If id contains a single id string, only the respective |
---|
[5676] | 250 | applicants are archived. |
---|
[5638] | 251 | |
---|
| 252 | If id contains a list of id strings all of the respective |
---|
[5676] | 253 | applicant types are saved to disk. |
---|
[5638] | 254 | |
---|
| 255 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 256 | and respective applicants are simply removed from the |
---|
[5638] | 257 | database. |
---|
| 258 | """ |
---|
[6073] | 259 | |
---|
[6069] | 260 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 261 | """An applicants container contains university applicants. |
---|
| 262 | """ |
---|
[6087] | 263 | prefix = schema.Choice( |
---|
| 264 | title = u'Application target', |
---|
[6069] | 265 | required = True, |
---|
[6087] | 266 | default = None, |
---|
| 267 | source = application_types_vocab, |
---|
[6069] | 268 | readonly = False, |
---|
[6076] | 269 | ) |
---|
[6073] | 270 | |
---|
[6087] | 271 | year = schema.Choice( |
---|
| 272 | title = u'Year of entrance', |
---|
| 273 | required = True, |
---|
| 274 | default = None, |
---|
[6158] | 275 | values = year_range(), |
---|
[6087] | 276 | readonly = False, |
---|
[6096] | 277 | ) |
---|
[6073] | 278 | |
---|
[6087] | 279 | provider = schema.Choice( |
---|
| 280 | title = u'Applicants container type', |
---|
| 281 | required = True, |
---|
| 282 | default = None, |
---|
| 283 | source = ApplicantContainerProviderSource(), |
---|
| 284 | readonly = False, |
---|
| 285 | ) |
---|
| 286 | |
---|
[6096] | 287 | IApplicantsContainerAdd[ |
---|
| 288 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 289 | IApplicantsContainerAdd[ |
---|
| 290 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 291 | IApplicantsContainerAdd[ |
---|
| 292 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 293 | |
---|
[5753] | 294 | class IApplicantBaseData(IWAeUPObject): |
---|
| 295 | """The data for an applicant. |
---|
| 296 | |
---|
| 297 | This is a base interface with no field (except ``reg_no``) |
---|
| 298 | required. For use with importers, forms, etc., please use one of |
---|
| 299 | the derived interfaces below, which set more fields to required |
---|
| 300 | state, depending on use-case. |
---|
| 301 | """ |
---|
[6339] | 302 | history = Attribute('Object history, a list of messages.') |
---|
[6332] | 303 | state = Attribute('Returns the application state of an applicant') |
---|
[6476] | 304 | application_date = Attribute('Date of submission, used for export only') |
---|
[6304] | 305 | |
---|
[6476] | 306 | #def getApplicantsRootLogger(): |
---|
| 307 | # """Returns the logger from the applicants root object |
---|
| 308 | # """ |
---|
| 309 | |
---|
| 310 | def loggerInfo(ob_class, comment): |
---|
| 311 | """Adds an INFO message to the log file |
---|
[6348] | 312 | """ |
---|
| 313 | |
---|
[5753] | 314 | reg_no = schema.TextLine( |
---|
| 315 | title = u'JAMB Registration Number', |
---|
[6195] | 316 | readonly = True, |
---|
[5753] | 317 | ) |
---|
| 318 | access_code = schema.TextLine( |
---|
| 319 | title = u'Access Code', |
---|
| 320 | required = False, |
---|
[6195] | 321 | readonly = True, |
---|
[5753] | 322 | ) |
---|
[6248] | 323 | course1 = schema.Choice( |
---|
[5753] | 324 | title = u'1st Choice Course of Study', |
---|
[6248] | 325 | source = AppCatCertificateSource(), |
---|
[6352] | 326 | required = True, |
---|
[5753] | 327 | ) |
---|
[6248] | 328 | course2 = schema.Choice( |
---|
[5753] | 329 | title = u'2nd Choice Course of Study', |
---|
[6248] | 330 | source = AppCatCertificateSource(), |
---|
[5753] | 331 | required = False, |
---|
| 332 | ) |
---|
| 333 | firstname = schema.TextLine( |
---|
| 334 | title = u'First Name', |
---|
[6352] | 335 | required = True, |
---|
[5753] | 336 | ) |
---|
| 337 | middlenames = schema.TextLine( |
---|
| 338 | title = u'Middle Names', |
---|
| 339 | required = False, |
---|
| 340 | ) |
---|
| 341 | lastname = schema.TextLine( |
---|
[6205] | 342 | title = u'Last Name (Surname)', |
---|
[6352] | 343 | required = True, |
---|
[5753] | 344 | ) |
---|
| 345 | date_of_birth = schema.Date( |
---|
| 346 | title = u'Date of Birth', |
---|
[6352] | 347 | required = True, |
---|
[5753] | 348 | ) |
---|
[6249] | 349 | lga = schema.Choice( |
---|
| 350 | source = lgas_vocab, |
---|
[6205] | 351 | title = u'State/LGA', |
---|
[6254] | 352 | default = 'foreigner', |
---|
| 353 | required = True, |
---|
[5753] | 354 | ) |
---|
| 355 | sex = schema.Choice( |
---|
| 356 | title = u'Sex', |
---|
| 357 | source = GenderSource(), |
---|
| 358 | default = u'm', |
---|
[6352] | 359 | required = True, |
---|
[5753] | 360 | ) |
---|
[6341] | 361 | email = schema.ASCIILine( |
---|
[5753] | 362 | title = u'Email', |
---|
| 363 | required = False, |
---|
[6343] | 364 | constraint=validate_email, |
---|
[5753] | 365 | ) |
---|
[6341] | 366 | phone = schema.Int( |
---|
[5753] | 367 | title = u'Phone', |
---|
[6341] | 368 | description = u'Enter phone number with country code and without spaces.', |
---|
[5753] | 369 | required = False, |
---|
| 370 | ) |
---|
| 371 | passport = ImageFile( |
---|
| 372 | title = u'Passport Photograph', |
---|
[6290] | 373 | #default = DEFAULT_PASSPORT_IMAGE_MALE, |
---|
| 374 | defaultFactory = default_passport_image, |
---|
[6341] | 375 | description = u'Maximun file size is 20 kB.', |
---|
[5753] | 376 | required = True, |
---|
[6285] | 377 | max_size = 20480, |
---|
[5753] | 378 | ) |
---|
[6322] | 379 | |
---|
[5753] | 380 | # |
---|
[6195] | 381 | # Process Data |
---|
[5753] | 382 | # |
---|
[6255] | 383 | screening_score = schema.Int( |
---|
[5753] | 384 | title = u'Screening Score', |
---|
| 385 | required = False, |
---|
| 386 | ) |
---|
| 387 | screening_venue = schema.TextLine( |
---|
| 388 | title = u'Screening Venue', |
---|
| 389 | required = False, |
---|
| 390 | ) |
---|
[6248] | 391 | course_admitted = schema.Choice( |
---|
[5753] | 392 | title = u'Admitted Course of Study', |
---|
[6248] | 393 | source = CertificateSource(), |
---|
[6254] | 394 | default = None, |
---|
[5753] | 395 | required = False, |
---|
| 396 | ) |
---|
| 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 | |
---|
[6500] | 518 | Samples: |
---|
[6076] | 519 | |
---|
[5820] | 520 | Given, you had an IApplicantsContainer implementation somewhere |
---|
| 521 | and you would like to make it findable on request, then you would |
---|
| 522 | normally create an appropriate provider utility like this:: |
---|
| 523 | |
---|
| 524 | import grok |
---|
[5846] | 525 | from waeup.sirp.applicants.interfaces import IApplicantsContainerProvider |
---|
[5820] | 526 | |
---|
| 527 | class MyContainerProvider(grok.GlobalUtility): |
---|
[5846] | 528 | grok.implements(IApplicantsContainerProvider) |
---|
[5820] | 529 | grok.name('MyContainerProvider') # Must be unique |
---|
| 530 | factory = MyContainer # A class implementing IApplicantsContainer |
---|
| 531 | # or derivations thereof. |
---|
| 532 | |
---|
| 533 | This utility would be registered on startup and could then be used |
---|
| 534 | like this: |
---|
| 535 | |
---|
| 536 | >>> from zope.component import getAllUtilitiesRegisteredFor |
---|
| 537 | >>> from waeup.sirp.applicants.interfaces import ( |
---|
[5846] | 538 | ... IApplicantsContainerProvider) |
---|
[5820] | 539 | >>> all_providers = getAllUtilitiesRegisteredFor( |
---|
[5846] | 540 | ... IApplicantsContainerProvider) |
---|
[5820] | 541 | >>> all_providers |
---|
| 542 | [<MyContainerProvider object at 0x...>] |
---|
| 543 | |
---|
| 544 | You could look up this specific provider by name: |
---|
| 545 | |
---|
| 546 | >>> from zope.component import getUtility |
---|
[5846] | 547 | >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider') |
---|
[5820] | 548 | >>> p |
---|
| 549 | <MyContainerProvider object at 0x...> |
---|
[6076] | 550 | |
---|
[5820] | 551 | An applicants container would then be created like this: |
---|
| 552 | |
---|
| 553 | >>> provider = all_providers[0] |
---|
| 554 | >>> container = provider.factory() |
---|
| 555 | >>> container |
---|
| 556 | <MyContainer object at 0x...> |
---|
| 557 | |
---|
| 558 | """ |
---|
| 559 | factory = Attribute("A class that can create instances of the " |
---|
| 560 | "requested container type") |
---|