[7191] | 1 | ## $Id: interfaces.py 7620 2012-02-09 19:29:24Z henrik $ |
---|
[6621] | 2 | ## |
---|
[7191] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 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. |
---|
| 8 | ## |
---|
| 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. |
---|
| 13 | ## |
---|
| 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 | ## |
---|
[6996] | 18 | from datetime import datetime |
---|
[7620] | 19 | from zope.component import getUtility |
---|
[7256] | 20 | from zope.interface import Attribute, Interface |
---|
[6621] | 21 | from zope import schema |
---|
[7620] | 22 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[7221] | 23 | from waeup.sirp.interfaces import ( |
---|
[7321] | 24 | ISIRPObject, academic_sessions_vocab, validate_email) |
---|
[6788] | 25 | from waeup.sirp.schema import TextLineChoice |
---|
[6874] | 26 | from waeup.sirp.university.vocabularies import CourseSource, study_modes |
---|
[6648] | 27 | from waeup.sirp.students.vocabularies import ( |
---|
[7620] | 28 | CertificateSource, StudyLevelSource, |
---|
[7523] | 29 | contextual_reg_num_source, contextual_mat_num_source, |
---|
| 30 | GenderSource, nats_vocab, |
---|
[6648] | 31 | ) |
---|
[6877] | 32 | from waeup.sirp.payments.interfaces import IPaymentsContainer, IOnlinePayment |
---|
[6621] | 33 | |
---|
[7620] | 34 | # VerdictSource can't be placed into the vocabularies module because it |
---|
| 35 | # requires importing IStudentsUtils which then leads to circular imports. |
---|
| 36 | class VerdictSource(BasicContextualSourceFactory): |
---|
| 37 | """A verdicts source delivers all verdicts provided |
---|
| 38 | in the portal. |
---|
| 39 | """ |
---|
| 40 | def getValues(self, context): |
---|
| 41 | self.verdicts_dict = getUtility(IStudentsUtils).getVerdictsDict() |
---|
| 42 | return self.verdicts_dict.keys() |
---|
| 43 | |
---|
| 44 | def getToken(self, context, value): |
---|
| 45 | return value |
---|
| 46 | |
---|
| 47 | def getTitle(self, context, value): |
---|
| 48 | return self.verdicts_dict[value] |
---|
| 49 | |
---|
[7150] | 50 | class IStudentsUtils(Interface): |
---|
| 51 | """A collection of methods which are subject to customization. |
---|
| 52 | |
---|
| 53 | """ |
---|
[7186] | 54 | def getPaymentDetails(category, student): |
---|
[7150] | 55 | """Get the payment dates of a student for the payment category |
---|
| 56 | specified. |
---|
| 57 | |
---|
| 58 | """ |
---|
| 59 | |
---|
[7186] | 60 | def getAccommodation_details(student): |
---|
[7150] | 61 | """Determine the accommodation dates of a student. |
---|
| 62 | |
---|
| 63 | """ |
---|
| 64 | |
---|
[7186] | 65 | def selectBed(available_beds): |
---|
[7150] | 66 | """Select a bed from a list of available beds. |
---|
| 67 | |
---|
| 68 | In the standard configuration we select the first bed found, |
---|
| 69 | but can also randomize the selection if we like. |
---|
| 70 | """ |
---|
| 71 | |
---|
[7186] | 72 | def renderPDF(view, subject='', filename='slip.pdf',): |
---|
[7150] | 73 | """Render pdf slips for various pages. |
---|
| 74 | |
---|
| 75 | """ |
---|
| 76 | |
---|
[7321] | 77 | class IStudentsContainer(ISIRPObject): |
---|
[7096] | 78 | """A students container contains university students. |
---|
[6692] | 79 | |
---|
| 80 | """ |
---|
| 81 | def addStudent(student): |
---|
| 82 | """Add an IStudent object and subcontainers. |
---|
| 83 | |
---|
| 84 | """ |
---|
| 85 | |
---|
| 86 | def archive(id=None): |
---|
| 87 | """Create on-dist archive of students. |
---|
| 88 | |
---|
| 89 | If id is `None`, all students are archived. |
---|
| 90 | |
---|
| 91 | If id contains a single id string, only the respective |
---|
| 92 | students are archived. |
---|
| 93 | |
---|
| 94 | If id contains a list of id strings all of the respective |
---|
| 95 | students types are saved to disk. |
---|
| 96 | """ |
---|
| 97 | |
---|
| 98 | def clear(id=None, archive=True): |
---|
| 99 | """Remove students of type given by 'id'. |
---|
| 100 | |
---|
| 101 | Optionally archive the students. |
---|
| 102 | |
---|
| 103 | If id is `None`, all students are archived. |
---|
| 104 | |
---|
| 105 | If id contains a single id string, only the respective |
---|
| 106 | students are archived. |
---|
| 107 | |
---|
| 108 | If id contains a list of id strings all of the respective |
---|
| 109 | student types are saved to disk. |
---|
| 110 | |
---|
| 111 | If `archive` is ``False`` none of the archive-handling is done |
---|
| 112 | and respective students are simply removed from the |
---|
| 113 | database. |
---|
| 114 | """ |
---|
| 115 | |
---|
[7321] | 116 | class IStudentNavigation(ISIRPObject): |
---|
[6642] | 117 | """Interface needed for student navigation. |
---|
[7150] | 118 | |
---|
[6642] | 119 | """ |
---|
| 120 | def getStudent(): |
---|
| 121 | """Return student object. |
---|
[7150] | 122 | |
---|
[6642] | 123 | """ |
---|
| 124 | |
---|
[7321] | 125 | class IStudentBase(ISIRPObject): |
---|
[6631] | 126 | """Representation of student base data. |
---|
[7150] | 127 | |
---|
[6621] | 128 | """ |
---|
[7062] | 129 | history = Attribute('Object history, a list of messages') |
---|
[6637] | 130 | state = Attribute('Returns the registration state of a student') |
---|
[6699] | 131 | password = Attribute('Encrypted password of a student') |
---|
[7203] | 132 | certcode = Attribute('The certificate code of any chosen study course') |
---|
| 133 | depcode = Attribute('The department code of any chosen study course') |
---|
| 134 | faccode = Attribute('The faculty code of any chosen study course') |
---|
[7062] | 135 | current_session = Attribute('The current session of the student') |
---|
[7364] | 136 | fullname = Attribute('All name parts separated by hyphens') |
---|
| 137 | display_fullname = Attribute('The fullname of an applicant') |
---|
[6637] | 138 | |
---|
| 139 | def loggerInfo(ob_class, comment): |
---|
[7150] | 140 | """Adds an INFO message to the log file. |
---|
| 141 | |
---|
[6637] | 142 | """ |
---|
| 143 | |
---|
[6665] | 144 | student_id = schema.TextLine( |
---|
[7240] | 145 | title = u'Student Id', |
---|
[6849] | 146 | required = False, |
---|
[6665] | 147 | ) |
---|
| 148 | |
---|
[7357] | 149 | firstname = schema.TextLine( |
---|
| 150 | title = u'First Name', |
---|
[6621] | 151 | required = True, |
---|
| 152 | ) |
---|
| 153 | |
---|
[7357] | 154 | middlename = schema.TextLine( |
---|
| 155 | title = u'Middle Name', |
---|
| 156 | required = False, |
---|
| 157 | ) |
---|
| 158 | |
---|
| 159 | lastname = schema.TextLine( |
---|
| 160 | title = u'Last Name (Surname)', |
---|
| 161 | required = True, |
---|
| 162 | ) |
---|
| 163 | |
---|
[6996] | 164 | sex = schema.Choice( |
---|
| 165 | title = u'Sex', |
---|
| 166 | source = GenderSource(), |
---|
| 167 | default = u'm', |
---|
| 168 | required = True, |
---|
| 169 | ) |
---|
| 170 | |
---|
[6788] | 171 | reg_number = TextLineChoice( |
---|
[6696] | 172 | title = u'Registration Number', |
---|
| 173 | required = True, |
---|
| 174 | readonly = False, |
---|
[6788] | 175 | source = contextual_reg_num_source, |
---|
[6696] | 176 | ) |
---|
| 177 | |
---|
[6788] | 178 | matric_number = TextLineChoice( |
---|
[6750] | 179 | title = u'Matriculation Number', |
---|
[6788] | 180 | #default = u'', |
---|
[6750] | 181 | required = False, |
---|
| 182 | readonly = False, |
---|
[6788] | 183 | source = contextual_mat_num_source, |
---|
[6750] | 184 | ) |
---|
| 185 | |
---|
[6769] | 186 | adm_code = schema.TextLine( |
---|
[6935] | 187 | title = u'PWD Activation Code', |
---|
[6769] | 188 | default = u'', |
---|
| 189 | required = False, |
---|
| 190 | readonly = True, |
---|
| 191 | ) |
---|
| 192 | |
---|
[7133] | 193 | email = schema.ASCIILine( |
---|
| 194 | title = u'Email', |
---|
| 195 | required = False, |
---|
| 196 | constraint=validate_email, |
---|
| 197 | ) |
---|
[7325] | 198 | phone = schema.TextLine( |
---|
[7133] | 199 | title = u'Phone', |
---|
[7331] | 200 | description = u'', |
---|
[7133] | 201 | required = False, |
---|
| 202 | ) |
---|
| 203 | |
---|
[7321] | 204 | class IStudentClearance(ISIRPObject): |
---|
[6631] | 205 | """Representation of student clearance data. |
---|
[7150] | 206 | |
---|
[6631] | 207 | """ |
---|
| 208 | date_of_birth = schema.Date( |
---|
| 209 | title = u'Date of Birth', |
---|
| 210 | required = True, |
---|
| 211 | ) |
---|
| 212 | |
---|
[6695] | 213 | clearance_locked = schema.Bool( |
---|
| 214 | title = u'Clearance form locked', |
---|
| 215 | default = False, |
---|
| 216 | ) |
---|
| 217 | |
---|
[6769] | 218 | clr_code = schema.TextLine( |
---|
[6935] | 219 | title = u'CLR Activation Code', |
---|
[6769] | 220 | default = u'', |
---|
| 221 | required = False, |
---|
| 222 | readonly = True, |
---|
| 223 | ) |
---|
| 224 | |
---|
[7523] | 225 | nationality = schema.Choice( |
---|
| 226 | source = nats_vocab, |
---|
| 227 | title = u'Nationality', |
---|
| 228 | default = 'nigeria', |
---|
| 229 | required = True, |
---|
| 230 | ) |
---|
| 231 | |
---|
[7321] | 232 | class IStudentPersonal(ISIRPObject): |
---|
[6631] | 233 | """Representation of student personal data. |
---|
[7150] | 234 | |
---|
[6631] | 235 | """ |
---|
[6651] | 236 | perm_address = schema.Text( |
---|
[6631] | 237 | title = u'Permanent Address', |
---|
| 238 | required = False, |
---|
| 239 | ) |
---|
| 240 | |
---|
| 241 | class IStudent(IStudentBase,IStudentClearance,IStudentPersonal): |
---|
| 242 | """Representation of a student. |
---|
[7150] | 243 | |
---|
[6631] | 244 | """ |
---|
| 245 | |
---|
[6849] | 246 | class IStudentUpdateByRegNo(IStudent): |
---|
| 247 | """Representation of a student. Skip regular reg_number validation. |
---|
[7150] | 248 | |
---|
[6849] | 249 | """ |
---|
| 250 | reg_number = schema.TextLine( |
---|
| 251 | title = u'Registration Number', |
---|
| 252 | default = None, |
---|
| 253 | required = False, |
---|
| 254 | ) |
---|
| 255 | |
---|
| 256 | class IStudentUpdateByMatricNo(IStudent): |
---|
| 257 | """Representation of a student. Skip regular matric_number validation. |
---|
[7150] | 258 | |
---|
[6849] | 259 | """ |
---|
| 260 | matric_number = schema.TextLine( |
---|
| 261 | title = u'Matriculation Number', |
---|
| 262 | default = None, |
---|
| 263 | required = False, |
---|
| 264 | ) |
---|
| 265 | |
---|
[7321] | 266 | class IStudentStudyCourse(ISIRPObject): |
---|
[6633] | 267 | """A container for student study levels. |
---|
| 268 | |
---|
| 269 | """ |
---|
[6648] | 270 | certificate = schema.Choice( |
---|
| 271 | title = u'Certificate', |
---|
| 272 | source = CertificateSource(), |
---|
| 273 | default = None, |
---|
[7209] | 274 | required = False, |
---|
[6633] | 275 | ) |
---|
[6635] | 276 | |
---|
[6996] | 277 | entry_mode = schema.Choice( |
---|
| 278 | title = u'Entry Mode', |
---|
| 279 | vocabulary = study_modes, |
---|
| 280 | default = u'ug_ft', |
---|
| 281 | required = True, |
---|
| 282 | readonly = False, |
---|
| 283 | ) |
---|
| 284 | |
---|
| 285 | entry_session = schema.Choice( |
---|
| 286 | title = u'Entry Session', |
---|
| 287 | source = academic_sessions_vocab, |
---|
[7425] | 288 | #default = datetime.now().year, |
---|
| 289 | default = None, |
---|
[6996] | 290 | required = True, |
---|
| 291 | readonly = False, |
---|
| 292 | ) |
---|
| 293 | |
---|
[6724] | 294 | current_session = schema.Choice( |
---|
| 295 | title = u'Current Session', |
---|
[6744] | 296 | source = academic_sessions_vocab, |
---|
[6724] | 297 | default = None, |
---|
| 298 | required = True, |
---|
[6996] | 299 | readonly = False, |
---|
[6724] | 300 | ) |
---|
| 301 | |
---|
| 302 | current_level = schema.Choice( |
---|
| 303 | title = u'Current Level', |
---|
[6725] | 304 | source = StudyLevelSource(), |
---|
[6724] | 305 | default = None, |
---|
[6725] | 306 | required = False, |
---|
[6996] | 307 | readonly = False, |
---|
[6724] | 308 | ) |
---|
| 309 | |
---|
| 310 | current_verdict = schema.Choice( |
---|
| 311 | title = u'Current Verdict', |
---|
[7619] | 312 | source = VerdictSource(), |
---|
[6804] | 313 | default = '0', |
---|
[6725] | 314 | required = False, |
---|
[6724] | 315 | ) |
---|
| 316 | |
---|
| 317 | previous_verdict = schema.Choice( |
---|
| 318 | title = u'Previous Verdict', |
---|
[7619] | 319 | source = VerdictSource(), |
---|
[6805] | 320 | default = '0', |
---|
[6725] | 321 | required = False, |
---|
[6724] | 322 | ) |
---|
| 323 | |
---|
[7321] | 324 | class IStudentStudyLevel(ISIRPObject): |
---|
[6774] | 325 | """A container for course tickets. |
---|
| 326 | |
---|
| 327 | """ |
---|
| 328 | level = Attribute('The level code') |
---|
[6793] | 329 | validation_date = Attribute('The date of validation') |
---|
| 330 | validated_by = Attribute('User Id of course adviser') |
---|
[6774] | 331 | |
---|
[6793] | 332 | level_session = schema.Choice( |
---|
| 333 | title = u'Session', |
---|
| 334 | source = academic_sessions_vocab, |
---|
| 335 | default = None, |
---|
| 336 | required = True, |
---|
| 337 | ) |
---|
[6781] | 338 | |
---|
[6793] | 339 | level_verdict = schema.Choice( |
---|
| 340 | title = u'Verdict', |
---|
[7619] | 341 | source = VerdictSource(), |
---|
[6805] | 342 | default = '0', |
---|
[6793] | 343 | required = False, |
---|
| 344 | ) |
---|
| 345 | |
---|
[7321] | 346 | class ICourseTicket(ISIRPObject): |
---|
[6781] | 347 | """A course ticket. |
---|
| 348 | |
---|
| 349 | """ |
---|
[6783] | 350 | code = Attribute('code of the original course') |
---|
| 351 | title = Attribute('title of the original course') |
---|
| 352 | credits = Attribute('credits of the original course') |
---|
| 353 | passmark = Attribute('passmark of the original course') |
---|
| 354 | semester = Attribute('semester of the original course') |
---|
[7304] | 355 | fcode = Attribute('faculty code of the original course') |
---|
| 356 | dcode = Attribute('department code of the original course') |
---|
[6781] | 357 | |
---|
[6795] | 358 | core_or_elective = schema.Bool( |
---|
| 359 | title = u'Mandatory', |
---|
| 360 | default = False, |
---|
| 361 | required = False, |
---|
| 362 | readonly = False, |
---|
| 363 | ) |
---|
| 364 | |
---|
[6781] | 365 | score = schema.Int( |
---|
| 366 | title = u'Score', |
---|
| 367 | default = 0, |
---|
| 368 | required = False, |
---|
| 369 | readonly = False, |
---|
| 370 | ) |
---|
| 371 | |
---|
[6806] | 372 | automatic = schema.Bool( |
---|
| 373 | title = u'Automatical Creation', |
---|
| 374 | default = False, |
---|
| 375 | required = False, |
---|
| 376 | readonly = True, |
---|
| 377 | ) |
---|
| 378 | |
---|
[6795] | 379 | class ICourseTicketAdd(ICourseTicket): |
---|
[7150] | 380 | """An interface for adding course tickets. |
---|
[6795] | 381 | |
---|
| 382 | """ |
---|
| 383 | course = schema.Choice( |
---|
| 384 | title = u'Course', |
---|
| 385 | source = CourseSource(), |
---|
| 386 | readonly = False, |
---|
| 387 | ) |
---|
| 388 | |
---|
[7321] | 389 | class IStudentAccommodation(ISIRPObject): |
---|
[6635] | 390 | """A container for student accommodation objects. |
---|
| 391 | |
---|
| 392 | """ |
---|
| 393 | |
---|
[7321] | 394 | class IBedTicket(ISIRPObject): |
---|
[6989] | 395 | """A ticket for accommodation booking. |
---|
| 396 | |
---|
| 397 | """ |
---|
[6996] | 398 | bed = Attribute('The bed object.') |
---|
| 399 | |
---|
| 400 | bed_coordinates = schema.TextLine( |
---|
| 401 | title = u'Bed Coordinates', |
---|
[6992] | 402 | default = None, |
---|
| 403 | required = False, |
---|
[7014] | 404 | readonly = False, |
---|
[6992] | 405 | ) |
---|
| 406 | |
---|
[6996] | 407 | bed_type = schema.TextLine( |
---|
| 408 | title = u'Bed Type', |
---|
| 409 | default = None, |
---|
| 410 | required = False, |
---|
[7014] | 411 | readonly = False, |
---|
[6996] | 412 | ) |
---|
| 413 | |
---|
[6992] | 414 | booking_session = schema.Choice( |
---|
| 415 | title = u'Session', |
---|
| 416 | source = academic_sessions_vocab, |
---|
| 417 | default = None, |
---|
| 418 | required = True, |
---|
[7014] | 419 | readonly = True, |
---|
[6992] | 420 | ) |
---|
| 421 | |
---|
| 422 | booking_date = schema.Datetime( |
---|
| 423 | title = u'Booking Date', |
---|
| 424 | required = False, |
---|
[7014] | 425 | readonly = True, |
---|
[6992] | 426 | ) |
---|
| 427 | |
---|
| 428 | booking_code = schema.TextLine( |
---|
| 429 | title = u'Booking Activation Code', |
---|
| 430 | default = u'', |
---|
| 431 | required = False, |
---|
[7014] | 432 | readonly = True, |
---|
[6992] | 433 | ) |
---|
| 434 | |
---|
[6994] | 435 | def getSessionString(): |
---|
[7150] | 436 | """Returns the the title of academic_sessions_vocab term. |
---|
| 437 | |
---|
[6994] | 438 | """ |
---|
[6992] | 439 | |
---|
[6860] | 440 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
[6635] | 441 | """A container for student payment objects. |
---|
| 442 | |
---|
| 443 | """ |
---|
| 444 | |
---|
[6877] | 445 | class IStudentOnlinePayment(IOnlinePayment): |
---|
| 446 | """A student payment via payment gateways. |
---|
| 447 | |
---|
| 448 | """ |
---|
| 449 | p_session = schema.Choice( |
---|
| 450 | title = u'Payment Session', |
---|
| 451 | source = academic_sessions_vocab, |
---|
| 452 | required = False, |
---|
| 453 | ) |
---|
| 454 | |
---|
| 455 | IStudentOnlinePayment['p_session'].order = IStudentOnlinePayment[ |
---|
| 456 | 'p_item'].order |
---|
| 457 | |
---|
[7369] | 458 | class IStudentChangePassword(ISIRPObject): |
---|
| 459 | """Interface needed for change pasword page. |
---|
| 460 | |
---|
| 461 | """ |
---|
| 462 | |
---|
| 463 | reg_number = schema.TextLine( |
---|
| 464 | title = u'Registration Number', |
---|
| 465 | default = None, |
---|
| 466 | required = True, |
---|
| 467 | readonly = False, |
---|
| 468 | ) |
---|
| 469 | |
---|
| 470 | email = schema.ASCIILine( |
---|
[7554] | 471 | title = u'Email Address', |
---|
[7369] | 472 | required = True, |
---|
| 473 | constraint=validate_email, |
---|
| 474 | ) |
---|