[5638] | 1 | ## $Id: interfaces.py 7682 2012-02-22 21:32:11Z henrik $ |
---|
[6076] | 2 | ## |
---|
[6087] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
[5638] | 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
[6076] | 8 | ## |
---|
[5638] | 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
[6076] | 13 | ## |
---|
[5638] | 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[6500] | 18 | """Interfaces of the university application package. |
---|
[5638] | 19 | """ |
---|
[6256] | 20 | |
---|
[5866] | 21 | from grokcore.content.interfaces import IContainer |
---|
[6256] | 22 | |
---|
[5638] | 23 | from zope import schema |
---|
[7263] | 24 | from zope.interface import Interface, Attribute, implements, directlyProvides |
---|
| 25 | from zope.component import getUtilitiesFor, queryUtility |
---|
| 26 | from zope.catalog.interfaces import ICatalog |
---|
[7317] | 27 | from zope.schema.interfaces import ( |
---|
| 28 | ValidationError, ISource, IContextSourceBinder) |
---|
[6256] | 29 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[7263] | 30 | from waeup.sirp.schema import TextLineChoice |
---|
[7250] | 31 | from waeup.sirp.interfaces import ( |
---|
[7321] | 32 | ISIRPObject, year_range, validate_email, academic_sessions_vocab) |
---|
[7436] | 33 | from waeup.sirp.university.vocabularies import ( |
---|
[7681] | 34 | course_levels, AppCatSource) |
---|
[7347] | 35 | from waeup.sirp.students.vocabularies import ( |
---|
[7436] | 36 | lgas_vocab, CertificateSource, GenderSource) |
---|
[6256] | 37 | from waeup.sirp.applicants.vocabularies import ( |
---|
[7438] | 38 | application_types_vocab, AppCatCertificateSource) |
---|
[7250] | 39 | from waeup.sirp.payments.interfaces import IOnlinePayment |
---|
[5638] | 40 | |
---|
[7075] | 41 | #: Maximum upload size for applicant passport photographs (in bytes) |
---|
[7086] | 42 | MAX_UPLOAD_SIZE = 1024 * 20 |
---|
[7075] | 43 | |
---|
[7263] | 44 | class RegNumInSource(ValidationError): |
---|
| 45 | """Registration number exists already |
---|
| 46 | """ |
---|
| 47 | # The docstring of ValidationErrors is used as error description |
---|
| 48 | # by zope.formlib. |
---|
| 49 | pass |
---|
| 50 | |
---|
| 51 | class RegNumberSource(object): |
---|
| 52 | implements(ISource) |
---|
| 53 | cat_name = 'applicants_catalog' |
---|
[7270] | 54 | field_name = 'reg_number' |
---|
[7263] | 55 | validation_error = RegNumInSource |
---|
| 56 | def __init__(self, context): |
---|
| 57 | self.context = context |
---|
| 58 | return |
---|
| 59 | |
---|
| 60 | def __contains__(self, value): |
---|
| 61 | cat = queryUtility(ICatalog, self.cat_name) |
---|
| 62 | if cat is None: |
---|
| 63 | return True |
---|
| 64 | kw = {self.field_name: (value, value)} |
---|
| 65 | results = cat.searchResults(**kw) |
---|
| 66 | for entry in results: |
---|
| 67 | if entry.applicant_id != self.context.applicant_id: |
---|
| 68 | # XXX: sources should simply return False. |
---|
| 69 | # But then we get some stupid error message in forms |
---|
| 70 | # when validation fails. |
---|
| 71 | raise self.validation_error(value) |
---|
| 72 | #return False |
---|
| 73 | return True |
---|
| 74 | |
---|
| 75 | def contextual_reg_num_source(context): |
---|
| 76 | source = RegNumberSource(context) |
---|
| 77 | return source |
---|
| 78 | directlyProvides(contextual_reg_num_source, IContextSourceBinder) |
---|
| 79 | |
---|
[6069] | 80 | class ApplicantContainerProviderSource(BasicSourceFactory): |
---|
[6075] | 81 | """A source offering all available applicants container types. |
---|
| 82 | |
---|
| 83 | The values returned by this source are names of utilities that can |
---|
| 84 | create :class:`ApplicantContainer` instances. So, if you get a |
---|
| 85 | name like ``'myactype'`` from this source, then you can do: |
---|
| 86 | |
---|
| 87 | >>> from zope.component import getUtility |
---|
| 88 | >>> p = getUtility(IApplicantsContainerProvider, name=myactype) |
---|
| 89 | >>> my_applicants_container = p.factory() |
---|
| 90 | |
---|
| 91 | Or you can access class-attributes like |
---|
| 92 | |
---|
| 93 | >>> my_applicants_container.container_title |
---|
| 94 | 'Pretty' |
---|
[6076] | 95 | |
---|
[6069] | 96 | """ |
---|
| 97 | def getValues(self): |
---|
[6075] | 98 | """Returns a list of ``(<name>, <provider>)`` tuples. |
---|
[5753] | 99 | |
---|
[6075] | 100 | Here ``<name>`` is the name under which an |
---|
| 101 | :class:``ApplicantContainerProvider`` was registered as a |
---|
| 102 | utility and ``<provider>`` is the utility itself. |
---|
| 103 | """ |
---|
| 104 | return getUtilitiesFor(IApplicantsContainerProvider) |
---|
| 105 | |
---|
[6069] | 106 | def getToken(self, value): |
---|
[6075] | 107 | """Return the name of the ``(<name>, <provider>)`` tuple. |
---|
| 108 | """ |
---|
| 109 | return value[0] |
---|
| 110 | |
---|
[6069] | 111 | def getTitle(self, value): |
---|
[6075] | 112 | """Get a 'title - description' string for a container type. |
---|
| 113 | """ |
---|
| 114 | factory = value[1].factory |
---|
| 115 | return "%s - %s" % ( |
---|
| 116 | factory.container_title, factory.container_description) |
---|
[6069] | 117 | |
---|
[7682] | 118 | class IApplicantsUtils(Interface): |
---|
| 119 | """A collection of methods which are subject to customization. |
---|
| 120 | """ |
---|
| 121 | |
---|
[7321] | 122 | class IApplicantsRoot(ISIRPObject, IContainer): |
---|
[5676] | 123 | """A container for university applicants containers. |
---|
[5645] | 124 | """ |
---|
[5866] | 125 | pass |
---|
[5638] | 126 | |
---|
[7321] | 127 | class IApplicantsContainer(ISIRPObject): |
---|
[5676] | 128 | """An applicants container contains university applicants. |
---|
[5645] | 129 | |
---|
[5638] | 130 | """ |
---|
[6069] | 131 | |
---|
[6075] | 132 | container_title = Attribute( |
---|
| 133 | u'classattribute: title for type of container') |
---|
| 134 | container_description = Attribute( |
---|
| 135 | u'classattribute: description for type of container') |
---|
| 136 | |
---|
[6076] | 137 | |
---|
[6069] | 138 | code = schema.TextLine( |
---|
| 139 | title = u'Code', |
---|
[6087] | 140 | default = u'-', |
---|
[6069] | 141 | required = True, |
---|
| 142 | readonly = True, |
---|
[6076] | 143 | ) |
---|
[6096] | 144 | |
---|
[6087] | 145 | title = schema.TextLine( |
---|
| 146 | title = u'Title', |
---|
| 147 | required = True, |
---|
| 148 | default = u'-', |
---|
| 149 | readonly = True, |
---|
[6096] | 150 | ) |
---|
| 151 | |
---|
[6087] | 152 | prefix = schema.Choice( |
---|
| 153 | title = u'Application target', |
---|
| 154 | required = True, |
---|
| 155 | default = None, |
---|
| 156 | source = application_types_vocab, |
---|
| 157 | readonly = True, |
---|
| 158 | ) |
---|
[6076] | 159 | |
---|
[7436] | 160 | entry_level = schema.Choice( |
---|
| 161 | title = u'Entry Level', |
---|
| 162 | vocabulary = course_levels, |
---|
| 163 | default = 100, |
---|
| 164 | required = True, |
---|
| 165 | ) |
---|
| 166 | |
---|
[6087] | 167 | year = schema.Choice( |
---|
| 168 | title = u'Year of entrance', |
---|
| 169 | required = True, |
---|
| 170 | default = None, |
---|
[6158] | 171 | values = year_range(), |
---|
[6087] | 172 | readonly = True, |
---|
[6096] | 173 | ) |
---|
[6087] | 174 | |
---|
[6069] | 175 | provider = schema.Choice( |
---|
[6070] | 176 | title = u'Applicants container type', |
---|
[6069] | 177 | required = True, |
---|
| 178 | default = None, |
---|
| 179 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 180 | readonly = True, |
---|
[6076] | 181 | ) |
---|
[6158] | 182 | |
---|
[7376] | 183 | #ac_prefix = schema.Choice( |
---|
| 184 | # title = u'Activation code prefix', |
---|
| 185 | # required = True, |
---|
| 186 | # default = None, |
---|
| 187 | # source = application_pins_vocab, |
---|
| 188 | # ) |
---|
[6076] | 189 | |
---|
[6189] | 190 | application_category = schema.Choice( |
---|
[6477] | 191 | title = u'Category for the grouping of certificates', |
---|
[6189] | 192 | required = True, |
---|
| 193 | default = None, |
---|
[7681] | 194 | source = AppCatSource(), |
---|
[6189] | 195 | ) |
---|
| 196 | |
---|
[5645] | 197 | description = schema.Text( |
---|
| 198 | title = u'Human readable description in reST format', |
---|
[5638] | 199 | required = False, |
---|
[6518] | 200 | default = u'''This text can been seen by anonymous users. |
---|
| 201 | Here we put information about the study courses provided, the application procedure and deadlines.''' |
---|
[5638] | 202 | ) |
---|
| 203 | |
---|
| 204 | startdate = schema.Date( |
---|
[6509] | 205 | title = u'Application start date', |
---|
[5638] | 206 | required = False, |
---|
| 207 | default = None, |
---|
| 208 | ) |
---|
| 209 | |
---|
| 210 | enddate = schema.Date( |
---|
[6509] | 211 | title = u'Application closing date', |
---|
[5638] | 212 | required = False, |
---|
| 213 | default = None, |
---|
| 214 | ) |
---|
| 215 | |
---|
[5645] | 216 | strict_deadline = schema.Bool( |
---|
| 217 | title = u'Forbid additions after deadline (enddate)', |
---|
| 218 | required = True, |
---|
| 219 | default = True, |
---|
| 220 | ) |
---|
[5638] | 221 | |
---|
| 222 | def archive(id=None): |
---|
[5676] | 223 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 224 | |
---|
[5676] | 225 | If id is `None`, all applicants are archived. |
---|
[5638] | 226 | |
---|
| 227 | If id contains a single id string, only the respective |
---|
[5676] | 228 | applicants are archived. |
---|
[5638] | 229 | |
---|
| 230 | If id contains a list of id strings all of the respective |
---|
[5676] | 231 | applicants types are saved to disk. |
---|
[5638] | 232 | """ |
---|
| 233 | |
---|
| 234 | def clear(id=None, archive=True): |
---|
[5676] | 235 | """Remove applicants of type given by 'id'. |
---|
[5638] | 236 | |
---|
[5676] | 237 | Optionally archive the applicants. |
---|
[6076] | 238 | |
---|
[5676] | 239 | If id is `None`, all applicants are archived. |
---|
[5638] | 240 | |
---|
| 241 | If id contains a single id string, only the respective |
---|
[5676] | 242 | applicants are archived. |
---|
[5638] | 243 | |
---|
| 244 | If id contains a list of id strings all of the respective |
---|
[5676] | 245 | applicant types are saved to disk. |
---|
[5638] | 246 | |
---|
| 247 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 248 | and respective applicants are simply removed from the |
---|
[5638] | 249 | database. |
---|
| 250 | """ |
---|
[6073] | 251 | |
---|
[6069] | 252 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 253 | """An applicants container contains university applicants. |
---|
| 254 | """ |
---|
[6087] | 255 | prefix = schema.Choice( |
---|
| 256 | title = u'Application target', |
---|
[6069] | 257 | required = True, |
---|
[6087] | 258 | default = None, |
---|
| 259 | source = application_types_vocab, |
---|
[6069] | 260 | readonly = False, |
---|
[6076] | 261 | ) |
---|
[6073] | 262 | |
---|
[6087] | 263 | year = schema.Choice( |
---|
| 264 | title = u'Year of entrance', |
---|
| 265 | required = True, |
---|
| 266 | default = None, |
---|
[6158] | 267 | values = year_range(), |
---|
[6087] | 268 | readonly = False, |
---|
[6096] | 269 | ) |
---|
[6073] | 270 | |
---|
[6087] | 271 | provider = schema.Choice( |
---|
| 272 | title = u'Applicants container type', |
---|
| 273 | required = True, |
---|
| 274 | default = None, |
---|
| 275 | source = ApplicantContainerProviderSource(), |
---|
| 276 | readonly = False, |
---|
| 277 | ) |
---|
| 278 | |
---|
[6096] | 279 | IApplicantsContainerAdd[ |
---|
| 280 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 281 | IApplicantsContainerAdd[ |
---|
| 282 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 283 | IApplicantsContainerAdd[ |
---|
| 284 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 285 | |
---|
[7321] | 286 | class IApplicantBaseData(ISIRPObject): |
---|
[5753] | 287 | """The data for an applicant. |
---|
| 288 | |
---|
[7240] | 289 | This is a base interface with no field |
---|
[5753] | 290 | required. For use with importers, forms, etc., please use one of |
---|
| 291 | the derived interfaces below, which set more fields to required |
---|
| 292 | state, depending on use-case. |
---|
[7338] | 293 | |
---|
| 294 | This base interface is also implemented by the StudentApplication |
---|
| 295 | class in the students package. Thus, these are the data which are saved |
---|
| 296 | after admission. |
---|
[5753] | 297 | """ |
---|
[6304] | 298 | |
---|
[7240] | 299 | applicant_id = schema.TextLine( |
---|
| 300 | title = u'Applicant Id', |
---|
| 301 | required = False, |
---|
[7260] | 302 | readonly = False, |
---|
[7240] | 303 | ) |
---|
[7270] | 304 | reg_number = TextLineChoice( |
---|
[5753] | 305 | title = u'JAMB Registration Number', |
---|
[7263] | 306 | readonly = False, |
---|
| 307 | required = True, |
---|
| 308 | default = None, |
---|
| 309 | source = contextual_reg_num_source, |
---|
[5753] | 310 | ) |
---|
[7376] | 311 | #access_code = schema.TextLine( |
---|
| 312 | # title = u'Activation Code', |
---|
| 313 | # required = False, |
---|
| 314 | # readonly = True, |
---|
| 315 | # ) |
---|
[5753] | 316 | firstname = schema.TextLine( |
---|
| 317 | title = u'First Name', |
---|
[6352] | 318 | required = True, |
---|
[5753] | 319 | ) |
---|
[7356] | 320 | middlename = schema.TextLine( |
---|
| 321 | title = u'Middle Name', |
---|
[5753] | 322 | required = False, |
---|
| 323 | ) |
---|
| 324 | lastname = schema.TextLine( |
---|
[6205] | 325 | title = u'Last Name (Surname)', |
---|
[6352] | 326 | required = True, |
---|
[5753] | 327 | ) |
---|
| 328 | date_of_birth = schema.Date( |
---|
| 329 | title = u'Date of Birth', |
---|
[6352] | 330 | required = True, |
---|
[5753] | 331 | ) |
---|
[6249] | 332 | lga = schema.Choice( |
---|
| 333 | source = lgas_vocab, |
---|
[6205] | 334 | title = u'State/LGA', |
---|
[6254] | 335 | default = 'foreigner', |
---|
| 336 | required = True, |
---|
[5753] | 337 | ) |
---|
| 338 | sex = schema.Choice( |
---|
| 339 | title = u'Sex', |
---|
| 340 | source = GenderSource(), |
---|
| 341 | default = u'm', |
---|
[6352] | 342 | required = True, |
---|
[5753] | 343 | ) |
---|
[6341] | 344 | email = schema.ASCIILine( |
---|
[7555] | 345 | title = u'Email Address', |
---|
[7240] | 346 | required = True, |
---|
[6343] | 347 | constraint=validate_email, |
---|
[5753] | 348 | ) |
---|
[7324] | 349 | phone = schema.TextLine( |
---|
[5753] | 350 | title = u'Phone', |
---|
[7331] | 351 | description = u'', |
---|
[5753] | 352 | required = False, |
---|
| 353 | ) |
---|
[7262] | 354 | course1 = schema.Choice( |
---|
| 355 | title = u'1st Choice Course of Study', |
---|
[7347] | 356 | source = CertificateSource(), |
---|
[7262] | 357 | required = True, |
---|
| 358 | ) |
---|
| 359 | course2 = schema.Choice( |
---|
| 360 | title = u'2nd Choice Course of Study', |
---|
[7347] | 361 | source = CertificateSource(), |
---|
[7262] | 362 | required = False, |
---|
| 363 | ) |
---|
[6322] | 364 | |
---|
[5753] | 365 | # |
---|
[7338] | 366 | # Data to be imported after screening |
---|
[5753] | 367 | # |
---|
[6255] | 368 | screening_score = schema.Int( |
---|
[5753] | 369 | title = u'Screening Score', |
---|
| 370 | required = False, |
---|
| 371 | ) |
---|
| 372 | screening_venue = schema.TextLine( |
---|
| 373 | title = u'Screening Venue', |
---|
| 374 | required = False, |
---|
| 375 | ) |
---|
[6248] | 376 | course_admitted = schema.Choice( |
---|
[5753] | 377 | title = u'Admitted Course of Study', |
---|
[7347] | 378 | source = CertificateSource(), |
---|
[6254] | 379 | default = None, |
---|
[5753] | 380 | required = False, |
---|
| 381 | ) |
---|
[7347] | 382 | notice = schema.Text( |
---|
| 383 | title = u'Notice', |
---|
| 384 | required = False, |
---|
| 385 | ) |
---|
[7338] | 386 | |
---|
| 387 | class IApplicantProcessData(IApplicantBaseData): |
---|
| 388 | """An applicant. |
---|
| 389 | |
---|
| 390 | Here we add process attributes and methods to the base data. |
---|
| 391 | """ |
---|
| 392 | |
---|
| 393 | history = Attribute('Object history, a list of messages.') |
---|
| 394 | state = Attribute('The application state of an applicant') |
---|
[7364] | 395 | display_fullname = Attribute('The fullname of an applicant') |
---|
[7338] | 396 | application_date = Attribute('Date of submission, used for export only') |
---|
| 397 | password = Attribute('Encrypted password of a applicant') |
---|
| 398 | application_number = Attribute('The key under which the record is stored') |
---|
| 399 | |
---|
| 400 | def loggerInfo(ob_class, comment): |
---|
| 401 | """Adds an INFO message to the log file |
---|
| 402 | """ |
---|
| 403 | |
---|
[5753] | 404 | student_id = schema.TextLine( |
---|
[7250] | 405 | title = u'Student Id', |
---|
[5753] | 406 | required = False, |
---|
[7351] | 407 | readonly = False, |
---|
[5753] | 408 | ) |
---|
[6302] | 409 | locked = schema.Bool( |
---|
| 410 | title = u'Form locked', |
---|
| 411 | default = False, |
---|
| 412 | ) |
---|
[5753] | 413 | |
---|
[7338] | 414 | class IApplicant(IApplicantProcessData): |
---|
[5753] | 415 | """An applicant. |
---|
| 416 | |
---|
| 417 | This is basically the applicant base data. Here we repeat the |
---|
[6195] | 418 | fields from base data if we have to set the `required` attribute |
---|
| 419 | to True (which is the default). |
---|
[5753] | 420 | """ |
---|
| 421 | |
---|
[7338] | 422 | class IApplicantEdit(IApplicantProcessData): |
---|
[6195] | 423 | """An applicant. |
---|
[5753] | 424 | |
---|
[6339] | 425 | Here we can repeat the fields from base data and set the |
---|
| 426 | `required` and `readonly` attributes to True to further restrict |
---|
[7262] | 427 | the data access. Or we can allow only certain certificates to be |
---|
| 428 | selected by choosing the appropriate source. |
---|
| 429 | |
---|
| 430 | We cannot omit fields here. This has to be done in the |
---|
[6339] | 431 | respective form page. |
---|
[6195] | 432 | """ |
---|
[7262] | 433 | |
---|
| 434 | course1 = schema.Choice( |
---|
| 435 | title = u'1st Choice Course of Study', |
---|
[7347] | 436 | source = AppCatCertificateSource(), |
---|
[7262] | 437 | required = True, |
---|
| 438 | ) |
---|
| 439 | course2 = schema.Choice( |
---|
| 440 | title = u'2nd Choice Course of Study', |
---|
[7347] | 441 | source = AppCatCertificateSource(), |
---|
[7262] | 442 | required = False, |
---|
| 443 | ) |
---|
[6255] | 444 | screening_score = schema.Int( |
---|
[5753] | 445 | title = u'Screening Score', |
---|
[6195] | 446 | required = False, |
---|
[5941] | 447 | readonly = True, |
---|
| 448 | ) |
---|
[6195] | 449 | screening_venue = schema.TextLine( |
---|
| 450 | title = u'Screening Venue', |
---|
[5753] | 451 | required = False, |
---|
| 452 | readonly = True, |
---|
| 453 | ) |
---|
[6301] | 454 | course_admitted = schema.Choice( |
---|
[6195] | 455 | title = u'Admitted Course of Study', |
---|
[7347] | 456 | source = CertificateSource(), |
---|
[6301] | 457 | default = None, |
---|
[5753] | 458 | required = False, |
---|
[6195] | 459 | readonly = True, |
---|
[5753] | 460 | ) |
---|
[6195] | 461 | notice = schema.Text( |
---|
| 462 | title = u'Notice', |
---|
[5753] | 463 | required = False, |
---|
| 464 | readonly = True, |
---|
| 465 | ) |
---|
[5758] | 466 | |
---|
[7338] | 467 | def createStudent(): |
---|
| 468 | """Create a student object from applicatnt data |
---|
| 469 | and copy applicant object. |
---|
| 470 | """ |
---|
| 471 | |
---|
[7268] | 472 | class IApplicantUpdateByRegNo(IApplicant): |
---|
| 473 | """Representation of an applicant. |
---|
| 474 | |
---|
[7270] | 475 | Skip regular reg_number validation if reg_number is used for finding |
---|
[7268] | 476 | the applicant object. |
---|
| 477 | """ |
---|
[7270] | 478 | reg_number = schema.TextLine( |
---|
[7268] | 479 | title = u'Registration Number', |
---|
| 480 | default = None, |
---|
| 481 | required = False, |
---|
| 482 | ) |
---|
| 483 | |
---|
[7250] | 484 | class IApplicantOnlinePayment(IOnlinePayment): |
---|
| 485 | """An applicant payment via payment gateways. |
---|
| 486 | |
---|
| 487 | """ |
---|
| 488 | p_year = schema.Choice( |
---|
| 489 | title = u'Payment Session', |
---|
| 490 | source = academic_sessions_vocab, |
---|
| 491 | required = False, |
---|
| 492 | ) |
---|
| 493 | |
---|
| 494 | IApplicantOnlinePayment['p_year'].order = IApplicantOnlinePayment[ |
---|
| 495 | 'p_year'].order |
---|
| 496 | |
---|
[5846] | 497 | class IApplicantsContainerProvider(Interface): |
---|
[5820] | 498 | """A provider for applicants containers. |
---|
| 499 | |
---|
| 500 | Applicants container providers are meant to be looked up as |
---|
| 501 | utilities. This way we can find all applicant container types |
---|
| 502 | defined somewhere. |
---|
| 503 | |
---|
| 504 | Each applicants container provider registered as utility provides |
---|
| 505 | one container type and one should be able to call the `factory` |
---|
| 506 | attribute to create an instance of the requested container type. |
---|
| 507 | |
---|
| 508 | .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested) |
---|
[6076] | 509 | |
---|
[6500] | 510 | Samples: |
---|
[6076] | 511 | |
---|
[5820] | 512 | Given, you had an IApplicantsContainer implementation somewhere |
---|
| 513 | and you would like to make it findable on request, then you would |
---|
| 514 | normally create an appropriate provider utility like this:: |
---|
| 515 | |
---|
| 516 | import grok |
---|
[5846] | 517 | from waeup.sirp.applicants.interfaces import IApplicantsContainerProvider |
---|
[5820] | 518 | |
---|
| 519 | class MyContainerProvider(grok.GlobalUtility): |
---|
[5846] | 520 | grok.implements(IApplicantsContainerProvider) |
---|
[5820] | 521 | grok.name('MyContainerProvider') # Must be unique |
---|
| 522 | factory = MyContainer # A class implementing IApplicantsContainer |
---|
| 523 | # or derivations thereof. |
---|
| 524 | |
---|
| 525 | This utility would be registered on startup and could then be used |
---|
| 526 | like this: |
---|
| 527 | |
---|
| 528 | >>> from zope.component import getAllUtilitiesRegisteredFor |
---|
| 529 | >>> from waeup.sirp.applicants.interfaces import ( |
---|
[5846] | 530 | ... IApplicantsContainerProvider) |
---|
[5820] | 531 | >>> all_providers = getAllUtilitiesRegisteredFor( |
---|
[5846] | 532 | ... IApplicantsContainerProvider) |
---|
[5820] | 533 | >>> all_providers |
---|
| 534 | [<MyContainerProvider object at 0x...>] |
---|
| 535 | |
---|
| 536 | You could look up this specific provider by name: |
---|
| 537 | |
---|
| 538 | >>> from zope.component import getUtility |
---|
[5846] | 539 | >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider') |
---|
[5820] | 540 | >>> p |
---|
| 541 | <MyContainerProvider object at 0x...> |
---|
[6076] | 542 | |
---|
[5820] | 543 | An applicants container would then be created like this: |
---|
| 544 | |
---|
| 545 | >>> provider = all_providers[0] |
---|
| 546 | >>> container = provider.factory() |
---|
| 547 | >>> container |
---|
| 548 | <MyContainer object at 0x...> |
---|
| 549 | |
---|
| 550 | """ |
---|
| 551 | factory = Attribute("A class that can create instances of the " |
---|
| 552 | "requested container type") |
---|