[7191] | 1 | ## $Id: interfaces.py 7641 2012-02-14 07:07:46Z 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') |
---|
[7641] | 136 | current_mode = Attribute('The current mode of the student') |
---|
[7364] | 137 | fullname = Attribute('All name parts separated by hyphens') |
---|
| 138 | display_fullname = Attribute('The fullname of an applicant') |
---|
[6637] | 139 | |
---|
| 140 | def loggerInfo(ob_class, comment): |
---|
[7150] | 141 | """Adds an INFO message to the log file. |
---|
| 142 | |
---|
[6637] | 143 | """ |
---|
| 144 | |
---|
[6665] | 145 | student_id = schema.TextLine( |
---|
[7240] | 146 | title = u'Student Id', |
---|
[6849] | 147 | required = False, |
---|
[6665] | 148 | ) |
---|
| 149 | |
---|
[7357] | 150 | firstname = schema.TextLine( |
---|
| 151 | title = u'First Name', |
---|
[6621] | 152 | required = True, |
---|
| 153 | ) |
---|
| 154 | |
---|
[7357] | 155 | middlename = schema.TextLine( |
---|
| 156 | title = u'Middle Name', |
---|
| 157 | required = False, |
---|
| 158 | ) |
---|
| 159 | |
---|
| 160 | lastname = schema.TextLine( |
---|
| 161 | title = u'Last Name (Surname)', |
---|
| 162 | required = True, |
---|
| 163 | ) |
---|
| 164 | |
---|
[6996] | 165 | sex = schema.Choice( |
---|
| 166 | title = u'Sex', |
---|
| 167 | source = GenderSource(), |
---|
| 168 | default = u'm', |
---|
| 169 | required = True, |
---|
| 170 | ) |
---|
| 171 | |
---|
[6788] | 172 | reg_number = TextLineChoice( |
---|
[6696] | 173 | title = u'Registration Number', |
---|
| 174 | required = True, |
---|
| 175 | readonly = False, |
---|
[6788] | 176 | source = contextual_reg_num_source, |
---|
[6696] | 177 | ) |
---|
| 178 | |
---|
[6788] | 179 | matric_number = TextLineChoice( |
---|
[6750] | 180 | title = u'Matriculation Number', |
---|
[6788] | 181 | #default = u'', |
---|
[6750] | 182 | required = False, |
---|
| 183 | readonly = False, |
---|
[6788] | 184 | source = contextual_mat_num_source, |
---|
[6750] | 185 | ) |
---|
| 186 | |
---|
[6769] | 187 | adm_code = schema.TextLine( |
---|
[6935] | 188 | title = u'PWD Activation Code', |
---|
[6769] | 189 | default = u'', |
---|
| 190 | required = False, |
---|
| 191 | readonly = True, |
---|
| 192 | ) |
---|
| 193 | |
---|
[7133] | 194 | email = schema.ASCIILine( |
---|
| 195 | title = u'Email', |
---|
| 196 | required = False, |
---|
| 197 | constraint=validate_email, |
---|
| 198 | ) |
---|
[7325] | 199 | phone = schema.TextLine( |
---|
[7133] | 200 | title = u'Phone', |
---|
[7331] | 201 | description = u'', |
---|
[7133] | 202 | required = False, |
---|
| 203 | ) |
---|
| 204 | |
---|
[7321] | 205 | class IStudentClearance(ISIRPObject): |
---|
[6631] | 206 | """Representation of student clearance data. |
---|
[7150] | 207 | |
---|
[6631] | 208 | """ |
---|
| 209 | date_of_birth = schema.Date( |
---|
| 210 | title = u'Date of Birth', |
---|
| 211 | required = True, |
---|
| 212 | ) |
---|
| 213 | |
---|
[6695] | 214 | clearance_locked = schema.Bool( |
---|
| 215 | title = u'Clearance form locked', |
---|
| 216 | default = False, |
---|
| 217 | ) |
---|
| 218 | |
---|
[6769] | 219 | clr_code = schema.TextLine( |
---|
[6935] | 220 | title = u'CLR Activation Code', |
---|
[6769] | 221 | default = u'', |
---|
| 222 | required = False, |
---|
| 223 | readonly = True, |
---|
| 224 | ) |
---|
| 225 | |
---|
[7523] | 226 | nationality = schema.Choice( |
---|
| 227 | source = nats_vocab, |
---|
| 228 | title = u'Nationality', |
---|
| 229 | default = 'nigeria', |
---|
| 230 | required = True, |
---|
| 231 | ) |
---|
| 232 | |
---|
[7321] | 233 | class IStudentPersonal(ISIRPObject): |
---|
[6631] | 234 | """Representation of student personal data. |
---|
[7150] | 235 | |
---|
[6631] | 236 | """ |
---|
[6651] | 237 | perm_address = schema.Text( |
---|
[6631] | 238 | title = u'Permanent Address', |
---|
| 239 | required = False, |
---|
| 240 | ) |
---|
| 241 | |
---|
| 242 | class IStudent(IStudentBase,IStudentClearance,IStudentPersonal): |
---|
| 243 | """Representation of a student. |
---|
[7150] | 244 | |
---|
[6631] | 245 | """ |
---|
| 246 | |
---|
[6849] | 247 | class IStudentUpdateByRegNo(IStudent): |
---|
| 248 | """Representation of a student. Skip regular reg_number validation. |
---|
[7150] | 249 | |
---|
[6849] | 250 | """ |
---|
| 251 | reg_number = schema.TextLine( |
---|
| 252 | title = u'Registration Number', |
---|
| 253 | default = None, |
---|
| 254 | required = False, |
---|
| 255 | ) |
---|
| 256 | |
---|
| 257 | class IStudentUpdateByMatricNo(IStudent): |
---|
| 258 | """Representation of a student. Skip regular matric_number validation. |
---|
[7150] | 259 | |
---|
[6849] | 260 | """ |
---|
| 261 | matric_number = schema.TextLine( |
---|
| 262 | title = u'Matriculation Number', |
---|
| 263 | default = None, |
---|
| 264 | required = False, |
---|
| 265 | ) |
---|
| 266 | |
---|
[7321] | 267 | class IStudentStudyCourse(ISIRPObject): |
---|
[6633] | 268 | """A container for student study levels. |
---|
| 269 | |
---|
| 270 | """ |
---|
[6648] | 271 | certificate = schema.Choice( |
---|
| 272 | title = u'Certificate', |
---|
| 273 | source = CertificateSource(), |
---|
| 274 | default = None, |
---|
[7209] | 275 | required = False, |
---|
[6633] | 276 | ) |
---|
[6635] | 277 | |
---|
[6996] | 278 | entry_mode = schema.Choice( |
---|
| 279 | title = u'Entry Mode', |
---|
| 280 | vocabulary = study_modes, |
---|
| 281 | default = u'ug_ft', |
---|
| 282 | required = True, |
---|
| 283 | readonly = False, |
---|
| 284 | ) |
---|
| 285 | |
---|
| 286 | entry_session = schema.Choice( |
---|
| 287 | title = u'Entry Session', |
---|
| 288 | source = academic_sessions_vocab, |
---|
[7425] | 289 | #default = datetime.now().year, |
---|
| 290 | default = None, |
---|
[6996] | 291 | required = True, |
---|
| 292 | readonly = False, |
---|
| 293 | ) |
---|
| 294 | |
---|
[6724] | 295 | current_session = schema.Choice( |
---|
| 296 | title = u'Current Session', |
---|
[6744] | 297 | source = academic_sessions_vocab, |
---|
[6724] | 298 | default = None, |
---|
| 299 | required = True, |
---|
[6996] | 300 | readonly = False, |
---|
[6724] | 301 | ) |
---|
| 302 | |
---|
| 303 | current_level = schema.Choice( |
---|
| 304 | title = u'Current Level', |
---|
[6725] | 305 | source = StudyLevelSource(), |
---|
[6724] | 306 | default = None, |
---|
[6725] | 307 | required = False, |
---|
[6996] | 308 | readonly = False, |
---|
[6724] | 309 | ) |
---|
| 310 | |
---|
| 311 | current_verdict = schema.Choice( |
---|
| 312 | title = u'Current Verdict', |
---|
[7619] | 313 | source = VerdictSource(), |
---|
[6804] | 314 | default = '0', |
---|
[6725] | 315 | required = False, |
---|
[6724] | 316 | ) |
---|
| 317 | |
---|
| 318 | previous_verdict = schema.Choice( |
---|
| 319 | title = u'Previous Verdict', |
---|
[7619] | 320 | source = VerdictSource(), |
---|
[6805] | 321 | default = '0', |
---|
[6725] | 322 | required = False, |
---|
[6724] | 323 | ) |
---|
| 324 | |
---|
[7321] | 325 | class IStudentStudyLevel(ISIRPObject): |
---|
[6774] | 326 | """A container for course tickets. |
---|
| 327 | |
---|
| 328 | """ |
---|
| 329 | level = Attribute('The level code') |
---|
[6793] | 330 | validation_date = Attribute('The date of validation') |
---|
| 331 | validated_by = Attribute('User Id of course adviser') |
---|
[6774] | 332 | |
---|
[6793] | 333 | level_session = schema.Choice( |
---|
| 334 | title = u'Session', |
---|
| 335 | source = academic_sessions_vocab, |
---|
| 336 | default = None, |
---|
| 337 | required = True, |
---|
| 338 | ) |
---|
[6781] | 339 | |
---|
[6793] | 340 | level_verdict = schema.Choice( |
---|
| 341 | title = u'Verdict', |
---|
[7619] | 342 | source = VerdictSource(), |
---|
[6805] | 343 | default = '0', |
---|
[6793] | 344 | required = False, |
---|
| 345 | ) |
---|
| 346 | |
---|
[7321] | 347 | class ICourseTicket(ISIRPObject): |
---|
[6781] | 348 | """A course ticket. |
---|
| 349 | |
---|
| 350 | """ |
---|
[6783] | 351 | code = Attribute('code of the original course') |
---|
| 352 | title = Attribute('title of the original course') |
---|
| 353 | credits = Attribute('credits of the original course') |
---|
| 354 | passmark = Attribute('passmark of the original course') |
---|
| 355 | semester = Attribute('semester of the original course') |
---|
[7304] | 356 | fcode = Attribute('faculty code of the original course') |
---|
| 357 | dcode = Attribute('department code of the original course') |
---|
[6781] | 358 | |
---|
[6795] | 359 | core_or_elective = schema.Bool( |
---|
| 360 | title = u'Mandatory', |
---|
| 361 | default = False, |
---|
| 362 | required = False, |
---|
| 363 | readonly = False, |
---|
| 364 | ) |
---|
| 365 | |
---|
[6781] | 366 | score = schema.Int( |
---|
| 367 | title = u'Score', |
---|
| 368 | default = 0, |
---|
| 369 | required = False, |
---|
| 370 | readonly = False, |
---|
| 371 | ) |
---|
| 372 | |
---|
[6806] | 373 | automatic = schema.Bool( |
---|
| 374 | title = u'Automatical Creation', |
---|
| 375 | default = False, |
---|
| 376 | required = False, |
---|
| 377 | readonly = True, |
---|
| 378 | ) |
---|
| 379 | |
---|
[7633] | 380 | def getLevel(): |
---|
| 381 | """Returns the id of the level the ticket has been added to. |
---|
| 382 | """ |
---|
| 383 | |
---|
| 384 | def getLevelSession(): |
---|
| 385 | """Returns the session of the level the ticket has been added to. |
---|
| 386 | """ |
---|
| 387 | |
---|
[6795] | 388 | class ICourseTicketAdd(ICourseTicket): |
---|
[7150] | 389 | """An interface for adding course tickets. |
---|
[6795] | 390 | |
---|
| 391 | """ |
---|
| 392 | course = schema.Choice( |
---|
| 393 | title = u'Course', |
---|
| 394 | source = CourseSource(), |
---|
| 395 | readonly = False, |
---|
| 396 | ) |
---|
| 397 | |
---|
[7321] | 398 | class IStudentAccommodation(ISIRPObject): |
---|
[6635] | 399 | """A container for student accommodation objects. |
---|
| 400 | |
---|
| 401 | """ |
---|
| 402 | |
---|
[7321] | 403 | class IBedTicket(ISIRPObject): |
---|
[6989] | 404 | """A ticket for accommodation booking. |
---|
| 405 | |
---|
| 406 | """ |
---|
[6996] | 407 | bed = Attribute('The bed object.') |
---|
| 408 | |
---|
| 409 | bed_coordinates = schema.TextLine( |
---|
| 410 | title = u'Bed Coordinates', |
---|
[6992] | 411 | default = None, |
---|
| 412 | required = False, |
---|
[7014] | 413 | readonly = False, |
---|
[6992] | 414 | ) |
---|
| 415 | |
---|
[6996] | 416 | bed_type = schema.TextLine( |
---|
| 417 | title = u'Bed Type', |
---|
| 418 | default = None, |
---|
| 419 | required = False, |
---|
[7014] | 420 | readonly = False, |
---|
[6996] | 421 | ) |
---|
| 422 | |
---|
[6992] | 423 | booking_session = schema.Choice( |
---|
| 424 | title = u'Session', |
---|
| 425 | source = academic_sessions_vocab, |
---|
| 426 | default = None, |
---|
| 427 | required = True, |
---|
[7014] | 428 | readonly = True, |
---|
[6992] | 429 | ) |
---|
| 430 | |
---|
| 431 | booking_date = schema.Datetime( |
---|
| 432 | title = u'Booking Date', |
---|
| 433 | required = False, |
---|
[7014] | 434 | readonly = True, |
---|
[6992] | 435 | ) |
---|
| 436 | |
---|
| 437 | booking_code = schema.TextLine( |
---|
| 438 | title = u'Booking Activation Code', |
---|
| 439 | default = u'', |
---|
| 440 | required = False, |
---|
[7014] | 441 | readonly = True, |
---|
[6992] | 442 | ) |
---|
| 443 | |
---|
[6994] | 444 | def getSessionString(): |
---|
[7633] | 445 | """Returns the title of academic_sessions_vocab term. |
---|
[7150] | 446 | |
---|
[6994] | 447 | """ |
---|
[6992] | 448 | |
---|
[6860] | 449 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
[6635] | 450 | """A container for student payment objects. |
---|
| 451 | |
---|
| 452 | """ |
---|
| 453 | |
---|
[6877] | 454 | class IStudentOnlinePayment(IOnlinePayment): |
---|
| 455 | """A student payment via payment gateways. |
---|
| 456 | |
---|
| 457 | """ |
---|
| 458 | p_session = schema.Choice( |
---|
| 459 | title = u'Payment Session', |
---|
| 460 | source = academic_sessions_vocab, |
---|
| 461 | required = False, |
---|
| 462 | ) |
---|
| 463 | |
---|
| 464 | IStudentOnlinePayment['p_session'].order = IStudentOnlinePayment[ |
---|
| 465 | 'p_item'].order |
---|
| 466 | |
---|
[7369] | 467 | class IStudentChangePassword(ISIRPObject): |
---|
| 468 | """Interface needed for change pasword page. |
---|
| 469 | |
---|
| 470 | """ |
---|
| 471 | |
---|
| 472 | reg_number = schema.TextLine( |
---|
| 473 | title = u'Registration Number', |
---|
| 474 | default = None, |
---|
| 475 | required = True, |
---|
| 476 | readonly = False, |
---|
| 477 | ) |
---|
| 478 | |
---|
| 479 | email = schema.ASCIILine( |
---|
[7554] | 480 | title = u'Email Address', |
---|
[7369] | 481 | required = True, |
---|
| 482 | constraint=validate_email, |
---|
| 483 | ) |
---|