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