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