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