[5638] | 1 | ## $Id: interfaces.py 7268 2011-12-04 17:40:41Z 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 |
---|
| 27 | from zope.schema.interfaces import ValidationError, ISource, IContextSourceBinder |
---|
[6256] | 28 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[7263] | 29 | from waeup.sirp.schema import TextLineChoice |
---|
[7250] | 30 | from waeup.sirp.interfaces import ( |
---|
| 31 | IWAeUPObject, year_range, validate_email, academic_sessions_vocab) |
---|
[6189] | 32 | from waeup.sirp.university.vocabularies import application_categories |
---|
[6648] | 33 | from waeup.sirp.students.vocabularies import ( |
---|
[6915] | 34 | lgas_vocab, CertificateSource, GenderSource, |
---|
[6648] | 35 | ) |
---|
[6256] | 36 | from waeup.sirp.applicants.vocabularies import ( |
---|
[6648] | 37 | application_types_vocab, application_pins_vocab, |
---|
| 38 | AppCatCertificateSource, |
---|
[6256] | 39 | ) |
---|
[7250] | 40 | from waeup.sirp.payments.interfaces import IOnlinePayment |
---|
[5638] | 41 | |
---|
[7075] | 42 | #: Maximum upload size for applicant passport photographs (in bytes) |
---|
[7086] | 43 | MAX_UPLOAD_SIZE = 1024 * 20 |
---|
[7075] | 44 | |
---|
[7263] | 45 | class RegNumInSource(ValidationError): |
---|
| 46 | """Registration number exists already |
---|
| 47 | """ |
---|
| 48 | # The docstring of ValidationErrors is used as error description |
---|
| 49 | # by zope.formlib. |
---|
| 50 | pass |
---|
| 51 | |
---|
| 52 | class RegNumberSource(object): |
---|
| 53 | implements(ISource) |
---|
| 54 | cat_name = 'applicants_catalog' |
---|
| 55 | field_name = 'reg_no' |
---|
| 56 | validation_error = RegNumInSource |
---|
| 57 | def __init__(self, context): |
---|
| 58 | self.context = context |
---|
| 59 | return |
---|
| 60 | |
---|
| 61 | def __contains__(self, value): |
---|
| 62 | cat = queryUtility(ICatalog, self.cat_name) |
---|
| 63 | if cat is None: |
---|
| 64 | return True |
---|
| 65 | kw = {self.field_name: (value, value)} |
---|
| 66 | results = cat.searchResults(**kw) |
---|
| 67 | for entry in results: |
---|
| 68 | if entry.applicant_id != self.context.applicant_id: |
---|
| 69 | # XXX: sources should simply return False. |
---|
| 70 | # But then we get some stupid error message in forms |
---|
| 71 | # when validation fails. |
---|
| 72 | raise self.validation_error(value) |
---|
| 73 | #return False |
---|
| 74 | return True |
---|
| 75 | |
---|
| 76 | def contextual_reg_num_source(context): |
---|
| 77 | source = RegNumberSource(context) |
---|
| 78 | return source |
---|
| 79 | directlyProvides(contextual_reg_num_source, IContextSourceBinder) |
---|
| 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 | |
---|
[5866] | 119 | class IApplicantsRoot(IWAeUPObject, IContainer): |
---|
[5676] | 120 | """A container for university applicants containers. |
---|
[5645] | 121 | """ |
---|
[5866] | 122 | pass |
---|
[5638] | 123 | |
---|
[5676] | 124 | class IApplicantsContainer(IWAeUPObject): |
---|
| 125 | """An applicants container contains university applicants. |
---|
[5645] | 126 | |
---|
[5638] | 127 | """ |
---|
[6069] | 128 | |
---|
[6075] | 129 | container_title = Attribute( |
---|
| 130 | u'classattribute: title for type of container') |
---|
| 131 | container_description = Attribute( |
---|
| 132 | u'classattribute: description for type of container') |
---|
| 133 | |
---|
[6076] | 134 | |
---|
[6069] | 135 | code = schema.TextLine( |
---|
| 136 | title = u'Code', |
---|
[6087] | 137 | default = u'-', |
---|
[6069] | 138 | required = True, |
---|
| 139 | readonly = True, |
---|
[6076] | 140 | ) |
---|
[6096] | 141 | |
---|
[6087] | 142 | title = schema.TextLine( |
---|
| 143 | title = u'Title', |
---|
| 144 | required = True, |
---|
| 145 | default = u'-', |
---|
| 146 | readonly = True, |
---|
[6096] | 147 | ) |
---|
| 148 | |
---|
[6087] | 149 | prefix = schema.Choice( |
---|
| 150 | title = u'Application target', |
---|
| 151 | required = True, |
---|
| 152 | default = None, |
---|
| 153 | source = application_types_vocab, |
---|
| 154 | readonly = True, |
---|
| 155 | ) |
---|
[6076] | 156 | |
---|
[6087] | 157 | year = schema.Choice( |
---|
| 158 | title = u'Year of entrance', |
---|
| 159 | required = True, |
---|
| 160 | default = None, |
---|
[6158] | 161 | values = year_range(), |
---|
[6087] | 162 | readonly = True, |
---|
[6096] | 163 | ) |
---|
[6087] | 164 | |
---|
[6069] | 165 | provider = schema.Choice( |
---|
[6070] | 166 | title = u'Applicants container type', |
---|
[6069] | 167 | required = True, |
---|
| 168 | default = None, |
---|
| 169 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 170 | readonly = True, |
---|
[6076] | 171 | ) |
---|
[6158] | 172 | |
---|
[6110] | 173 | ac_prefix = schema.Choice( |
---|
| 174 | title = u'Access code prefix', |
---|
| 175 | required = True, |
---|
| 176 | default = None, |
---|
[6111] | 177 | source = application_pins_vocab, |
---|
[6110] | 178 | ) |
---|
[6076] | 179 | |
---|
[6189] | 180 | application_category = schema.Choice( |
---|
[6477] | 181 | title = u'Category for the grouping of certificates', |
---|
[6189] | 182 | required = True, |
---|
| 183 | default = None, |
---|
| 184 | source = application_categories, |
---|
| 185 | ) |
---|
| 186 | |
---|
[5645] | 187 | description = schema.Text( |
---|
| 188 | title = u'Human readable description in reST format', |
---|
[5638] | 189 | required = False, |
---|
[6518] | 190 | default = u'''This text can been seen by anonymous users. |
---|
| 191 | Here we put information about the study courses provided, the application procedure and deadlines.''' |
---|
[5638] | 192 | ) |
---|
| 193 | |
---|
| 194 | startdate = schema.Date( |
---|
[6509] | 195 | title = u'Application start date', |
---|
[5638] | 196 | required = False, |
---|
| 197 | default = None, |
---|
| 198 | ) |
---|
| 199 | |
---|
| 200 | enddate = schema.Date( |
---|
[6509] | 201 | title = u'Application closing date', |
---|
[5638] | 202 | required = False, |
---|
| 203 | default = None, |
---|
| 204 | ) |
---|
| 205 | |
---|
[5645] | 206 | strict_deadline = schema.Bool( |
---|
| 207 | title = u'Forbid additions after deadline (enddate)', |
---|
| 208 | required = True, |
---|
| 209 | default = True, |
---|
| 210 | ) |
---|
[5638] | 211 | |
---|
| 212 | def archive(id=None): |
---|
[5676] | 213 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 214 | |
---|
[5676] | 215 | If id is `None`, all applicants are archived. |
---|
[5638] | 216 | |
---|
| 217 | If id contains a single id string, only the respective |
---|
[5676] | 218 | applicants are archived. |
---|
[5638] | 219 | |
---|
| 220 | If id contains a list of id strings all of the respective |
---|
[5676] | 221 | applicants types are saved to disk. |
---|
[5638] | 222 | """ |
---|
| 223 | |
---|
| 224 | def clear(id=None, archive=True): |
---|
[5676] | 225 | """Remove applicants of type given by 'id'. |
---|
[5638] | 226 | |
---|
[5676] | 227 | Optionally archive the applicants. |
---|
[6076] | 228 | |
---|
[5676] | 229 | If id is `None`, all applicants are archived. |
---|
[5638] | 230 | |
---|
| 231 | If id contains a single id string, only the respective |
---|
[5676] | 232 | applicants are archived. |
---|
[5638] | 233 | |
---|
| 234 | If id contains a list of id strings all of the respective |
---|
[5676] | 235 | applicant types are saved to disk. |
---|
[5638] | 236 | |
---|
| 237 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 238 | and respective applicants are simply removed from the |
---|
[5638] | 239 | database. |
---|
| 240 | """ |
---|
[6073] | 241 | |
---|
[6069] | 242 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 243 | """An applicants container contains university applicants. |
---|
| 244 | """ |
---|
[6087] | 245 | prefix = schema.Choice( |
---|
| 246 | title = u'Application target', |
---|
[6069] | 247 | required = True, |
---|
[6087] | 248 | default = None, |
---|
| 249 | source = application_types_vocab, |
---|
[6069] | 250 | readonly = False, |
---|
[6076] | 251 | ) |
---|
[6073] | 252 | |
---|
[6087] | 253 | year = schema.Choice( |
---|
| 254 | title = u'Year of entrance', |
---|
| 255 | required = True, |
---|
| 256 | default = None, |
---|
[6158] | 257 | values = year_range(), |
---|
[6087] | 258 | readonly = False, |
---|
[6096] | 259 | ) |
---|
[6073] | 260 | |
---|
[6087] | 261 | provider = schema.Choice( |
---|
| 262 | title = u'Applicants container type', |
---|
| 263 | required = True, |
---|
| 264 | default = None, |
---|
| 265 | source = ApplicantContainerProviderSource(), |
---|
| 266 | readonly = False, |
---|
| 267 | ) |
---|
| 268 | |
---|
[6096] | 269 | IApplicantsContainerAdd[ |
---|
| 270 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 271 | IApplicantsContainerAdd[ |
---|
| 272 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 273 | IApplicantsContainerAdd[ |
---|
| 274 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 275 | |
---|
[5753] | 276 | class IApplicantBaseData(IWAeUPObject): |
---|
| 277 | """The data for an applicant. |
---|
| 278 | |
---|
[7240] | 279 | This is a base interface with no field |
---|
[5753] | 280 | required. For use with importers, forms, etc., please use one of |
---|
| 281 | the derived interfaces below, which set more fields to required |
---|
| 282 | state, depending on use-case. |
---|
| 283 | """ |
---|
[6339] | 284 | history = Attribute('Object history, a list of messages.') |
---|
[7240] | 285 | state = Attribute('The application state of an applicant') |
---|
| 286 | fullname = Attribute('The fullname of an applicant') |
---|
[6476] | 287 | application_date = Attribute('Date of submission, used for export only') |
---|
[7240] | 288 | password = Attribute('Encrypted password of a applicant') |
---|
| 289 | application_number = Attribute('The key under which the record is stored') |
---|
[6304] | 290 | |
---|
[6476] | 291 | def loggerInfo(ob_class, comment): |
---|
| 292 | """Adds an INFO message to the log file |
---|
[6348] | 293 | """ |
---|
| 294 | |
---|
[7240] | 295 | applicant_id = schema.TextLine( |
---|
| 296 | title = u'Applicant Id', |
---|
| 297 | required = False, |
---|
[7260] | 298 | readonly = False, |
---|
[7240] | 299 | ) |
---|
[7263] | 300 | reg_no = TextLineChoice( |
---|
[5753] | 301 | title = u'JAMB Registration Number', |
---|
[7263] | 302 | readonly = False, |
---|
| 303 | required = True, |
---|
| 304 | default = None, |
---|
| 305 | source = contextual_reg_num_source, |
---|
[5753] | 306 | ) |
---|
| 307 | access_code = schema.TextLine( |
---|
| 308 | title = u'Access Code', |
---|
| 309 | required = False, |
---|
[6195] | 310 | readonly = True, |
---|
[5753] | 311 | ) |
---|
| 312 | firstname = schema.TextLine( |
---|
| 313 | title = u'First Name', |
---|
[6352] | 314 | required = True, |
---|
[5753] | 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)', |
---|
[6352] | 322 | required = True, |
---|
[5753] | 323 | ) |
---|
| 324 | date_of_birth = schema.Date( |
---|
| 325 | title = u'Date of Birth', |
---|
[6352] | 326 | required = True, |
---|
[5753] | 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', |
---|
[6352] | 338 | required = True, |
---|
[5753] | 339 | ) |
---|
[6341] | 340 | email = schema.ASCIILine( |
---|
[5753] | 341 | title = u'Email', |
---|
[7240] | 342 | required = True, |
---|
[6343] | 343 | constraint=validate_email, |
---|
[5753] | 344 | ) |
---|
[6341] | 345 | phone = schema.Int( |
---|
[5753] | 346 | title = u'Phone', |
---|
[6341] | 347 | description = u'Enter phone number with country code and without spaces.', |
---|
[5753] | 348 | required = False, |
---|
| 349 | ) |
---|
[7262] | 350 | course1 = schema.Choice( |
---|
| 351 | title = u'1st Choice Course of Study', |
---|
| 352 | source = CertificateSource(), |
---|
| 353 | required = True, |
---|
| 354 | ) |
---|
| 355 | course2 = schema.Choice( |
---|
| 356 | title = u'2nd Choice Course of Study', |
---|
| 357 | source = CertificateSource(), |
---|
| 358 | required = False, |
---|
| 359 | ) |
---|
[6322] | 360 | |
---|
[5753] | 361 | # |
---|
[6195] | 362 | # Process Data |
---|
[5753] | 363 | # |
---|
[6255] | 364 | screening_score = schema.Int( |
---|
[5753] | 365 | title = u'Screening Score', |
---|
| 366 | required = False, |
---|
| 367 | ) |
---|
| 368 | screening_venue = schema.TextLine( |
---|
| 369 | title = u'Screening Venue', |
---|
| 370 | required = False, |
---|
| 371 | ) |
---|
[6248] | 372 | course_admitted = schema.Choice( |
---|
[5753] | 373 | title = u'Admitted Course of Study', |
---|
[6248] | 374 | source = CertificateSource(), |
---|
[6254] | 375 | default = None, |
---|
[5753] | 376 | required = False, |
---|
| 377 | ) |
---|
| 378 | notice = schema.Text( |
---|
| 379 | title = u'Notice', |
---|
| 380 | required = False, |
---|
| 381 | ) |
---|
| 382 | student_id = schema.TextLine( |
---|
[7250] | 383 | title = u'Student Id', |
---|
[5753] | 384 | required = False, |
---|
[6195] | 385 | readonly = True, |
---|
[5753] | 386 | ) |
---|
[6302] | 387 | locked = schema.Bool( |
---|
| 388 | title = u'Form locked', |
---|
| 389 | default = False, |
---|
| 390 | ) |
---|
[5753] | 391 | |
---|
| 392 | class IApplicant(IApplicantBaseData): |
---|
| 393 | """An applicant. |
---|
| 394 | |
---|
| 395 | This is basically the applicant base data. Here we repeat the |
---|
[6195] | 396 | fields from base data if we have to set the `required` attribute |
---|
| 397 | to True (which is the default). |
---|
[5753] | 398 | """ |
---|
| 399 | |
---|
[6195] | 400 | class IApplicantEdit(IApplicantBaseData): |
---|
| 401 | """An applicant. |
---|
[5753] | 402 | |
---|
[6339] | 403 | Here we can repeat the fields from base data and set the |
---|
| 404 | `required` and `readonly` attributes to True to further restrict |
---|
[7262] | 405 | the data access. Or we can allow only certain certificates to be |
---|
| 406 | selected by choosing the appropriate source. |
---|
| 407 | |
---|
| 408 | We cannot omit fields here. This has to be done in the |
---|
[6339] | 409 | respective form page. |
---|
[6195] | 410 | """ |
---|
[7262] | 411 | |
---|
| 412 | course1 = schema.Choice( |
---|
| 413 | title = u'1st Choice Course of Study', |
---|
| 414 | source = AppCatCertificateSource(), |
---|
| 415 | required = True, |
---|
| 416 | ) |
---|
| 417 | course2 = schema.Choice( |
---|
| 418 | title = u'2nd Choice Course of Study', |
---|
| 419 | source = AppCatCertificateSource(), |
---|
| 420 | required = False, |
---|
| 421 | ) |
---|
[6255] | 422 | screening_score = schema.Int( |
---|
[5753] | 423 | title = u'Screening Score', |
---|
[6195] | 424 | required = False, |
---|
[5941] | 425 | readonly = True, |
---|
| 426 | ) |
---|
[6195] | 427 | screening_venue = schema.TextLine( |
---|
| 428 | title = u'Screening Venue', |
---|
[5753] | 429 | required = False, |
---|
| 430 | readonly = True, |
---|
| 431 | ) |
---|
[6301] | 432 | course_admitted = schema.Choice( |
---|
[6195] | 433 | title = u'Admitted Course of Study', |
---|
[6301] | 434 | source = CertificateSource(), |
---|
| 435 | default = None, |
---|
[5753] | 436 | required = False, |
---|
[6195] | 437 | readonly = True, |
---|
[5753] | 438 | ) |
---|
[6195] | 439 | notice = schema.Text( |
---|
| 440 | title = u'Notice', |
---|
[5753] | 441 | required = False, |
---|
| 442 | readonly = True, |
---|
| 443 | ) |
---|
[5758] | 444 | |
---|
[7268] | 445 | class IApplicantUpdateByRegNo(IApplicant): |
---|
| 446 | """Representation of an applicant. |
---|
| 447 | |
---|
| 448 | Skip regular reg_no validation if reg_no is used for finding |
---|
| 449 | the applicant object. |
---|
| 450 | """ |
---|
| 451 | reg_no = schema.TextLine( |
---|
| 452 | title = u'Registration Number', |
---|
| 453 | default = None, |
---|
| 454 | required = False, |
---|
| 455 | ) |
---|
| 456 | |
---|
[7250] | 457 | class IApplicantOnlinePayment(IOnlinePayment): |
---|
| 458 | """An applicant payment via payment gateways. |
---|
| 459 | |
---|
| 460 | """ |
---|
| 461 | p_year = schema.Choice( |
---|
| 462 | title = u'Payment Session', |
---|
| 463 | source = academic_sessions_vocab, |
---|
| 464 | required = False, |
---|
| 465 | ) |
---|
| 466 | |
---|
| 467 | IApplicantOnlinePayment['p_year'].order = IApplicantOnlinePayment[ |
---|
| 468 | 'p_year'].order |
---|
| 469 | |
---|
[5846] | 470 | class IApplicantsContainerProvider(Interface): |
---|
[5820] | 471 | """A provider for applicants containers. |
---|
| 472 | |
---|
| 473 | Applicants container providers are meant to be looked up as |
---|
| 474 | utilities. This way we can find all applicant container types |
---|
| 475 | defined somewhere. |
---|
| 476 | |
---|
| 477 | Each applicants container provider registered as utility provides |
---|
| 478 | one container type and one should be able to call the `factory` |
---|
| 479 | attribute to create an instance of the requested container type. |
---|
| 480 | |
---|
| 481 | .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested) |
---|
[6076] | 482 | |
---|
[6500] | 483 | Samples: |
---|
[6076] | 484 | |
---|
[5820] | 485 | Given, you had an IApplicantsContainer implementation somewhere |
---|
| 486 | and you would like to make it findable on request, then you would |
---|
| 487 | normally create an appropriate provider utility like this:: |
---|
| 488 | |
---|
| 489 | import grok |
---|
[5846] | 490 | from waeup.sirp.applicants.interfaces import IApplicantsContainerProvider |
---|
[5820] | 491 | |
---|
| 492 | class MyContainerProvider(grok.GlobalUtility): |
---|
[5846] | 493 | grok.implements(IApplicantsContainerProvider) |
---|
[5820] | 494 | grok.name('MyContainerProvider') # Must be unique |
---|
| 495 | factory = MyContainer # A class implementing IApplicantsContainer |
---|
| 496 | # or derivations thereof. |
---|
| 497 | |
---|
| 498 | This utility would be registered on startup and could then be used |
---|
| 499 | like this: |
---|
| 500 | |
---|
| 501 | >>> from zope.component import getAllUtilitiesRegisteredFor |
---|
| 502 | >>> from waeup.sirp.applicants.interfaces import ( |
---|
[5846] | 503 | ... IApplicantsContainerProvider) |
---|
[5820] | 504 | >>> all_providers = getAllUtilitiesRegisteredFor( |
---|
[5846] | 505 | ... IApplicantsContainerProvider) |
---|
[5820] | 506 | >>> all_providers |
---|
| 507 | [<MyContainerProvider object at 0x...>] |
---|
| 508 | |
---|
| 509 | You could look up this specific provider by name: |
---|
| 510 | |
---|
| 511 | >>> from zope.component import getUtility |
---|
[5846] | 512 | >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider') |
---|
[5820] | 513 | >>> p |
---|
| 514 | <MyContainerProvider object at 0x...> |
---|
[6076] | 515 | |
---|
[5820] | 516 | An applicants container would then be created like this: |
---|
| 517 | |
---|
| 518 | >>> provider = all_providers[0] |
---|
| 519 | >>> container = provider.factory() |
---|
| 520 | >>> container |
---|
| 521 | <MyContainer object at 0x...> |
---|
| 522 | |
---|
| 523 | """ |
---|
| 524 | factory = Attribute("A class that can create instances of the " |
---|
| 525 | "requested container type") |
---|