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