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