1 | ## $Id: interfaces.py 9182 2012-09-14 05:31:47Z henrik $ |
---|
2 | ## |
---|
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 | ## |
---|
18 | #from datetime import datetime |
---|
19 | from zope.component import getUtility |
---|
20 | from zope.interface import Attribute, Interface |
---|
21 | from zope import schema |
---|
22 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
23 | from waeup.kofa.interfaces import ( |
---|
24 | IKofaObject, academic_sessions_vocab, validate_email, ICSVExporter) |
---|
25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
26 | from waeup.kofa.schema import TextLineChoice, FormattedDate, PhoneNumber |
---|
27 | from waeup.kofa.students.vocabularies import ( |
---|
28 | StudyLevelSource, contextual_reg_num_source, contextual_mat_num_source, |
---|
29 | GenderSource, nats_vocab, |
---|
30 | ) |
---|
31 | from waeup.kofa.payments.interfaces import ( |
---|
32 | IPaymentsContainer, IOnlinePayment) |
---|
33 | from waeup.kofa.university.vocabularies import ( |
---|
34 | CourseSource, StudyModeSource, CertificateSource) |
---|
35 | |
---|
36 | # VerdictSource can't be placed into the vocabularies module because it |
---|
37 | # requires importing IStudentsUtils which then leads to circular imports. |
---|
38 | class VerdictSource(BasicContextualSourceFactory): |
---|
39 | """A verdicts source delivers all verdicts provided |
---|
40 | in the portal. |
---|
41 | """ |
---|
42 | def getValues(self, context): |
---|
43 | verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT |
---|
44 | return sorted(verdicts_dict.keys()) |
---|
45 | |
---|
46 | def getToken(self, context, value): |
---|
47 | return value |
---|
48 | |
---|
49 | def getTitle(self, context, value): |
---|
50 | verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT |
---|
51 | if value != '0': |
---|
52 | return verdicts_dict[value] + ' (%s)' % value |
---|
53 | return verdicts_dict[value] |
---|
54 | |
---|
55 | |
---|
56 | class IStudentsUtils(Interface): |
---|
57 | """A collection of methods which are subject to customization. |
---|
58 | |
---|
59 | """ |
---|
60 | def setReturningData(student): |
---|
61 | """ This method defines what happens after school fee payment |
---|
62 | depending on the student's senate verdict. |
---|
63 | |
---|
64 | In the base configuration current level is always increased |
---|
65 | by 100 no matter which verdict has been assigned. |
---|
66 | """ |
---|
67 | |
---|
68 | def setPaymentDetails(category, student, previous_session=None, |
---|
69 | previous_level=None,): |
---|
70 | """Create Payment object and set the payment data of a student for |
---|
71 | the payment category specified. |
---|
72 | |
---|
73 | """ |
---|
74 | |
---|
75 | def getAccommodation_details(student): |
---|
76 | """Determine the accommodation dates of a student. |
---|
77 | |
---|
78 | """ |
---|
79 | |
---|
80 | def selectBed(available_beds): |
---|
81 | """Select a bed from a list of available beds. |
---|
82 | |
---|
83 | In the standard configuration we select the first bed found, |
---|
84 | but can also randomize the selection if we like. |
---|
85 | """ |
---|
86 | |
---|
87 | def renderPDF(view, subject='', filename='slip.pdf',): |
---|
88 | """Render pdf slips for various pages. |
---|
89 | |
---|
90 | """ |
---|
91 | |
---|
92 | class IStudentsContainer(IKofaObject): |
---|
93 | """A students container contains university students. |
---|
94 | |
---|
95 | """ |
---|
96 | def addStudent(student): |
---|
97 | """Add an IStudent object and subcontainers. |
---|
98 | |
---|
99 | """ |
---|
100 | |
---|
101 | def archive(id=None): |
---|
102 | """Create on-dist archive of students. |
---|
103 | |
---|
104 | If id is `None`, all students are archived. |
---|
105 | |
---|
106 | If id contains a single id string, only the respective |
---|
107 | students are archived. |
---|
108 | |
---|
109 | If id contains a list of id strings all of the respective |
---|
110 | students types are saved to disk. |
---|
111 | """ |
---|
112 | |
---|
113 | def clear(id=None, archive=True): |
---|
114 | """Remove students of type given by 'id'. |
---|
115 | |
---|
116 | Optionally archive the students. |
---|
117 | |
---|
118 | If id is `None`, all students are archived. |
---|
119 | |
---|
120 | If id contains a single id string, only the respective |
---|
121 | students are archived. |
---|
122 | |
---|
123 | If id contains a list of id strings all of the respective |
---|
124 | student types are saved to disk. |
---|
125 | |
---|
126 | If `archive` is ``False`` none of the archive-handling is done |
---|
127 | and respective students are simply removed from the |
---|
128 | database. |
---|
129 | """ |
---|
130 | |
---|
131 | unique_student_id = Attribute("""A unique student id.""") |
---|
132 | |
---|
133 | class IStudentNavigation(IKofaObject): |
---|
134 | """Interface needed for student navigation, logging, etc. |
---|
135 | |
---|
136 | """ |
---|
137 | student = Attribute('Student object of context.') |
---|
138 | |
---|
139 | def writeLogMessage(view, message): |
---|
140 | """Write a view specific log message into students.log. |
---|
141 | |
---|
142 | """ |
---|
143 | |
---|
144 | class IStudentBase(IKofaObject): |
---|
145 | """Representation of student base data. |
---|
146 | |
---|
147 | """ |
---|
148 | history = Attribute('Object history, a list of messages') |
---|
149 | state = Attribute('Returns the registration state of a student') |
---|
150 | password = Attribute('Encrypted password of a student') |
---|
151 | certcode = Attribute('The certificate code of any chosen study course') |
---|
152 | depcode = Attribute('The department code of any chosen study course') |
---|
153 | faccode = Attribute('The faculty code of any chosen study course') |
---|
154 | current_session = Attribute('The current session of the student') |
---|
155 | current_level = Attribute('The current level of the student') |
---|
156 | current_mode = Attribute('The current mode of the student') |
---|
157 | current_verdict = Attribute('The current verdict of the student') |
---|
158 | fullname = Attribute('All name parts separated by hyphens') |
---|
159 | display_fullname = Attribute('The fullname of an applicant') |
---|
160 | is_postgrad = Attribute('True if postgraduate student') |
---|
161 | |
---|
162 | suspended = schema.Bool( |
---|
163 | title = _(u'Account suspended'), |
---|
164 | default = False, |
---|
165 | required = False, |
---|
166 | ) |
---|
167 | |
---|
168 | student_id = schema.TextLine( |
---|
169 | title = _(u'Student Id'), |
---|
170 | required = False, |
---|
171 | ) |
---|
172 | |
---|
173 | firstname = schema.TextLine( |
---|
174 | title = _(u'First Name'), |
---|
175 | required = True, |
---|
176 | ) |
---|
177 | |
---|
178 | middlename = schema.TextLine( |
---|
179 | title = _(u'Middle Name'), |
---|
180 | required = False, |
---|
181 | ) |
---|
182 | |
---|
183 | lastname = schema.TextLine( |
---|
184 | title = _(u'Last Name (Surname)'), |
---|
185 | required = True, |
---|
186 | ) |
---|
187 | |
---|
188 | sex = schema.Choice( |
---|
189 | title = _(u'Sex'), |
---|
190 | source = GenderSource(), |
---|
191 | required = True, |
---|
192 | ) |
---|
193 | |
---|
194 | reg_number = TextLineChoice( |
---|
195 | title = _(u'Registration Number'), |
---|
196 | required = True, |
---|
197 | readonly = False, |
---|
198 | source = contextual_reg_num_source, |
---|
199 | ) |
---|
200 | |
---|
201 | matric_number = TextLineChoice( |
---|
202 | title = _(u'Matriculation Number'), |
---|
203 | required = False, |
---|
204 | readonly = False, |
---|
205 | source = contextual_mat_num_source, |
---|
206 | ) |
---|
207 | |
---|
208 | adm_code = schema.TextLine( |
---|
209 | title = _(u'PWD Activation Code'), |
---|
210 | required = False, |
---|
211 | readonly = False, |
---|
212 | ) |
---|
213 | |
---|
214 | email = schema.ASCIILine( |
---|
215 | title = _(u'Email'), |
---|
216 | required = False, |
---|
217 | constraint=validate_email, |
---|
218 | ) |
---|
219 | phone = PhoneNumber( |
---|
220 | title = _(u'Phone'), |
---|
221 | description = u'', |
---|
222 | required = False, |
---|
223 | ) |
---|
224 | |
---|
225 | def transfer(certificate, current_session, |
---|
226 | current_level, current_verdict): |
---|
227 | """ Creates a new studycourse and backups the old one. |
---|
228 | |
---|
229 | """ |
---|
230 | |
---|
231 | class IUGStudentClearance(IKofaObject): |
---|
232 | """Representation of undergraduate student clearance data. |
---|
233 | |
---|
234 | """ |
---|
235 | date_of_birth = FormattedDate( |
---|
236 | title = _(u'Date of Birth'), |
---|
237 | required = True, |
---|
238 | show_year = True, |
---|
239 | ) |
---|
240 | |
---|
241 | clearance_locked = schema.Bool( |
---|
242 | title = _(u'Clearance form locked'), |
---|
243 | default = False, |
---|
244 | required = False, |
---|
245 | ) |
---|
246 | |
---|
247 | clr_code = schema.TextLine( |
---|
248 | title = _(u'CLR Activation Code'), |
---|
249 | required = False, |
---|
250 | readonly = False, |
---|
251 | ) |
---|
252 | |
---|
253 | nationality = schema.Choice( |
---|
254 | vocabulary = nats_vocab, |
---|
255 | title = _(u'Nationality'), |
---|
256 | required = False, |
---|
257 | ) |
---|
258 | |
---|
259 | class IPGStudentClearance(IUGStudentClearance): |
---|
260 | """Representation of postgraduate student clearance data. |
---|
261 | |
---|
262 | """ |
---|
263 | employer = schema.TextLine( |
---|
264 | title = _(u'Employer'), |
---|
265 | required = False, |
---|
266 | readonly = False, |
---|
267 | ) |
---|
268 | |
---|
269 | class IStudentPersonal(IKofaObject): |
---|
270 | """Representation of student personal data. |
---|
271 | |
---|
272 | """ |
---|
273 | perm_address = schema.Text( |
---|
274 | title = _(u'Permanent Address'), |
---|
275 | required = False, |
---|
276 | ) |
---|
277 | |
---|
278 | class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance, |
---|
279 | IStudentPersonal): |
---|
280 | """Representation of a student. |
---|
281 | |
---|
282 | """ |
---|
283 | |
---|
284 | class IStudentUpdateByRegNo(IStudent): |
---|
285 | """Representation of a student. Skip regular reg_number validation. |
---|
286 | |
---|
287 | """ |
---|
288 | reg_number = schema.TextLine( |
---|
289 | title = _(u'Registration Number'), |
---|
290 | required = False, |
---|
291 | ) |
---|
292 | |
---|
293 | class IStudentUpdateByMatricNo(IStudent): |
---|
294 | """Representation of a student. Skip regular matric_number validation. |
---|
295 | |
---|
296 | """ |
---|
297 | matric_number = schema.TextLine( |
---|
298 | title = _(u'Matriculation Number'), |
---|
299 | required = False, |
---|
300 | ) |
---|
301 | |
---|
302 | class IStudentRequestPW(IStudent): |
---|
303 | """Representation of an student for first-time password request. |
---|
304 | |
---|
305 | This interface is used when students use the requestpw page to |
---|
306 | login for the the first time. |
---|
307 | """ |
---|
308 | number = schema.TextLine( |
---|
309 | title = _(u'Registr. or Matric. Number'), |
---|
310 | required = True, |
---|
311 | ) |
---|
312 | |
---|
313 | firstname = schema.TextLine( |
---|
314 | title = _(u'First Name'), |
---|
315 | required = True, |
---|
316 | ) |
---|
317 | |
---|
318 | email = schema.ASCIILine( |
---|
319 | title = _(u'Email Address'), |
---|
320 | required = True, |
---|
321 | constraint=validate_email, |
---|
322 | ) |
---|
323 | |
---|
324 | class IStudentStudyCourse(IKofaObject): |
---|
325 | """A container for student study levels. |
---|
326 | |
---|
327 | """ |
---|
328 | certificate = schema.Choice( |
---|
329 | title = _(u'Certificate'), |
---|
330 | source = CertificateSource(), |
---|
331 | required = False, |
---|
332 | ) |
---|
333 | |
---|
334 | entry_mode = schema.Choice( |
---|
335 | title = _(u'Entry Mode'), |
---|
336 | source = StudyModeSource(), |
---|
337 | required = True, |
---|
338 | readonly = False, |
---|
339 | ) |
---|
340 | |
---|
341 | entry_session = schema.Choice( |
---|
342 | title = _(u'Entry Session'), |
---|
343 | source = academic_sessions_vocab, |
---|
344 | #default = datetime.now().year, |
---|
345 | required = True, |
---|
346 | readonly = False, |
---|
347 | ) |
---|
348 | |
---|
349 | current_session = schema.Choice( |
---|
350 | title = _(u'Current Session'), |
---|
351 | source = academic_sessions_vocab, |
---|
352 | required = True, |
---|
353 | readonly = False, |
---|
354 | ) |
---|
355 | |
---|
356 | current_level = schema.Choice( |
---|
357 | title = _(u'Current Level'), |
---|
358 | source = StudyLevelSource(), |
---|
359 | required = False, |
---|
360 | readonly = False, |
---|
361 | ) |
---|
362 | |
---|
363 | current_verdict = schema.Choice( |
---|
364 | title = _(u'Current Verdict'), |
---|
365 | source = VerdictSource(), |
---|
366 | default = '0', |
---|
367 | required = False, |
---|
368 | ) |
---|
369 | |
---|
370 | previous_verdict = schema.Choice( |
---|
371 | title = _(u'Previous Verdict'), |
---|
372 | source = VerdictSource(), |
---|
373 | default = '0', |
---|
374 | required = False, |
---|
375 | ) |
---|
376 | |
---|
377 | class IStudentStudyCourseTransfer(IStudentStudyCourse): |
---|
378 | """An student transfers. |
---|
379 | |
---|
380 | """ |
---|
381 | |
---|
382 | certificate = schema.Choice( |
---|
383 | title = _(u'Certificate'), |
---|
384 | source = CertificateSource(), |
---|
385 | required = True, |
---|
386 | ) |
---|
387 | |
---|
388 | current_level = schema.Choice( |
---|
389 | title = _(u'Current Level'), |
---|
390 | source = StudyLevelSource(), |
---|
391 | required = True, |
---|
392 | readonly = False, |
---|
393 | ) |
---|
394 | |
---|
395 | |
---|
396 | IStudentStudyCourseTransfer['certificate'].order = IStudentStudyCourse[ |
---|
397 | 'certificate'].order |
---|
398 | IStudentStudyCourseTransfer['current_level'].order = IStudentStudyCourse[ |
---|
399 | 'current_level'].order |
---|
400 | |
---|
401 | class IStudentVerdictUpdate(IKofaObject): |
---|
402 | """A interface for verdict imports. |
---|
403 | |
---|
404 | """ |
---|
405 | |
---|
406 | current_verdict = schema.Choice( |
---|
407 | title = _(u'Current Verdict'), |
---|
408 | source = VerdictSource(), |
---|
409 | required = True, |
---|
410 | ) |
---|
411 | |
---|
412 | current_session = schema.Choice( |
---|
413 | title = _(u'Current Session'), |
---|
414 | source = academic_sessions_vocab, |
---|
415 | required = True, |
---|
416 | ) |
---|
417 | |
---|
418 | current_level = schema.Choice( |
---|
419 | title = _(u'Current Level'), |
---|
420 | source = StudyLevelSource(), |
---|
421 | required = True, |
---|
422 | ) |
---|
423 | |
---|
424 | class IStudentStudyLevel(IKofaObject): |
---|
425 | """A container for course tickets. |
---|
426 | |
---|
427 | """ |
---|
428 | level = Attribute('The level code') |
---|
429 | |
---|
430 | level_session = schema.Choice( |
---|
431 | title = _(u'Session'), |
---|
432 | source = academic_sessions_vocab, |
---|
433 | required = False, |
---|
434 | ) |
---|
435 | |
---|
436 | level_verdict = schema.Choice( |
---|
437 | title = _(u'Verdict'), |
---|
438 | source = VerdictSource(), |
---|
439 | default = '0', |
---|
440 | required = False, |
---|
441 | ) |
---|
442 | |
---|
443 | validated_by = schema.TextLine( |
---|
444 | title = _(u'Validated by'), |
---|
445 | default = None, |
---|
446 | required = False, |
---|
447 | ) |
---|
448 | |
---|
449 | validation_date = schema.Datetime( |
---|
450 | title = _(u'Validation Date'), |
---|
451 | required = False, |
---|
452 | readonly = False, |
---|
453 | ) |
---|
454 | |
---|
455 | def addCourseTicket(ticket, course): |
---|
456 | """Add a course ticket object. |
---|
457 | """ |
---|
458 | |
---|
459 | class ICourseTicket(IKofaObject): |
---|
460 | """A course ticket. |
---|
461 | |
---|
462 | """ |
---|
463 | code = Attribute('code of the original course') |
---|
464 | title = Attribute('title of the original course') |
---|
465 | credits = Attribute('credits of the original course') |
---|
466 | passmark = Attribute('passmark of the original course') |
---|
467 | semester = Attribute('semester of the original course') |
---|
468 | fcode = Attribute('faculty code of the original course') |
---|
469 | dcode = Attribute('department code of the original course') |
---|
470 | |
---|
471 | mandatory = schema.Bool( |
---|
472 | title = _(u'Mandatory'), |
---|
473 | default = False, |
---|
474 | required = False, |
---|
475 | readonly = False, |
---|
476 | ) |
---|
477 | |
---|
478 | score = schema.Int( |
---|
479 | title = _(u'Score'), |
---|
480 | default = 0, |
---|
481 | required = False, |
---|
482 | readonly = False, |
---|
483 | ) |
---|
484 | |
---|
485 | automatic = schema.Bool( |
---|
486 | title = _(u'Automatical Creation'), |
---|
487 | default = False, |
---|
488 | required = False, |
---|
489 | readonly = True, |
---|
490 | ) |
---|
491 | |
---|
492 | carry_over = schema.Bool( |
---|
493 | title = _(u'Carry-over Course'), |
---|
494 | default = False, |
---|
495 | required = False, |
---|
496 | readonly = False, |
---|
497 | ) |
---|
498 | |
---|
499 | def getLevel(): |
---|
500 | """Returns the id of the level the ticket has been added to. |
---|
501 | """ |
---|
502 | |
---|
503 | def getLevelSession(): |
---|
504 | """Returns the session of the level the ticket has been added to. |
---|
505 | """ |
---|
506 | |
---|
507 | class ICourseTicketAdd(ICourseTicket): |
---|
508 | """An interface for adding course tickets. |
---|
509 | |
---|
510 | """ |
---|
511 | course = schema.Choice( |
---|
512 | title = _(u'Course'), |
---|
513 | source = CourseSource(), |
---|
514 | readonly = False, |
---|
515 | ) |
---|
516 | |
---|
517 | class IStudentAccommodation(IKofaObject): |
---|
518 | """A container for student accommodation objects. |
---|
519 | |
---|
520 | """ |
---|
521 | |
---|
522 | class IBedTicket(IKofaObject): |
---|
523 | """A ticket for accommodation booking. |
---|
524 | |
---|
525 | """ |
---|
526 | bed = Attribute('The bed object.') |
---|
527 | |
---|
528 | bed_coordinates = schema.TextLine( |
---|
529 | title = _(u'Bed Coordinates'), |
---|
530 | required = False, |
---|
531 | readonly = False, |
---|
532 | ) |
---|
533 | |
---|
534 | bed_type = schema.TextLine( |
---|
535 | title = _(u'Bed Type'), |
---|
536 | required = False, |
---|
537 | readonly = False, |
---|
538 | ) |
---|
539 | |
---|
540 | booking_session = schema.Choice( |
---|
541 | title = _(u'Session'), |
---|
542 | source = academic_sessions_vocab, |
---|
543 | required = True, |
---|
544 | readonly = True, |
---|
545 | ) |
---|
546 | |
---|
547 | booking_date = schema.Datetime( |
---|
548 | title = _(u'Booking Date'), |
---|
549 | required = False, |
---|
550 | readonly = True, |
---|
551 | ) |
---|
552 | |
---|
553 | booking_code = schema.TextLine( |
---|
554 | title = _(u'Booking Activation Code'), |
---|
555 | required = False, |
---|
556 | readonly = True, |
---|
557 | ) |
---|
558 | |
---|
559 | def getSessionString(): |
---|
560 | """Returns the title of academic_sessions_vocab term. |
---|
561 | |
---|
562 | """ |
---|
563 | |
---|
564 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
565 | """A container for student payment objects. |
---|
566 | |
---|
567 | """ |
---|
568 | |
---|
569 | class IStudentOnlinePayment(IOnlinePayment): |
---|
570 | """A student payment via payment gateways. |
---|
571 | |
---|
572 | """ |
---|
573 | |
---|
574 | p_current = schema.Bool( |
---|
575 | title = _(u'Current Session Payment'), |
---|
576 | default = True, |
---|
577 | required = False, |
---|
578 | ) |
---|
579 | |
---|
580 | p_level = schema.Int( |
---|
581 | title = _(u'Payment Level'), |
---|
582 | required = False, |
---|
583 | readonly = True, |
---|
584 | ) |
---|
585 | |
---|
586 | def doAfterStudentPayment(): |
---|
587 | """Process student after payment was made. |
---|
588 | |
---|
589 | """ |
---|
590 | |
---|
591 | def doAfterStudentPaymentApproval(): |
---|
592 | """Process student after payment was approved. |
---|
593 | |
---|
594 | """ |
---|
595 | |
---|
596 | def approveStudentPayment(): |
---|
597 | """Approve payment and process student. |
---|
598 | |
---|
599 | """ |
---|
600 | |
---|
601 | IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[ |
---|
602 | 'p_session'].order |
---|
603 | |
---|
604 | class IStudentPreviousPayment(IOnlinePayment): |
---|
605 | """An interface for adding previous session payments. |
---|
606 | |
---|
607 | """ |
---|
608 | |
---|
609 | p_session = schema.Choice( |
---|
610 | title = _(u'Payment Session'), |
---|
611 | source = academic_sessions_vocab, |
---|
612 | required = True, |
---|
613 | ) |
---|
614 | |
---|
615 | p_level = schema.Choice( |
---|
616 | title = _(u'Payment Level'), |
---|
617 | source = StudyLevelSource(), |
---|
618 | required = True, |
---|
619 | ) |
---|
620 | |
---|
621 | class ICSVStudentExporter(ICSVExporter): |
---|
622 | """A regular ICSVExporter that additionally supports exporting |
---|
623 | data from a given student object. |
---|
624 | """ |
---|
625 | |
---|
626 | def export_student(student, filepath=None): |
---|
627 | """Export data for a given student. |
---|
628 | """ |
---|