[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 | |
---|
[6631] | 76 | class IStudentBase(IWAeUPObject): |
---|
| 77 | """Representation of student base data. |
---|
[6621] | 78 | """ |
---|
[7062] | 79 | history = Attribute('Object history, a list of messages') |
---|
[6637] | 80 | state = Attribute('Returns the registration state of a student') |
---|
[6699] | 81 | password = Attribute('Encrypted password of a student') |
---|
[6814] | 82 | certificate = Attribute('The certificate of any chosen study course') |
---|
[7062] | 83 | current_session = Attribute('The current session of the student') |
---|
[6637] | 84 | |
---|
| 85 | def loggerInfo(ob_class, comment): |
---|
| 86 | """Adds an INFO message to the log file |
---|
| 87 | """ |
---|
| 88 | |
---|
[6665] | 89 | student_id = schema.TextLine( |
---|
| 90 | title = u'Student ID', |
---|
[6849] | 91 | required = False, |
---|
[6665] | 92 | ) |
---|
| 93 | |
---|
[6818] | 94 | fullname = schema.TextLine( |
---|
[6631] | 95 | title = u'Full Name', |
---|
[6818] | 96 | default = None, |
---|
[6621] | 97 | required = True, |
---|
| 98 | ) |
---|
| 99 | |
---|
[6996] | 100 | sex = schema.Choice( |
---|
| 101 | title = u'Sex', |
---|
| 102 | source = GenderSource(), |
---|
| 103 | default = u'm', |
---|
| 104 | required = True, |
---|
| 105 | ) |
---|
| 106 | |
---|
[6788] | 107 | reg_number = TextLineChoice( |
---|
[6696] | 108 | title = u'Registration Number', |
---|
[6818] | 109 | default = None, |
---|
[6696] | 110 | required = True, |
---|
| 111 | readonly = False, |
---|
[6788] | 112 | source = contextual_reg_num_source, |
---|
[6696] | 113 | ) |
---|
| 114 | |
---|
[6788] | 115 | matric_number = TextLineChoice( |
---|
[6750] | 116 | title = u'Matriculation Number', |
---|
[6788] | 117 | #default = u'', |
---|
[6750] | 118 | required = False, |
---|
| 119 | readonly = False, |
---|
[6788] | 120 | source = contextual_mat_num_source, |
---|
[6750] | 121 | ) |
---|
| 122 | |
---|
[6769] | 123 | adm_code = schema.TextLine( |
---|
[6935] | 124 | title = u'PWD Activation Code', |
---|
[6769] | 125 | default = u'', |
---|
| 126 | required = False, |
---|
| 127 | readonly = True, |
---|
| 128 | ) |
---|
| 129 | |
---|
[7133] | 130 | email = schema.ASCIILine( |
---|
| 131 | title = u'Email', |
---|
| 132 | required = False, |
---|
| 133 | constraint=validate_email, |
---|
| 134 | ) |
---|
| 135 | phone = schema.Int( |
---|
| 136 | title = u'Phone', |
---|
| 137 | description = u'Enter phone number with country code and without spaces.', |
---|
| 138 | required = False, |
---|
| 139 | ) |
---|
| 140 | |
---|
[6631] | 141 | class IStudentClearance(IWAeUPObject): |
---|
| 142 | """Representation of student clearance data. |
---|
| 143 | """ |
---|
[6622] | 144 | |
---|
[6631] | 145 | date_of_birth = schema.Date( |
---|
| 146 | title = u'Date of Birth', |
---|
| 147 | required = True, |
---|
| 148 | ) |
---|
| 149 | |
---|
[6695] | 150 | clearance_locked = schema.Bool( |
---|
| 151 | title = u'Clearance form locked', |
---|
| 152 | default = False, |
---|
| 153 | ) |
---|
| 154 | |
---|
[6769] | 155 | clr_code = schema.TextLine( |
---|
[6935] | 156 | title = u'CLR Activation Code', |
---|
[6769] | 157 | default = u'', |
---|
| 158 | required = False, |
---|
| 159 | readonly = True, |
---|
| 160 | ) |
---|
| 161 | |
---|
[6631] | 162 | class IStudentPersonal(IWAeUPObject): |
---|
| 163 | """Representation of student personal data. |
---|
| 164 | """ |
---|
| 165 | |
---|
[6651] | 166 | perm_address = schema.Text( |
---|
[6631] | 167 | title = u'Permanent Address', |
---|
| 168 | required = False, |
---|
| 169 | ) |
---|
| 170 | |
---|
| 171 | class IStudent(IStudentBase,IStudentClearance,IStudentPersonal): |
---|
| 172 | """Representation of a student. |
---|
| 173 | """ |
---|
| 174 | |
---|
[6849] | 175 | class IStudentUpdateByRegNo(IStudent): |
---|
| 176 | """Representation of a student. Skip regular reg_number validation. |
---|
| 177 | """ |
---|
| 178 | |
---|
| 179 | reg_number = schema.TextLine( |
---|
| 180 | title = u'Registration Number', |
---|
| 181 | default = None, |
---|
| 182 | required = False, |
---|
| 183 | ) |
---|
| 184 | |
---|
| 185 | class IStudentUpdateByMatricNo(IStudent): |
---|
| 186 | """Representation of a student. Skip regular matric_number validation. |
---|
| 187 | """ |
---|
| 188 | |
---|
| 189 | matric_number = schema.TextLine( |
---|
| 190 | title = u'Matriculation Number', |
---|
| 191 | default = None, |
---|
| 192 | required = False, |
---|
| 193 | ) |
---|
| 194 | |
---|
[6633] | 195 | class IStudentStudyCourse(IWAeUPObject): |
---|
| 196 | """A container for student study levels. |
---|
| 197 | |
---|
| 198 | """ |
---|
| 199 | |
---|
[6648] | 200 | certificate = schema.Choice( |
---|
| 201 | title = u'Certificate', |
---|
| 202 | source = CertificateSource(), |
---|
| 203 | default = None, |
---|
[6633] | 204 | required = True, |
---|
| 205 | ) |
---|
[6635] | 206 | |
---|
[6996] | 207 | |
---|
| 208 | entry_mode = schema.Choice( |
---|
| 209 | title = u'Entry Mode', |
---|
| 210 | vocabulary = study_modes, |
---|
| 211 | default = u'ug_ft', |
---|
| 212 | required = True, |
---|
| 213 | readonly = False, |
---|
| 214 | ) |
---|
| 215 | |
---|
| 216 | entry_session = schema.Choice( |
---|
| 217 | title = u'Entry Session', |
---|
| 218 | source = academic_sessions_vocab, |
---|
| 219 | default = datetime.now().year, |
---|
| 220 | required = True, |
---|
| 221 | readonly = False, |
---|
| 222 | ) |
---|
| 223 | |
---|
[6724] | 224 | current_session = schema.Choice( |
---|
| 225 | title = u'Current Session', |
---|
[6744] | 226 | source = academic_sessions_vocab, |
---|
[6724] | 227 | default = None, |
---|
| 228 | required = True, |
---|
[6996] | 229 | readonly = False, |
---|
[6724] | 230 | ) |
---|
| 231 | |
---|
| 232 | current_level = schema.Choice( |
---|
| 233 | title = u'Current Level', |
---|
[6725] | 234 | source = StudyLevelSource(), |
---|
[6724] | 235 | default = None, |
---|
[6725] | 236 | required = False, |
---|
[6996] | 237 | readonly = False, |
---|
[6724] | 238 | ) |
---|
| 239 | |
---|
| 240 | current_verdict = schema.Choice( |
---|
| 241 | title = u'Current Verdict', |
---|
| 242 | source = verdicts, |
---|
[6804] | 243 | default = '0', |
---|
[6725] | 244 | required = False, |
---|
[6724] | 245 | ) |
---|
| 246 | |
---|
| 247 | previous_verdict = schema.Choice( |
---|
| 248 | title = u'Previous Verdict', |
---|
| 249 | source = verdicts, |
---|
[6805] | 250 | default = '0', |
---|
[6725] | 251 | required = False, |
---|
[6724] | 252 | ) |
---|
| 253 | |
---|
[6825] | 254 | class IStudentStudyCourseImport(IStudentStudyCourse): |
---|
| 255 | """A container for student study levels. |
---|
| 256 | |
---|
| 257 | """ |
---|
| 258 | |
---|
| 259 | current_level = schema.Int( |
---|
| 260 | title = u'Current Level', |
---|
| 261 | default = None, |
---|
| 262 | ) |
---|
| 263 | |
---|
[6774] | 264 | class IStudentStudyLevel(IWAeUPObject): |
---|
| 265 | """A container for course tickets. |
---|
| 266 | |
---|
| 267 | """ |
---|
| 268 | level = Attribute('The level code') |
---|
[6793] | 269 | validation_date = Attribute('The date of validation') |
---|
| 270 | validated_by = Attribute('User Id of course adviser') |
---|
[6774] | 271 | |
---|
[6793] | 272 | level_session = schema.Choice( |
---|
| 273 | title = u'Session', |
---|
| 274 | source = academic_sessions_vocab, |
---|
| 275 | default = None, |
---|
| 276 | required = True, |
---|
| 277 | ) |
---|
[6781] | 278 | |
---|
[6793] | 279 | level_verdict = schema.Choice( |
---|
| 280 | title = u'Verdict', |
---|
| 281 | source = verdicts, |
---|
[6805] | 282 | default = '0', |
---|
[6793] | 283 | required = False, |
---|
| 284 | ) |
---|
| 285 | |
---|
[6781] | 286 | class ICourseTicket(IWAeUPObject): |
---|
| 287 | """A course ticket. |
---|
| 288 | |
---|
| 289 | """ |
---|
[6783] | 290 | code = Attribute('code of the original course') |
---|
| 291 | title = Attribute('title of the original course') |
---|
| 292 | credits = Attribute('credits of the original course') |
---|
| 293 | passmark = Attribute('passmark of the original course') |
---|
| 294 | semester = Attribute('semester of the original course') |
---|
| 295 | faculty = Attribute('faculty of the original course') |
---|
| 296 | department = Attribute('department of the original course') |
---|
[6781] | 297 | |
---|
[6795] | 298 | core_or_elective = schema.Bool( |
---|
| 299 | title = u'Mandatory', |
---|
| 300 | default = False, |
---|
| 301 | required = False, |
---|
| 302 | readonly = False, |
---|
| 303 | ) |
---|
| 304 | |
---|
[6781] | 305 | score = schema.Int( |
---|
| 306 | title = u'Score', |
---|
| 307 | default = 0, |
---|
| 308 | required = False, |
---|
| 309 | readonly = False, |
---|
| 310 | ) |
---|
| 311 | |
---|
[6806] | 312 | automatic = schema.Bool( |
---|
| 313 | title = u'Automatical Creation', |
---|
| 314 | default = False, |
---|
| 315 | required = False, |
---|
| 316 | readonly = True, |
---|
| 317 | ) |
---|
| 318 | |
---|
[6795] | 319 | class ICourseTicketAdd(ICourseTicket): |
---|
| 320 | """An interface for adding course tickets |
---|
| 321 | |
---|
| 322 | """ |
---|
| 323 | course = schema.Choice( |
---|
| 324 | title = u'Course', |
---|
| 325 | source = CourseSource(), |
---|
| 326 | readonly = False, |
---|
| 327 | ) |
---|
| 328 | |
---|
[6635] | 329 | class IStudentAccommodation(IWAeUPObject): |
---|
| 330 | """A container for student accommodation objects. |
---|
| 331 | |
---|
| 332 | """ |
---|
| 333 | |
---|
[6989] | 334 | class IBedTicket(IWAeUPObject): |
---|
| 335 | """A ticket for accommodation booking. |
---|
| 336 | |
---|
| 337 | """ |
---|
| 338 | |
---|
[6996] | 339 | bed = Attribute('The bed object.') |
---|
| 340 | |
---|
| 341 | bed_coordinates = schema.TextLine( |
---|
| 342 | title = u'Bed Coordinates', |
---|
[6992] | 343 | default = None, |
---|
| 344 | required = False, |
---|
[7014] | 345 | readonly = False, |
---|
[6992] | 346 | ) |
---|
| 347 | |
---|
[6996] | 348 | bed_type = schema.TextLine( |
---|
| 349 | title = u'Bed Type', |
---|
| 350 | default = None, |
---|
| 351 | required = False, |
---|
[7014] | 352 | readonly = False, |
---|
[6996] | 353 | ) |
---|
| 354 | |
---|
[6992] | 355 | booking_session = schema.Choice( |
---|
| 356 | title = u'Session', |
---|
| 357 | source = academic_sessions_vocab, |
---|
| 358 | default = None, |
---|
| 359 | required = True, |
---|
[7014] | 360 | readonly = True, |
---|
[6992] | 361 | ) |
---|
| 362 | |
---|
| 363 | booking_date = schema.Datetime( |
---|
| 364 | title = u'Booking Date', |
---|
| 365 | required = False, |
---|
[7014] | 366 | readonly = True, |
---|
[6992] | 367 | ) |
---|
| 368 | |
---|
| 369 | booking_code = schema.TextLine( |
---|
| 370 | title = u'Booking Activation Code', |
---|
| 371 | default = u'', |
---|
| 372 | required = False, |
---|
[7014] | 373 | readonly = True, |
---|
[6992] | 374 | ) |
---|
| 375 | |
---|
[6994] | 376 | def getSessionString(): |
---|
| 377 | """Returns the the title of academic_sessions_vocab term |
---|
| 378 | """ |
---|
[6992] | 379 | |
---|
[6860] | 380 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
[6635] | 381 | """A container for student payment objects. |
---|
| 382 | |
---|
| 383 | """ |
---|
| 384 | |
---|
[6877] | 385 | class IStudentOnlinePayment(IOnlinePayment): |
---|
| 386 | """A student payment via payment gateways. |
---|
| 387 | |
---|
| 388 | """ |
---|
| 389 | |
---|
| 390 | p_session = schema.Choice( |
---|
| 391 | title = u'Payment Session', |
---|
| 392 | source = academic_sessions_vocab, |
---|
| 393 | required = False, |
---|
| 394 | ) |
---|
| 395 | |
---|
| 396 | IStudentOnlinePayment['p_session'].order = IStudentOnlinePayment[ |
---|
| 397 | 'p_item'].order |
---|
| 398 | |
---|
[6694] | 399 | # Interfaces for students only |
---|
| 400 | |
---|
| 401 | class IStudentClearanceEdit(IStudentClearance): |
---|
| 402 | """Interface needed for restricted editing of student clearance data. |
---|
| 403 | """ |
---|
| 404 | |
---|
| 405 | class IStudentPersonalEdit(IStudentPersonal): |
---|
| 406 | """Interface needed for restricted editing of student personal data. |
---|
| 407 | """ |
---|