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