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