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