[6621] | 1 | ## |
---|
| 2 | ## interfaces.py |
---|
[7133] | 3 | import re |
---|
[6996] | 4 | from datetime import datetime |
---|
[6788] | 5 | from zope.interface import Attribute, invariant |
---|
[6756] | 6 | from zope.interface.exceptions import Invalid |
---|
[6621] | 7 | from zope import schema |
---|
[6915] | 8 | from waeup.sirp.interfaces import IWAeUPObject, academic_sessions_vocab |
---|
[6788] | 9 | from waeup.sirp.schema import TextLineChoice |
---|
[6874] | 10 | from waeup.sirp.university.vocabularies import CourseSource, study_modes |
---|
[6648] | 11 | from waeup.sirp.students.vocabularies import ( |
---|
[6788] | 12 | CertificateSource, academic_sessions_vocab, verdicts, StudyLevelSource, |
---|
[6996] | 13 | contextual_reg_num_source, contextual_mat_num_source, GenderSource, |
---|
[6648] | 14 | ) |
---|
[6877] | 15 | from waeup.sirp.payments.interfaces import IPaymentsContainer, IOnlinePayment |
---|
[6621] | 16 | |
---|
[7133] | 17 | # Define a valiation method for email addresses |
---|
| 18 | class NotAnEmailAddress(schema.ValidationError): |
---|
| 19 | __doc__ = u"Invalid email address" |
---|
| 20 | |
---|
| 21 | check_email = re.compile( |
---|
| 22 | r"[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match |
---|
| 23 | def validate_email(value): |
---|
| 24 | if not check_email(value): |
---|
| 25 | raise NotAnEmailAddress(value) |
---|
| 26 | return True |
---|
| 27 | |
---|
[6692] | 28 | class IStudentsContainer(IWAeUPObject): |
---|
[7096] | 29 | """A students container contains university students. |
---|
[6692] | 30 | |
---|
| 31 | """ |
---|
| 32 | |
---|
| 33 | def addStudent(student): |
---|
| 34 | """Add an IStudent object and subcontainers. |
---|
| 35 | |
---|
| 36 | """ |
---|
| 37 | |
---|
| 38 | def archive(id=None): |
---|
| 39 | """Create on-dist archive of students. |
---|
| 40 | |
---|
| 41 | If id is `None`, all students are archived. |
---|
| 42 | |
---|
| 43 | If id contains a single id string, only the respective |
---|
| 44 | students are archived. |
---|
| 45 | |
---|
| 46 | If id contains a list of id strings all of the respective |
---|
| 47 | students types are saved to disk. |
---|
| 48 | """ |
---|
| 49 | |
---|
| 50 | def clear(id=None, archive=True): |
---|
| 51 | """Remove students of type given by 'id'. |
---|
| 52 | |
---|
| 53 | Optionally archive the students. |
---|
| 54 | |
---|
| 55 | If id is `None`, all students are archived. |
---|
| 56 | |
---|
| 57 | If id contains a single id string, only the respective |
---|
| 58 | students are archived. |
---|
| 59 | |
---|
| 60 | If id contains a list of id strings all of the respective |
---|
| 61 | student types are saved to disk. |
---|
| 62 | |
---|
| 63 | If `archive` is ``False`` none of the archive-handling is done |
---|
| 64 | and respective students are simply removed from the |
---|
| 65 | database. |
---|
| 66 | """ |
---|
| 67 | |
---|
[6642] | 68 | class IStudentNavigation(IWAeUPObject): |
---|
| 69 | """Interface needed for student navigation. |
---|
| 70 | """ |
---|
| 71 | |
---|
| 72 | def getStudent(): |
---|
| 73 | """Return student object. |
---|
| 74 | """ |
---|
| 75 | |
---|
[6756] | 76 | class IStudentPasswordSetting(IWAeUPObject): |
---|
| 77 | """Data needed for password setting. |
---|
| 78 | """ |
---|
| 79 | |
---|
[7124] | 80 | def validPassword(value): |
---|
| 81 | return len(value) > 3 |
---|
| 82 | |
---|
[6756] | 83 | password = schema.Password( |
---|
| 84 | title = u'New password', |
---|
| 85 | required = False, |
---|
[7124] | 86 | constraint = validPassword, |
---|
[6756] | 87 | ) |
---|
| 88 | |
---|
| 89 | password_repeat = schema.Password( |
---|
| 90 | title = u'Retype new password', |
---|
| 91 | required = False, |
---|
[7124] | 92 | constraint = validPassword, |
---|
[6756] | 93 | ) |
---|
| 94 | |
---|
| 95 | @invariant |
---|
| 96 | def passwords_match(obj): |
---|
| 97 | if obj.password == obj.password_repeat: |
---|
| 98 | return |
---|
| 99 | raise Invalid('passwords do not match') |
---|
| 100 | |
---|
[6631] | 101 | class IStudentBase(IWAeUPObject): |
---|
| 102 | """Representation of student base data. |
---|
[6621] | 103 | """ |
---|
[7062] | 104 | history = Attribute('Object history, a list of messages') |
---|
[6637] | 105 | state = Attribute('Returns the registration state of a student') |
---|
[6699] | 106 | password = Attribute('Encrypted password of a student') |
---|
[6814] | 107 | certificate = Attribute('The certificate of any chosen study course') |
---|
[7062] | 108 | current_session = Attribute('The current session of the student') |
---|
[6637] | 109 | |
---|
| 110 | def loggerInfo(ob_class, comment): |
---|
| 111 | """Adds an INFO message to the log file |
---|
| 112 | """ |
---|
| 113 | |
---|
[6665] | 114 | student_id = schema.TextLine( |
---|
| 115 | title = u'Student ID', |
---|
[6849] | 116 | required = False, |
---|
[6665] | 117 | ) |
---|
| 118 | |
---|
[6818] | 119 | fullname = schema.TextLine( |
---|
[6631] | 120 | title = u'Full Name', |
---|
[6818] | 121 | default = None, |
---|
[6621] | 122 | required = True, |
---|
| 123 | ) |
---|
| 124 | |
---|
[6996] | 125 | sex = schema.Choice( |
---|
| 126 | title = u'Sex', |
---|
| 127 | source = GenderSource(), |
---|
| 128 | default = u'm', |
---|
| 129 | required = True, |
---|
| 130 | ) |
---|
| 131 | |
---|
[6788] | 132 | reg_number = TextLineChoice( |
---|
[6696] | 133 | title = u'Registration Number', |
---|
[6818] | 134 | default = None, |
---|
[6696] | 135 | required = True, |
---|
| 136 | readonly = False, |
---|
[6788] | 137 | source = contextual_reg_num_source, |
---|
[6696] | 138 | ) |
---|
| 139 | |
---|
[6788] | 140 | matric_number = TextLineChoice( |
---|
[6750] | 141 | title = u'Matriculation Number', |
---|
[6788] | 142 | #default = u'', |
---|
[6750] | 143 | required = False, |
---|
| 144 | readonly = False, |
---|
[6788] | 145 | source = contextual_mat_num_source, |
---|
[6750] | 146 | ) |
---|
| 147 | |
---|
[6769] | 148 | adm_code = schema.TextLine( |
---|
[6935] | 149 | title = u'PWD Activation Code', |
---|
[6769] | 150 | default = u'', |
---|
| 151 | required = False, |
---|
| 152 | readonly = True, |
---|
| 153 | ) |
---|
| 154 | |
---|
[7133] | 155 | email = schema.ASCIILine( |
---|
| 156 | title = u'Email', |
---|
| 157 | required = False, |
---|
| 158 | constraint=validate_email, |
---|
| 159 | ) |
---|
| 160 | phone = schema.Int( |
---|
| 161 | title = u'Phone', |
---|
| 162 | description = u'Enter phone number with country code and without spaces.', |
---|
| 163 | required = False, |
---|
| 164 | ) |
---|
| 165 | |
---|
[6631] | 166 | class IStudentClearance(IWAeUPObject): |
---|
| 167 | """Representation of student clearance data. |
---|
| 168 | """ |
---|
[6622] | 169 | |
---|
[6631] | 170 | date_of_birth = schema.Date( |
---|
| 171 | title = u'Date of Birth', |
---|
| 172 | required = True, |
---|
| 173 | ) |
---|
| 174 | |
---|
[6695] | 175 | clearance_locked = schema.Bool( |
---|
| 176 | title = u'Clearance form locked', |
---|
| 177 | default = False, |
---|
| 178 | ) |
---|
| 179 | |
---|
[6769] | 180 | clr_code = schema.TextLine( |
---|
[6935] | 181 | title = u'CLR Activation Code', |
---|
[6769] | 182 | default = u'', |
---|
| 183 | required = False, |
---|
| 184 | readonly = True, |
---|
| 185 | ) |
---|
| 186 | |
---|
[6631] | 187 | class IStudentPersonal(IWAeUPObject): |
---|
| 188 | """Representation of student personal data. |
---|
| 189 | """ |
---|
| 190 | |
---|
[6651] | 191 | perm_address = schema.Text( |
---|
[6631] | 192 | title = u'Permanent Address', |
---|
| 193 | required = False, |
---|
| 194 | ) |
---|
| 195 | |
---|
| 196 | class IStudent(IStudentBase,IStudentClearance,IStudentPersonal): |
---|
| 197 | """Representation of a student. |
---|
| 198 | """ |
---|
| 199 | |
---|
[6849] | 200 | class IStudentUpdateByRegNo(IStudent): |
---|
| 201 | """Representation of a student. Skip regular reg_number validation. |
---|
| 202 | """ |
---|
| 203 | |
---|
| 204 | reg_number = schema.TextLine( |
---|
| 205 | title = u'Registration Number', |
---|
| 206 | default = None, |
---|
| 207 | required = False, |
---|
| 208 | ) |
---|
| 209 | |
---|
| 210 | class IStudentUpdateByMatricNo(IStudent): |
---|
| 211 | """Representation of a student. Skip regular matric_number validation. |
---|
| 212 | """ |
---|
| 213 | |
---|
| 214 | matric_number = schema.TextLine( |
---|
| 215 | title = u'Matriculation Number', |
---|
| 216 | default = None, |
---|
| 217 | required = False, |
---|
| 218 | ) |
---|
| 219 | |
---|
[6633] | 220 | class IStudentStudyCourse(IWAeUPObject): |
---|
| 221 | """A container for student study levels. |
---|
| 222 | |
---|
| 223 | """ |
---|
| 224 | |
---|
[6648] | 225 | certificate = schema.Choice( |
---|
| 226 | title = u'Certificate', |
---|
| 227 | source = CertificateSource(), |
---|
| 228 | default = None, |
---|
[6633] | 229 | required = True, |
---|
| 230 | ) |
---|
[6635] | 231 | |
---|
[6996] | 232 | |
---|
| 233 | entry_mode = schema.Choice( |
---|
| 234 | title = u'Entry Mode', |
---|
| 235 | vocabulary = study_modes, |
---|
| 236 | default = u'ug_ft', |
---|
| 237 | required = True, |
---|
| 238 | readonly = False, |
---|
| 239 | ) |
---|
| 240 | |
---|
| 241 | entry_session = schema.Choice( |
---|
| 242 | title = u'Entry Session', |
---|
| 243 | source = academic_sessions_vocab, |
---|
| 244 | default = datetime.now().year, |
---|
| 245 | required = True, |
---|
| 246 | readonly = False, |
---|
| 247 | ) |
---|
| 248 | |
---|
[6724] | 249 | current_session = schema.Choice( |
---|
| 250 | title = u'Current Session', |
---|
[6744] | 251 | source = academic_sessions_vocab, |
---|
[6724] | 252 | default = None, |
---|
| 253 | required = True, |
---|
[6996] | 254 | readonly = False, |
---|
[6724] | 255 | ) |
---|
| 256 | |
---|
| 257 | current_level = schema.Choice( |
---|
| 258 | title = u'Current Level', |
---|
[6725] | 259 | source = StudyLevelSource(), |
---|
[6724] | 260 | default = None, |
---|
[6725] | 261 | required = False, |
---|
[6996] | 262 | readonly = False, |
---|
[6724] | 263 | ) |
---|
| 264 | |
---|
| 265 | current_verdict = schema.Choice( |
---|
| 266 | title = u'Current Verdict', |
---|
| 267 | source = verdicts, |
---|
[6804] | 268 | default = '0', |
---|
[6725] | 269 | required = False, |
---|
[6724] | 270 | ) |
---|
| 271 | |
---|
| 272 | previous_verdict = schema.Choice( |
---|
| 273 | title = u'Previous Verdict', |
---|
| 274 | source = verdicts, |
---|
[6805] | 275 | default = '0', |
---|
[6725] | 276 | required = False, |
---|
[6724] | 277 | ) |
---|
| 278 | |
---|
[6825] | 279 | class IStudentStudyCourseImport(IStudentStudyCourse): |
---|
| 280 | """A container for student study levels. |
---|
| 281 | |
---|
| 282 | """ |
---|
| 283 | |
---|
| 284 | current_level = schema.Int( |
---|
| 285 | title = u'Current Level', |
---|
| 286 | default = None, |
---|
| 287 | ) |
---|
| 288 | |
---|
[6774] | 289 | class IStudentStudyLevel(IWAeUPObject): |
---|
| 290 | """A container for course tickets. |
---|
| 291 | |
---|
| 292 | """ |
---|
| 293 | level = Attribute('The level code') |
---|
[6793] | 294 | validation_date = Attribute('The date of validation') |
---|
| 295 | validated_by = Attribute('User Id of course adviser') |
---|
[6774] | 296 | |
---|
[6793] | 297 | level_session = schema.Choice( |
---|
| 298 | title = u'Session', |
---|
| 299 | source = academic_sessions_vocab, |
---|
| 300 | default = None, |
---|
| 301 | required = True, |
---|
| 302 | ) |
---|
[6781] | 303 | |
---|
[6793] | 304 | level_verdict = schema.Choice( |
---|
| 305 | title = u'Verdict', |
---|
| 306 | source = verdicts, |
---|
[6805] | 307 | default = '0', |
---|
[6793] | 308 | required = False, |
---|
| 309 | ) |
---|
| 310 | |
---|
[6781] | 311 | class ICourseTicket(IWAeUPObject): |
---|
| 312 | """A course ticket. |
---|
| 313 | |
---|
| 314 | """ |
---|
[6783] | 315 | code = Attribute('code of the original course') |
---|
| 316 | title = Attribute('title of the original course') |
---|
| 317 | credits = Attribute('credits of the original course') |
---|
| 318 | passmark = Attribute('passmark of the original course') |
---|
| 319 | semester = Attribute('semester of the original course') |
---|
| 320 | faculty = Attribute('faculty of the original course') |
---|
| 321 | department = Attribute('department of the original course') |
---|
[6781] | 322 | |
---|
[6795] | 323 | core_or_elective = schema.Bool( |
---|
| 324 | title = u'Mandatory', |
---|
| 325 | default = False, |
---|
| 326 | required = False, |
---|
| 327 | readonly = False, |
---|
| 328 | ) |
---|
| 329 | |
---|
[6781] | 330 | score = schema.Int( |
---|
| 331 | title = u'Score', |
---|
| 332 | default = 0, |
---|
| 333 | required = False, |
---|
| 334 | readonly = False, |
---|
| 335 | ) |
---|
| 336 | |
---|
[6806] | 337 | automatic = schema.Bool( |
---|
| 338 | title = u'Automatical Creation', |
---|
| 339 | default = False, |
---|
| 340 | required = False, |
---|
| 341 | readonly = True, |
---|
| 342 | ) |
---|
| 343 | |
---|
[6795] | 344 | class ICourseTicketAdd(ICourseTicket): |
---|
| 345 | """An interface for adding course tickets |
---|
| 346 | |
---|
| 347 | """ |
---|
| 348 | course = schema.Choice( |
---|
| 349 | title = u'Course', |
---|
| 350 | source = CourseSource(), |
---|
| 351 | readonly = False, |
---|
| 352 | ) |
---|
| 353 | |
---|
[6635] | 354 | class IStudentAccommodation(IWAeUPObject): |
---|
| 355 | """A container for student accommodation objects. |
---|
| 356 | |
---|
| 357 | """ |
---|
| 358 | |
---|
[6989] | 359 | class IBedTicket(IWAeUPObject): |
---|
| 360 | """A ticket for accommodation booking. |
---|
| 361 | |
---|
| 362 | """ |
---|
| 363 | |
---|
[6996] | 364 | bed = Attribute('The bed object.') |
---|
| 365 | |
---|
| 366 | bed_coordinates = schema.TextLine( |
---|
| 367 | title = u'Bed Coordinates', |
---|
[6992] | 368 | default = None, |
---|
| 369 | required = False, |
---|
[7014] | 370 | readonly = False, |
---|
[6992] | 371 | ) |
---|
| 372 | |
---|
[6996] | 373 | bed_type = schema.TextLine( |
---|
| 374 | title = u'Bed Type', |
---|
| 375 | default = None, |
---|
| 376 | required = False, |
---|
[7014] | 377 | readonly = False, |
---|
[6996] | 378 | ) |
---|
| 379 | |
---|
[6992] | 380 | booking_session = schema.Choice( |
---|
| 381 | title = u'Session', |
---|
| 382 | source = academic_sessions_vocab, |
---|
| 383 | default = None, |
---|
| 384 | required = True, |
---|
[7014] | 385 | readonly = True, |
---|
[6992] | 386 | ) |
---|
| 387 | |
---|
| 388 | booking_date = schema.Datetime( |
---|
| 389 | title = u'Booking Date', |
---|
| 390 | required = False, |
---|
[7014] | 391 | readonly = True, |
---|
[6992] | 392 | ) |
---|
| 393 | |
---|
| 394 | booking_code = schema.TextLine( |
---|
| 395 | title = u'Booking Activation Code', |
---|
| 396 | default = u'', |
---|
| 397 | required = False, |
---|
[7014] | 398 | readonly = True, |
---|
[6992] | 399 | ) |
---|
| 400 | |
---|
[6994] | 401 | def getSessionString(): |
---|
| 402 | """Returns the the title of academic_sessions_vocab term |
---|
| 403 | """ |
---|
[6992] | 404 | |
---|
[6860] | 405 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
[6635] | 406 | """A container for student payment objects. |
---|
| 407 | |
---|
| 408 | """ |
---|
| 409 | |
---|
[6877] | 410 | class IStudentOnlinePayment(IOnlinePayment): |
---|
| 411 | """A student payment via payment gateways. |
---|
| 412 | |
---|
| 413 | """ |
---|
| 414 | |
---|
| 415 | p_session = schema.Choice( |
---|
| 416 | title = u'Payment Session', |
---|
| 417 | source = academic_sessions_vocab, |
---|
| 418 | required = False, |
---|
| 419 | ) |
---|
| 420 | |
---|
| 421 | IStudentOnlinePayment['p_session'].order = IStudentOnlinePayment[ |
---|
| 422 | 'p_item'].order |
---|
| 423 | |
---|
[6694] | 424 | # Interfaces for students only |
---|
| 425 | |
---|
| 426 | class IStudentClearanceEdit(IStudentClearance): |
---|
| 427 | """Interface needed for restricted editing of student clearance data. |
---|
| 428 | """ |
---|
| 429 | |
---|
| 430 | class IStudentPersonalEdit(IStudentPersonal): |
---|
| 431 | """Interface needed for restricted editing of student personal data. |
---|
| 432 | """ |
---|