[5638] | 1 | ## $Id: interfaces.py 7770 2012-03-07 08:28:34Z uli $ |
---|
[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 |
---|
[7683] | 25 | from zope.component import getUtilitiesFor, queryUtility, getUtility |
---|
[7263] | 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 |
---|
[7683] | 30 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[7263] | 31 | from waeup.sirp.schema import TextLineChoice |
---|
[7250] | 32 | from waeup.sirp.interfaces import ( |
---|
[7321] | 33 | ISIRPObject, year_range, validate_email, academic_sessions_vocab) |
---|
[7708] | 34 | from waeup.sirp.interfaces import MessageFactory as _ |
---|
[7436] | 35 | from waeup.sirp.university.vocabularies import ( |
---|
[7681] | 36 | course_levels, AppCatSource) |
---|
[7347] | 37 | from waeup.sirp.students.vocabularies import ( |
---|
[7436] | 38 | lgas_vocab, CertificateSource, GenderSource) |
---|
[7250] | 39 | from waeup.sirp.payments.interfaces import IOnlinePayment |
---|
[7770] | 40 | from waeup.sirp.schema import MultiValObject |
---|
[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' |
---|
[7270] | 55 | field_name = 'reg_number' |
---|
[7263] | 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 | |
---|
[7761] | 81 | SUBJECTS = dict(math=_(u'Math'), |
---|
| 82 | bio=_(u'Biology'), |
---|
| 83 | eng=_(u'English'), |
---|
| 84 | ) |
---|
| 85 | class SubjectSource(BasicSourceFactory): |
---|
| 86 | def getValues(self): |
---|
| 87 | return sorted(SUBJECTS.keys()) |
---|
| 88 | def getTitle(self, value): |
---|
| 89 | return SUBJECTS.get(value, None) |
---|
| 90 | |
---|
| 91 | GRADES = {'A':_(u'Very Good'), |
---|
| 92 | 'B':_(u'Good'), |
---|
| 93 | 'C':_(u'Satisfactory'), |
---|
| 94 | 'D':_(u'Sufficient'), |
---|
| 95 | 'E':_(u'Fail'), |
---|
| 96 | } |
---|
| 97 | class GradeSource(BasicSourceFactory): |
---|
| 98 | def getValues(self): |
---|
| 99 | return sorted(GRADES.keys()) |
---|
| 100 | def getTitle(self, value): |
---|
| 101 | return GRADES.get(value, None) |
---|
| 102 | |
---|
[7683] | 103 | class AppCatCertificateSource(CertificateSource): |
---|
| 104 | """An application certificate source delivers all courses which belong to |
---|
| 105 | a certain application_category. |
---|
| 106 | """ |
---|
| 107 | def getValues(self, context): |
---|
| 108 | # appliction category not available when certificate was deleted. |
---|
| 109 | # shouldn't that info be part of applicant info instead? |
---|
| 110 | # when we cannot determine the appcat, we will display all courses. |
---|
| 111 | appcat = getattr(getattr(context, '__parent__', None), |
---|
| 112 | 'application_category', None) |
---|
| 113 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 114 | result = catalog.searchResults( |
---|
| 115 | application_category=(appcat,appcat)) |
---|
| 116 | result = sorted(result, key=lambda value: value.code) |
---|
| 117 | curr_course = context.course1 |
---|
| 118 | if curr_course is not None and curr_course not in result: |
---|
| 119 | # display also current course even if it is not catalogued |
---|
| 120 | # (any more) |
---|
| 121 | result = [curr_course,] + result |
---|
| 122 | return result |
---|
| 123 | |
---|
| 124 | class ApplicationTypeSource(BasicContextualSourceFactory): |
---|
| 125 | """An application type source delivers screening types defined in the |
---|
| 126 | portal. |
---|
| 127 | """ |
---|
| 128 | def getValues(self, context): |
---|
[7688] | 129 | appcats_dict = getUtility( |
---|
[7683] | 130 | IApplicantsUtils).getApplicationTypeDict() |
---|
[7688] | 131 | return sorted(appcats_dict.keys()) |
---|
[7683] | 132 | |
---|
| 133 | def getToken(self, context, value): |
---|
| 134 | return value |
---|
| 135 | |
---|
| 136 | def getTitle(self, context, value): |
---|
[7688] | 137 | appcats_dict = getUtility( |
---|
| 138 | IApplicantsUtils).getApplicationTypeDict() |
---|
| 139 | return appcats_dict[value][0] |
---|
[7683] | 140 | |
---|
| 141 | # Maybe Uniben still needs this ... |
---|
| 142 | #class ApplicationPinSource(BasicContextualSourceFactory): |
---|
| 143 | # """An application pin source delivers PIN prefixes for application |
---|
| 144 | # defined in the portal. |
---|
| 145 | # """ |
---|
| 146 | # def getValues(self, context): |
---|
[7688] | 147 | # apppins_dict = getUtility( |
---|
[7683] | 148 | # IApplicantsUtils).getApplicationTypeDict() |
---|
[7688] | 149 | # return sorted(appcats_dict.keys()) |
---|
[7683] | 150 | # |
---|
| 151 | # def getToken(self, context, value): |
---|
| 152 | # return value |
---|
| 153 | # |
---|
| 154 | # def getTitle(self, context, value): |
---|
[7688] | 155 | # apppins_dict = getUtility( |
---|
| 156 | # IApplicantsUtils).getApplicationTypeDict() |
---|
[7683] | 157 | # return u"%s (%s)" % ( |
---|
[7688] | 158 | # apppins_dict[value][1],self.apppins_dict[value][0]) |
---|
[7683] | 159 | |
---|
[6069] | 160 | class ApplicantContainerProviderSource(BasicSourceFactory): |
---|
[6075] | 161 | """A source offering all available applicants container types. |
---|
| 162 | |
---|
| 163 | The values returned by this source are names of utilities that can |
---|
| 164 | create :class:`ApplicantContainer` instances. So, if you get a |
---|
| 165 | name like ``'myactype'`` from this source, then you can do: |
---|
| 166 | |
---|
| 167 | >>> from zope.component import getUtility |
---|
| 168 | >>> p = getUtility(IApplicantsContainerProvider, name=myactype) |
---|
| 169 | >>> my_applicants_container = p.factory() |
---|
| 170 | |
---|
| 171 | Or you can access class-attributes like |
---|
| 172 | |
---|
| 173 | >>> my_applicants_container.container_title |
---|
| 174 | 'Pretty' |
---|
[6076] | 175 | |
---|
[6069] | 176 | """ |
---|
| 177 | def getValues(self): |
---|
[6075] | 178 | """Returns a list of ``(<name>, <provider>)`` tuples. |
---|
[5753] | 179 | |
---|
[6075] | 180 | Here ``<name>`` is the name under which an |
---|
| 181 | :class:``ApplicantContainerProvider`` was registered as a |
---|
| 182 | utility and ``<provider>`` is the utility itself. |
---|
| 183 | """ |
---|
| 184 | return getUtilitiesFor(IApplicantsContainerProvider) |
---|
| 185 | |
---|
[6069] | 186 | def getToken(self, value): |
---|
[6075] | 187 | """Return the name of the ``(<name>, <provider>)`` tuple. |
---|
| 188 | """ |
---|
| 189 | return value[0] |
---|
| 190 | |
---|
[6069] | 191 | def getTitle(self, value): |
---|
[6075] | 192 | """Get a 'title - description' string for a container type. |
---|
| 193 | """ |
---|
| 194 | factory = value[1].factory |
---|
| 195 | return "%s - %s" % ( |
---|
| 196 | factory.container_title, factory.container_description) |
---|
[6069] | 197 | |
---|
[7682] | 198 | class IApplicantsUtils(Interface): |
---|
| 199 | """A collection of methods which are subject to customization. |
---|
| 200 | """ |
---|
[7683] | 201 | pass |
---|
[7682] | 202 | |
---|
[7321] | 203 | class IApplicantsRoot(ISIRPObject, IContainer): |
---|
[5676] | 204 | """A container for university applicants containers. |
---|
[5645] | 205 | """ |
---|
[5866] | 206 | pass |
---|
[5638] | 207 | |
---|
[7321] | 208 | class IApplicantsContainer(ISIRPObject): |
---|
[5676] | 209 | """An applicants container contains university applicants. |
---|
[5645] | 210 | |
---|
[5638] | 211 | """ |
---|
[6069] | 212 | |
---|
[6075] | 213 | container_title = Attribute( |
---|
| 214 | u'classattribute: title for type of container') |
---|
| 215 | container_description = Attribute( |
---|
| 216 | u'classattribute: description for type of container') |
---|
| 217 | |
---|
[6076] | 218 | |
---|
[6069] | 219 | code = schema.TextLine( |
---|
[7708] | 220 | title = _(u'Code'), |
---|
[6087] | 221 | default = u'-', |
---|
[6069] | 222 | required = True, |
---|
| 223 | readonly = True, |
---|
[6076] | 224 | ) |
---|
[6096] | 225 | |
---|
[6087] | 226 | title = schema.TextLine( |
---|
[7708] | 227 | title = _(u'Title'), |
---|
[6087] | 228 | required = True, |
---|
| 229 | default = u'-', |
---|
| 230 | readonly = True, |
---|
[6096] | 231 | ) |
---|
| 232 | |
---|
[6087] | 233 | prefix = schema.Choice( |
---|
[7708] | 234 | title = _(u'Application Target'), |
---|
[6087] | 235 | required = True, |
---|
| 236 | default = None, |
---|
[7683] | 237 | source = ApplicationTypeSource(), |
---|
[6087] | 238 | readonly = True, |
---|
| 239 | ) |
---|
[6076] | 240 | |
---|
[7436] | 241 | entry_level = schema.Choice( |
---|
[7708] | 242 | title = _(u'Entry Level'), |
---|
[7436] | 243 | vocabulary = course_levels, |
---|
| 244 | default = 100, |
---|
| 245 | required = True, |
---|
| 246 | ) |
---|
| 247 | |
---|
[6087] | 248 | year = schema.Choice( |
---|
[7708] | 249 | title = _(u'Year of Entrance'), |
---|
[6087] | 250 | required = True, |
---|
| 251 | default = None, |
---|
[6158] | 252 | values = year_range(), |
---|
[6087] | 253 | readonly = True, |
---|
[6096] | 254 | ) |
---|
[6087] | 255 | |
---|
[6069] | 256 | provider = schema.Choice( |
---|
[7708] | 257 | title = _(u'Applicants Container Type'), |
---|
[6069] | 258 | required = True, |
---|
| 259 | default = None, |
---|
| 260 | source = ApplicantContainerProviderSource(), |
---|
[6087] | 261 | readonly = True, |
---|
[6076] | 262 | ) |
---|
[6158] | 263 | |
---|
[7683] | 264 | # Maybe Uniben still needs this ... |
---|
[7376] | 265 | #ac_prefix = schema.Choice( |
---|
| 266 | # title = u'Activation code prefix', |
---|
| 267 | # required = True, |
---|
| 268 | # default = None, |
---|
[7683] | 269 | # source = ApplicationPinSource(), |
---|
[7376] | 270 | # ) |
---|
[6076] | 271 | |
---|
[6189] | 272 | application_category = schema.Choice( |
---|
[7708] | 273 | title = _(u'Category for the grouping of certificates'), |
---|
[6189] | 274 | required = True, |
---|
| 275 | default = None, |
---|
[7681] | 276 | source = AppCatSource(), |
---|
[6189] | 277 | ) |
---|
| 278 | |
---|
[5645] | 279 | description = schema.Text( |
---|
[7708] | 280 | title = _(u'Human readable description in reST format'), |
---|
[5638] | 281 | required = False, |
---|
[6518] | 282 | default = u'''This text can been seen by anonymous users. |
---|
[7708] | 283 | Here we put mult-lingual information about the study courses provided, the application procedure and deadlines. |
---|
| 284 | >>de<< |
---|
| 285 | Dieser Text kann von anonymen Benutzern gelesen werden. |
---|
| 286 | Hier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.''' |
---|
[5638] | 287 | ) |
---|
| 288 | |
---|
[7708] | 289 | description_dict = schema.Dict( |
---|
| 290 | title = u'Content as language dictionary with values in html format', |
---|
| 291 | required = False, |
---|
| 292 | default = {}, |
---|
| 293 | ) |
---|
| 294 | |
---|
[5638] | 295 | startdate = schema.Date( |
---|
[7708] | 296 | title = _(u'Application Start Date'), |
---|
[5638] | 297 | required = False, |
---|
| 298 | default = None, |
---|
| 299 | ) |
---|
| 300 | |
---|
| 301 | enddate = schema.Date( |
---|
[7708] | 302 | title = _(u'Application Closing Date'), |
---|
[5638] | 303 | required = False, |
---|
| 304 | default = None, |
---|
| 305 | ) |
---|
| 306 | |
---|
[5645] | 307 | strict_deadline = schema.Bool( |
---|
[7708] | 308 | title = _(u'Forbid additions after deadline (enddate)'), |
---|
[5645] | 309 | required = True, |
---|
| 310 | default = True, |
---|
| 311 | ) |
---|
[5638] | 312 | |
---|
| 313 | def archive(id=None): |
---|
[5676] | 314 | """Create on-dist archive of applicants stored in this term. |
---|
[5638] | 315 | |
---|
[5676] | 316 | If id is `None`, all applicants are archived. |
---|
[5638] | 317 | |
---|
| 318 | If id contains a single id string, only the respective |
---|
[5676] | 319 | applicants are archived. |
---|
[5638] | 320 | |
---|
| 321 | If id contains a list of id strings all of the respective |
---|
[5676] | 322 | applicants types are saved to disk. |
---|
[5638] | 323 | """ |
---|
| 324 | |
---|
| 325 | def clear(id=None, archive=True): |
---|
[5676] | 326 | """Remove applicants of type given by 'id'. |
---|
[5638] | 327 | |
---|
[5676] | 328 | Optionally archive the applicants. |
---|
[6076] | 329 | |
---|
[5676] | 330 | If id is `None`, all applicants are archived. |
---|
[5638] | 331 | |
---|
| 332 | If id contains a single id string, only the respective |
---|
[5676] | 333 | applicants are archived. |
---|
[5638] | 334 | |
---|
| 335 | If id contains a list of id strings all of the respective |
---|
[5676] | 336 | applicant types are saved to disk. |
---|
[5638] | 337 | |
---|
| 338 | If `archive` is ``False`` none of the archive-handling is done |
---|
[5676] | 339 | and respective applicants are simply removed from the |
---|
[5638] | 340 | database. |
---|
| 341 | """ |
---|
[6073] | 342 | |
---|
[6069] | 343 | class IApplicantsContainerAdd(IApplicantsContainer): |
---|
| 344 | """An applicants container contains university applicants. |
---|
| 345 | """ |
---|
[6087] | 346 | prefix = schema.Choice( |
---|
[7708] | 347 | title = _(u'Application Target'), |
---|
[6069] | 348 | required = True, |
---|
[6087] | 349 | default = None, |
---|
[7683] | 350 | source = ApplicationTypeSource(), |
---|
[6069] | 351 | readonly = False, |
---|
[6076] | 352 | ) |
---|
[6073] | 353 | |
---|
[6087] | 354 | year = schema.Choice( |
---|
[7708] | 355 | title = _(u'Year of Entrance'), |
---|
[6087] | 356 | required = True, |
---|
| 357 | default = None, |
---|
[6158] | 358 | values = year_range(), |
---|
[6087] | 359 | readonly = False, |
---|
[6096] | 360 | ) |
---|
[6073] | 361 | |
---|
[6087] | 362 | provider = schema.Choice( |
---|
[7708] | 363 | title = _(u'Applicants Container Type'), |
---|
[6087] | 364 | required = True, |
---|
| 365 | default = None, |
---|
| 366 | source = ApplicantContainerProviderSource(), |
---|
| 367 | readonly = False, |
---|
| 368 | ) |
---|
| 369 | |
---|
[6096] | 370 | IApplicantsContainerAdd[ |
---|
| 371 | 'prefix'].order = IApplicantsContainer['prefix'].order |
---|
| 372 | IApplicantsContainerAdd[ |
---|
| 373 | 'year'].order = IApplicantsContainer['year'].order |
---|
| 374 | IApplicantsContainerAdd[ |
---|
| 375 | 'provider'].order = IApplicantsContainer['provider'].order |
---|
[6087] | 376 | |
---|
[7761] | 377 | class IResultEntry(Interface): |
---|
| 378 | subject = schema.Choice( |
---|
| 379 | title = _(u'Subject'), |
---|
| 380 | source = SubjectSource(), |
---|
| 381 | ) |
---|
| 382 | #subject = schema.TextLine( |
---|
| 383 | # title = _(u'Subject'), |
---|
| 384 | # ) |
---|
| 385 | grade = schema.Choice( |
---|
| 386 | title = _(u'Grafde'), |
---|
| 387 | source = GradeSource(), |
---|
| 388 | ) |
---|
| 389 | #grade = schema.TextLine( |
---|
| 390 | # title = _(u'Grade'), |
---|
| 391 | # ) |
---|
| 392 | |
---|
[7321] | 393 | class IApplicantBaseData(ISIRPObject): |
---|
[5753] | 394 | """The data for an applicant. |
---|
| 395 | |
---|
[7240] | 396 | This is a base interface with no field |
---|
[5753] | 397 | required. For use with importers, forms, etc., please use one of |
---|
| 398 | the derived interfaces below, which set more fields to required |
---|
| 399 | state, depending on use-case. |
---|
[7338] | 400 | |
---|
[7761] | 401 | This base interface is also implemented by the |
---|
| 402 | :class:`waeup.sirp.students.StudentApplication` class in the |
---|
| 403 | students package. Thus, these are the data which are saved after |
---|
| 404 | admission. |
---|
[5753] | 405 | """ |
---|
[7240] | 406 | applicant_id = schema.TextLine( |
---|
[7708] | 407 | title = _(u'Applicant Id'), |
---|
[7240] | 408 | required = False, |
---|
[7260] | 409 | readonly = False, |
---|
[7240] | 410 | ) |
---|
[7270] | 411 | reg_number = TextLineChoice( |
---|
[7708] | 412 | title = _(u'JAMB Registration Number'), |
---|
[7263] | 413 | readonly = False, |
---|
| 414 | required = True, |
---|
| 415 | default = None, |
---|
| 416 | source = contextual_reg_num_source, |
---|
[5753] | 417 | ) |
---|
[7376] | 418 | #access_code = schema.TextLine( |
---|
| 419 | # title = u'Activation Code', |
---|
| 420 | # required = False, |
---|
| 421 | # readonly = True, |
---|
| 422 | # ) |
---|
[5753] | 423 | firstname = schema.TextLine( |
---|
[7708] | 424 | title = _(u'First Name'), |
---|
[6352] | 425 | required = True, |
---|
[5753] | 426 | ) |
---|
[7356] | 427 | middlename = schema.TextLine( |
---|
[7708] | 428 | title = _(u'Middle Name'), |
---|
[5753] | 429 | required = False, |
---|
| 430 | ) |
---|
| 431 | lastname = schema.TextLine( |
---|
[7708] | 432 | title = _(u'Last Name (Surname)'), |
---|
[6352] | 433 | required = True, |
---|
[5753] | 434 | ) |
---|
| 435 | date_of_birth = schema.Date( |
---|
[7708] | 436 | title = _(u'Date of Birth'), |
---|
[6352] | 437 | required = True, |
---|
[5753] | 438 | ) |
---|
[6249] | 439 | lga = schema.Choice( |
---|
| 440 | source = lgas_vocab, |
---|
[7708] | 441 | title = _(u'State/LGA'), |
---|
[6254] | 442 | default = 'foreigner', |
---|
| 443 | required = True, |
---|
[5753] | 444 | ) |
---|
| 445 | sex = schema.Choice( |
---|
[7708] | 446 | title = _(u'Sex'), |
---|
[5753] | 447 | source = GenderSource(), |
---|
| 448 | default = u'm', |
---|
[6352] | 449 | required = True, |
---|
[5753] | 450 | ) |
---|
[6341] | 451 | email = schema.ASCIILine( |
---|
[7708] | 452 | title = _(u'Email Address'), |
---|
[7240] | 453 | required = True, |
---|
[6343] | 454 | constraint=validate_email, |
---|
[5753] | 455 | ) |
---|
[7324] | 456 | phone = schema.TextLine( |
---|
[7708] | 457 | title = _(u'Phone'), |
---|
[7331] | 458 | description = u'', |
---|
[5753] | 459 | required = False, |
---|
| 460 | ) |
---|
[7262] | 461 | course1 = schema.Choice( |
---|
[7708] | 462 | title = _(u'1st Choice Course of Study'), |
---|
[7347] | 463 | source = CertificateSource(), |
---|
[7262] | 464 | required = True, |
---|
| 465 | ) |
---|
| 466 | course2 = schema.Choice( |
---|
[7708] | 467 | title = _(u'2nd Choice Course of Study'), |
---|
[7347] | 468 | source = CertificateSource(), |
---|
[7262] | 469 | required = False, |
---|
| 470 | ) |
---|
[7761] | 471 | school_grades = schema.List( |
---|
| 472 | title = _(u'School Grades'), |
---|
[7770] | 473 | value_type = MultiValObject( |
---|
[7761] | 474 | schema = IResultEntry), |
---|
[7770] | 475 | #value_type = schema.Object( |
---|
| 476 | # schema = IResultEntry), |
---|
[7761] | 477 | required = True, |
---|
| 478 | default = [], |
---|
| 479 | ) |
---|
| 480 | #school_grades = schema.Dict( |
---|
| 481 | # title = _(u'School Grades'), |
---|
| 482 | # key_type = schema.TextLine( |
---|
| 483 | # title = _(u'Subject'), |
---|
| 484 | # ), |
---|
| 485 | # value_type = schema.TextLine( |
---|
| 486 | # title = _(u'Grade'), |
---|
| 487 | # ) |
---|
| 488 | # ) |
---|
[6322] | 489 | |
---|
[5753] | 490 | # |
---|
[7338] | 491 | # Data to be imported after screening |
---|
[5753] | 492 | # |
---|
[6255] | 493 | screening_score = schema.Int( |
---|
[7708] | 494 | title = _(u'Screening Score'), |
---|
[5753] | 495 | required = False, |
---|
| 496 | ) |
---|
| 497 | screening_venue = schema.TextLine( |
---|
[7708] | 498 | title = _(u'Screening Venue'), |
---|
[5753] | 499 | required = False, |
---|
| 500 | ) |
---|
[6248] | 501 | course_admitted = schema.Choice( |
---|
[7708] | 502 | title = _(u'Admitted Course of Study'), |
---|
[7347] | 503 | source = CertificateSource(), |
---|
[6254] | 504 | default = None, |
---|
[5753] | 505 | required = False, |
---|
| 506 | ) |
---|
[7347] | 507 | notice = schema.Text( |
---|
[7708] | 508 | title = _(u'Notice'), |
---|
[7347] | 509 | required = False, |
---|
| 510 | ) |
---|
[7338] | 511 | |
---|
| 512 | class IApplicantProcessData(IApplicantBaseData): |
---|
| 513 | """An applicant. |
---|
| 514 | |
---|
| 515 | Here we add process attributes and methods to the base data. |
---|
| 516 | """ |
---|
| 517 | |
---|
| 518 | history = Attribute('Object history, a list of messages.') |
---|
| 519 | state = Attribute('The application state of an applicant') |
---|
[7364] | 520 | display_fullname = Attribute('The fullname of an applicant') |
---|
[7338] | 521 | application_date = Attribute('Date of submission, used for export only') |
---|
| 522 | password = Attribute('Encrypted password of a applicant') |
---|
| 523 | application_number = Attribute('The key under which the record is stored') |
---|
| 524 | |
---|
| 525 | def loggerInfo(ob_class, comment): |
---|
| 526 | """Adds an INFO message to the log file |
---|
| 527 | """ |
---|
| 528 | |
---|
[5753] | 529 | student_id = schema.TextLine( |
---|
[7708] | 530 | title = _(u'Student Id'), |
---|
[5753] | 531 | required = False, |
---|
[7351] | 532 | readonly = False, |
---|
[5753] | 533 | ) |
---|
[6302] | 534 | locked = schema.Bool( |
---|
[7708] | 535 | title = _(u'Form locked'), |
---|
[6302] | 536 | default = False, |
---|
| 537 | ) |
---|
[5753] | 538 | |
---|
[7338] | 539 | class IApplicant(IApplicantProcessData): |
---|
[5753] | 540 | """An applicant. |
---|
| 541 | |
---|
| 542 | This is basically the applicant base data. Here we repeat the |
---|
[6195] | 543 | fields from base data if we have to set the `required` attribute |
---|
| 544 | to True (which is the default). |
---|
[5753] | 545 | """ |
---|
| 546 | |
---|
[7338] | 547 | class IApplicantEdit(IApplicantProcessData): |
---|
[6195] | 548 | """An applicant. |
---|
[5753] | 549 | |
---|
[6339] | 550 | Here we can repeat the fields from base data and set the |
---|
| 551 | `required` and `readonly` attributes to True to further restrict |
---|
[7262] | 552 | the data access. Or we can allow only certain certificates to be |
---|
| 553 | selected by choosing the appropriate source. |
---|
| 554 | |
---|
| 555 | We cannot omit fields here. This has to be done in the |
---|
[6339] | 556 | respective form page. |
---|
[6195] | 557 | """ |
---|
[7262] | 558 | |
---|
| 559 | course1 = schema.Choice( |
---|
[7708] | 560 | title = _(u'1st Choice Course of Study'), |
---|
[7347] | 561 | source = AppCatCertificateSource(), |
---|
[7262] | 562 | required = True, |
---|
| 563 | ) |
---|
| 564 | course2 = schema.Choice( |
---|
[7708] | 565 | title = _(u'2nd Choice Course of Study'), |
---|
[7347] | 566 | source = AppCatCertificateSource(), |
---|
[7262] | 567 | required = False, |
---|
| 568 | ) |
---|
[6255] | 569 | screening_score = schema.Int( |
---|
[7708] | 570 | title = _(u'Screening Score'), |
---|
[6195] | 571 | required = False, |
---|
[5941] | 572 | readonly = True, |
---|
| 573 | ) |
---|
[6195] | 574 | screening_venue = schema.TextLine( |
---|
[7708] | 575 | title = _(u'Screening Venue'), |
---|
[5753] | 576 | required = False, |
---|
| 577 | readonly = True, |
---|
| 578 | ) |
---|
[6301] | 579 | course_admitted = schema.Choice( |
---|
[7708] | 580 | title = _(u'Admitted Course of Study'), |
---|
[7347] | 581 | source = CertificateSource(), |
---|
[6301] | 582 | default = None, |
---|
[5753] | 583 | required = False, |
---|
[6195] | 584 | readonly = True, |
---|
[5753] | 585 | ) |
---|
[6195] | 586 | notice = schema.Text( |
---|
[7708] | 587 | title = _(u'Notice'), |
---|
[5753] | 588 | required = False, |
---|
| 589 | readonly = True, |
---|
| 590 | ) |
---|
[5758] | 591 | |
---|
[7338] | 592 | def createStudent(): |
---|
| 593 | """Create a student object from applicatnt data |
---|
| 594 | and copy applicant object. |
---|
| 595 | """ |
---|
| 596 | |
---|
[7268] | 597 | class IApplicantUpdateByRegNo(IApplicant): |
---|
| 598 | """Representation of an applicant. |
---|
| 599 | |
---|
[7270] | 600 | Skip regular reg_number validation if reg_number is used for finding |
---|
[7268] | 601 | the applicant object. |
---|
| 602 | """ |
---|
[7270] | 603 | reg_number = schema.TextLine( |
---|
[7268] | 604 | title = u'Registration Number', |
---|
| 605 | default = None, |
---|
| 606 | required = False, |
---|
| 607 | ) |
---|
| 608 | |
---|
[7250] | 609 | class IApplicantOnlinePayment(IOnlinePayment): |
---|
| 610 | """An applicant payment via payment gateways. |
---|
| 611 | |
---|
| 612 | """ |
---|
| 613 | p_year = schema.Choice( |
---|
[7708] | 614 | title = _(u'Payment Session'), |
---|
[7250] | 615 | source = academic_sessions_vocab, |
---|
| 616 | required = False, |
---|
| 617 | ) |
---|
| 618 | |
---|
| 619 | IApplicantOnlinePayment['p_year'].order = IApplicantOnlinePayment[ |
---|
| 620 | 'p_year'].order |
---|
| 621 | |
---|
[5846] | 622 | class IApplicantsContainerProvider(Interface): |
---|
[5820] | 623 | """A provider for applicants containers. |
---|
| 624 | |
---|
| 625 | Applicants container providers are meant to be looked up as |
---|
| 626 | utilities. This way we can find all applicant container types |
---|
| 627 | defined somewhere. |
---|
| 628 | |
---|
| 629 | Each applicants container provider registered as utility provides |
---|
| 630 | one container type and one should be able to call the `factory` |
---|
| 631 | attribute to create an instance of the requested container type. |
---|
| 632 | |
---|
| 633 | .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested) |
---|
[6076] | 634 | |
---|
[6500] | 635 | Samples: |
---|
[6076] | 636 | |
---|
[5820] | 637 | Given, you had an IApplicantsContainer implementation somewhere |
---|
| 638 | and you would like to make it findable on request, then you would |
---|
| 639 | normally create an appropriate provider utility like this:: |
---|
| 640 | |
---|
| 641 | import grok |
---|
[5846] | 642 | from waeup.sirp.applicants.interfaces import IApplicantsContainerProvider |
---|
[5820] | 643 | |
---|
| 644 | class MyContainerProvider(grok.GlobalUtility): |
---|
[5846] | 645 | grok.implements(IApplicantsContainerProvider) |
---|
[5820] | 646 | grok.name('MyContainerProvider') # Must be unique |
---|
| 647 | factory = MyContainer # A class implementing IApplicantsContainer |
---|
| 648 | # or derivations thereof. |
---|
| 649 | |
---|
| 650 | This utility would be registered on startup and could then be used |
---|
| 651 | like this: |
---|
| 652 | |
---|
| 653 | >>> from zope.component import getAllUtilitiesRegisteredFor |
---|
| 654 | >>> from waeup.sirp.applicants.interfaces import ( |
---|
[5846] | 655 | ... IApplicantsContainerProvider) |
---|
[5820] | 656 | >>> all_providers = getAllUtilitiesRegisteredFor( |
---|
[5846] | 657 | ... IApplicantsContainerProvider) |
---|
[5820] | 658 | >>> all_providers |
---|
| 659 | [<MyContainerProvider object at 0x...>] |
---|
| 660 | |
---|
| 661 | You could look up this specific provider by name: |
---|
| 662 | |
---|
| 663 | >>> from zope.component import getUtility |
---|
[5846] | 664 | >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider') |
---|
[5820] | 665 | >>> p |
---|
| 666 | <MyContainerProvider object at 0x...> |
---|
[6076] | 667 | |
---|
[5820] | 668 | An applicants container would then be created like this: |
---|
| 669 | |
---|
| 670 | >>> provider = all_providers[0] |
---|
| 671 | >>> container = provider.factory() |
---|
| 672 | >>> container |
---|
| 673 | <MyContainer object at 0x...> |
---|
| 674 | |
---|
| 675 | """ |
---|
| 676 | factory = Attribute("A class that can create instances of the " |
---|
| 677 | "requested container type") |
---|