1 | ## $Id: interfaces.py 8983 2012-07-12 11:43:12Z 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): |
---|
69 | """Create Payment object and set the payment data of a student for |
---|
70 | the payment category specified. |
---|
71 | |
---|
72 | """ |
---|
73 | |
---|
74 | def getAccommodation_details(student): |
---|
75 | """Determine the accommodation dates of a student. |
---|
76 | |
---|
77 | """ |
---|
78 | |
---|
79 | def selectBed(available_beds): |
---|
80 | """Select a bed from a list of available beds. |
---|
81 | |
---|
82 | In the standard configuration we select the first bed found, |
---|
83 | but can also randomize the selection if we like. |
---|
84 | """ |
---|
85 | |
---|
86 | def renderPDF(view, subject='', filename='slip.pdf',): |
---|
87 | """Render pdf slips for various pages. |
---|
88 | |
---|
89 | """ |
---|
90 | |
---|
91 | class IStudentsContainer(IKofaObject): |
---|
92 | """A students container contains university students. |
---|
93 | |
---|
94 | """ |
---|
95 | def addStudent(student): |
---|
96 | """Add an IStudent object and subcontainers. |
---|
97 | |
---|
98 | """ |
---|
99 | |
---|
100 | def archive(id=None): |
---|
101 | """Create on-dist archive of 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 | students types are saved to disk. |
---|
110 | """ |
---|
111 | |
---|
112 | def clear(id=None, archive=True): |
---|
113 | """Remove students of type given by 'id'. |
---|
114 | |
---|
115 | Optionally archive the students. |
---|
116 | |
---|
117 | If id is `None`, all students are archived. |
---|
118 | |
---|
119 | If id contains a single id string, only the respective |
---|
120 | students are archived. |
---|
121 | |
---|
122 | If id contains a list of id strings all of the respective |
---|
123 | student types are saved to disk. |
---|
124 | |
---|
125 | If `archive` is ``False`` none of the archive-handling is done |
---|
126 | and respective students are simply removed from the |
---|
127 | database. |
---|
128 | """ |
---|
129 | |
---|
130 | unique_student_id = Attribute("""A unique student id.""") |
---|
131 | |
---|
132 | class IStudentNavigation(IKofaObject): |
---|
133 | """Interface needed for student navigation, logging, etc. |
---|
134 | |
---|
135 | """ |
---|
136 | student = Attribute('Student object of context.') |
---|
137 | |
---|
138 | def writeLogMessage(view, message): |
---|
139 | """Write a view specific log message into students.log. |
---|
140 | |
---|
141 | """ |
---|
142 | |
---|
143 | class IStudentBase(IKofaObject): |
---|
144 | """Representation of student base data. |
---|
145 | |
---|
146 | """ |
---|
147 | history = Attribute('Object history, a list of messages') |
---|
148 | state = Attribute('Returns the registration state of a student') |
---|
149 | password = Attribute('Encrypted password of a student') |
---|
150 | certcode = Attribute('The certificate code of any chosen study course') |
---|
151 | depcode = Attribute('The department code of any chosen study course') |
---|
152 | faccode = Attribute('The faculty code of any chosen study course') |
---|
153 | current_session = Attribute('The current session of the student') |
---|
154 | current_mode = Attribute('The current mode of the student') |
---|
155 | fullname = Attribute('All name parts separated by hyphens') |
---|
156 | display_fullname = Attribute('The fullname of an applicant') |
---|
157 | is_postgrad = Attribute('True if postgraduate student') |
---|
158 | |
---|
159 | suspended = schema.Bool( |
---|
160 | title = _(u'Account suspended'), |
---|
161 | default = False, |
---|
162 | ) |
---|
163 | |
---|
164 | student_id = schema.TextLine( |
---|
165 | title = _(u'Student Id'), |
---|
166 | required = False, |
---|
167 | ) |
---|
168 | |
---|
169 | firstname = schema.TextLine( |
---|
170 | title = _(u'First Name'), |
---|
171 | required = True, |
---|
172 | ) |
---|
173 | |
---|
174 | middlename = schema.TextLine( |
---|
175 | title = _(u'Middle Name'), |
---|
176 | required = False, |
---|
177 | ) |
---|
178 | |
---|
179 | lastname = schema.TextLine( |
---|
180 | title = _(u'Last Name (Surname)'), |
---|
181 | required = True, |
---|
182 | ) |
---|
183 | |
---|
184 | sex = schema.Choice( |
---|
185 | title = _(u'Sex'), |
---|
186 | source = GenderSource(), |
---|
187 | required = True, |
---|
188 | ) |
---|
189 | |
---|
190 | reg_number = TextLineChoice( |
---|
191 | title = _(u'Registration Number'), |
---|
192 | required = True, |
---|
193 | readonly = False, |
---|
194 | source = contextual_reg_num_source, |
---|
195 | ) |
---|
196 | |
---|
197 | matric_number = TextLineChoice( |
---|
198 | title = _(u'Matriculation Number'), |
---|
199 | required = False, |
---|
200 | readonly = False, |
---|
201 | source = contextual_mat_num_source, |
---|
202 | ) |
---|
203 | |
---|
204 | adm_code = schema.TextLine( |
---|
205 | title = _(u'PWD Activation Code'), |
---|
206 | required = False, |
---|
207 | readonly = False, |
---|
208 | ) |
---|
209 | |
---|
210 | email = schema.ASCIILine( |
---|
211 | title = _(u'Email'), |
---|
212 | required = False, |
---|
213 | constraint=validate_email, |
---|
214 | ) |
---|
215 | phone = PhoneNumber( |
---|
216 | title = _(u'Phone'), |
---|
217 | description = u'', |
---|
218 | required = False, |
---|
219 | ) |
---|
220 | |
---|
221 | class IUGStudentClearance(IKofaObject): |
---|
222 | """Representation of undergraduate student clearance data. |
---|
223 | |
---|
224 | """ |
---|
225 | date_of_birth = FormattedDate( |
---|
226 | title = _(u'Date of Birth'), |
---|
227 | required = True, |
---|
228 | show_year = True, |
---|
229 | ) |
---|
230 | |
---|
231 | clearance_locked = schema.Bool( |
---|
232 | title = _(u'Clearance form locked'), |
---|
233 | default = False, |
---|
234 | ) |
---|
235 | |
---|
236 | clr_code = schema.TextLine( |
---|
237 | title = _(u'CLR Activation Code'), |
---|
238 | required = False, |
---|
239 | readonly = False, |
---|
240 | ) |
---|
241 | |
---|
242 | nationality = schema.Choice( |
---|
243 | vocabulary = nats_vocab, |
---|
244 | title = _(u'Nationality'), |
---|
245 | required = False, |
---|
246 | ) |
---|
247 | |
---|
248 | class IPGStudentClearance(IUGStudentClearance): |
---|
249 | """Representation of postgraduate student clearance data. |
---|
250 | |
---|
251 | """ |
---|
252 | employer = schema.TextLine( |
---|
253 | title = _(u'Employer'), |
---|
254 | required = False, |
---|
255 | readonly = False, |
---|
256 | ) |
---|
257 | |
---|
258 | class IStudentPersonal(IKofaObject): |
---|
259 | """Representation of student personal data. |
---|
260 | |
---|
261 | """ |
---|
262 | perm_address = schema.Text( |
---|
263 | title = _(u'Permanent Address'), |
---|
264 | required = False, |
---|
265 | ) |
---|
266 | |
---|
267 | class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance, |
---|
268 | IStudentPersonal): |
---|
269 | """Representation of a student. |
---|
270 | |
---|
271 | """ |
---|
272 | |
---|
273 | class IStudentUpdateByRegNo(IStudent): |
---|
274 | """Representation of a student. Skip regular reg_number validation. |
---|
275 | |
---|
276 | """ |
---|
277 | reg_number = schema.TextLine( |
---|
278 | title = _(u'Registration Number'), |
---|
279 | required = False, |
---|
280 | ) |
---|
281 | |
---|
282 | class IStudentUpdateByMatricNo(IStudent): |
---|
283 | """Representation of a student. Skip regular matric_number validation. |
---|
284 | |
---|
285 | """ |
---|
286 | matric_number = schema.TextLine( |
---|
287 | title = _(u'Matriculation Number'), |
---|
288 | required = False, |
---|
289 | ) |
---|
290 | |
---|
291 | class IStudentRequestPW(IStudent): |
---|
292 | """Representation of an student for first-time password request. |
---|
293 | |
---|
294 | This interface is used when students use the requestpw page to |
---|
295 | login for the the first time. |
---|
296 | """ |
---|
297 | number = schema.TextLine( |
---|
298 | title = _(u'Registr. or Matric. Number'), |
---|
299 | required = True, |
---|
300 | ) |
---|
301 | |
---|
302 | firstname = schema.TextLine( |
---|
303 | title = _(u'First Name'), |
---|
304 | required = True, |
---|
305 | ) |
---|
306 | |
---|
307 | email = schema.ASCIILine( |
---|
308 | title = _(u'Email Address'), |
---|
309 | required = True, |
---|
310 | constraint=validate_email, |
---|
311 | ) |
---|
312 | |
---|
313 | class IStudentStudyCourse(IKofaObject): |
---|
314 | """A container for student study levels. |
---|
315 | |
---|
316 | """ |
---|
317 | certificate = schema.Choice( |
---|
318 | title = _(u'Certificate'), |
---|
319 | source = CertificateSource(), |
---|
320 | required = False, |
---|
321 | ) |
---|
322 | |
---|
323 | entry_mode = schema.Choice( |
---|
324 | title = _(u'Entry Mode'), |
---|
325 | source = StudyModeSource(), |
---|
326 | required = True, |
---|
327 | readonly = False, |
---|
328 | ) |
---|
329 | |
---|
330 | entry_session = schema.Choice( |
---|
331 | title = _(u'Entry Session'), |
---|
332 | source = academic_sessions_vocab, |
---|
333 | #default = datetime.now().year, |
---|
334 | required = True, |
---|
335 | readonly = False, |
---|
336 | ) |
---|
337 | |
---|
338 | current_session = schema.Choice( |
---|
339 | title = _(u'Current Session'), |
---|
340 | source = academic_sessions_vocab, |
---|
341 | required = True, |
---|
342 | readonly = False, |
---|
343 | ) |
---|
344 | |
---|
345 | current_level = schema.Choice( |
---|
346 | title = _(u'Current Level'), |
---|
347 | source = StudyLevelSource(), |
---|
348 | required = False, |
---|
349 | readonly = False, |
---|
350 | ) |
---|
351 | |
---|
352 | current_verdict = schema.Choice( |
---|
353 | title = _(u'Current Verdict'), |
---|
354 | source = VerdictSource(), |
---|
355 | default = '0', |
---|
356 | required = False, |
---|
357 | ) |
---|
358 | |
---|
359 | previous_verdict = schema.Choice( |
---|
360 | title = _(u'Previous Verdict'), |
---|
361 | source = VerdictSource(), |
---|
362 | default = '0', |
---|
363 | required = False, |
---|
364 | ) |
---|
365 | |
---|
366 | class IStudentVerdictUpdate(IKofaObject): |
---|
367 | """A interface for verdict imports. |
---|
368 | |
---|
369 | """ |
---|
370 | |
---|
371 | current_verdict = schema.Choice( |
---|
372 | title = _(u'Current Verdict'), |
---|
373 | source = VerdictSource(), |
---|
374 | required = True, |
---|
375 | ) |
---|
376 | |
---|
377 | current_session = schema.Choice( |
---|
378 | title = _(u'Current Session'), |
---|
379 | source = academic_sessions_vocab, |
---|
380 | required = True, |
---|
381 | ) |
---|
382 | |
---|
383 | current_level = schema.Choice( |
---|
384 | title = _(u'Current Level'), |
---|
385 | source = StudyLevelSource(), |
---|
386 | required = True, |
---|
387 | ) |
---|
388 | |
---|
389 | class IStudentStudyLevel(IKofaObject): |
---|
390 | """A container for course tickets. |
---|
391 | |
---|
392 | """ |
---|
393 | level = Attribute('The level code') |
---|
394 | validation_date = Attribute('The date of validation') |
---|
395 | validated_by = Attribute('User Id of course adviser') |
---|
396 | |
---|
397 | level_session = schema.Choice( |
---|
398 | title = _(u'Session'), |
---|
399 | source = academic_sessions_vocab, |
---|
400 | required = True, |
---|
401 | ) |
---|
402 | |
---|
403 | level_verdict = schema.Choice( |
---|
404 | title = _(u'Verdict'), |
---|
405 | source = VerdictSource(), |
---|
406 | default = '0', |
---|
407 | required = False, |
---|
408 | ) |
---|
409 | |
---|
410 | def addCourseTicket(ticket, course): |
---|
411 | """Add a course ticket object. |
---|
412 | """ |
---|
413 | |
---|
414 | class ICourseTicket(IKofaObject): |
---|
415 | """A course ticket. |
---|
416 | |
---|
417 | """ |
---|
418 | code = Attribute('code of the original course') |
---|
419 | title = Attribute('title of the original course') |
---|
420 | credits = Attribute('credits of the original course') |
---|
421 | passmark = Attribute('passmark of the original course') |
---|
422 | semester = Attribute('semester of the original course') |
---|
423 | fcode = Attribute('faculty code of the original course') |
---|
424 | dcode = Attribute('department code of the original course') |
---|
425 | |
---|
426 | mandatory = schema.Bool( |
---|
427 | title = _(u'Mandatory'), |
---|
428 | default = False, |
---|
429 | required = False, |
---|
430 | readonly = False, |
---|
431 | ) |
---|
432 | |
---|
433 | score = schema.Int( |
---|
434 | title = _(u'Score'), |
---|
435 | default = 0, |
---|
436 | required = False, |
---|
437 | readonly = False, |
---|
438 | ) |
---|
439 | |
---|
440 | automatic = schema.Bool( |
---|
441 | title = _(u'Automatical Creation'), |
---|
442 | default = False, |
---|
443 | required = False, |
---|
444 | readonly = True, |
---|
445 | ) |
---|
446 | |
---|
447 | carry_over = schema.Bool( |
---|
448 | title = _(u'Carry-over Course'), |
---|
449 | default = False, |
---|
450 | required = False, |
---|
451 | readonly = False, |
---|
452 | ) |
---|
453 | |
---|
454 | def getLevel(): |
---|
455 | """Returns the id of the level the ticket has been added to. |
---|
456 | """ |
---|
457 | |
---|
458 | def getLevelSession(): |
---|
459 | """Returns the session of the level the ticket has been added to. |
---|
460 | """ |
---|
461 | |
---|
462 | class ICourseTicketAdd(ICourseTicket): |
---|
463 | """An interface for adding course tickets. |
---|
464 | |
---|
465 | """ |
---|
466 | course = schema.Choice( |
---|
467 | title = _(u'Course'), |
---|
468 | source = CourseSource(), |
---|
469 | readonly = False, |
---|
470 | ) |
---|
471 | |
---|
472 | class IStudentAccommodation(IKofaObject): |
---|
473 | """A container for student accommodation objects. |
---|
474 | |
---|
475 | """ |
---|
476 | |
---|
477 | class IBedTicket(IKofaObject): |
---|
478 | """A ticket for accommodation booking. |
---|
479 | |
---|
480 | """ |
---|
481 | bed = Attribute('The bed object.') |
---|
482 | |
---|
483 | bed_coordinates = schema.TextLine( |
---|
484 | title = _(u'Bed Coordinates'), |
---|
485 | required = False, |
---|
486 | readonly = False, |
---|
487 | ) |
---|
488 | |
---|
489 | bed_type = schema.TextLine( |
---|
490 | title = _(u'Bed Type'), |
---|
491 | required = False, |
---|
492 | readonly = False, |
---|
493 | ) |
---|
494 | |
---|
495 | booking_session = schema.Choice( |
---|
496 | title = _(u'Session'), |
---|
497 | source = academic_sessions_vocab, |
---|
498 | required = True, |
---|
499 | readonly = True, |
---|
500 | ) |
---|
501 | |
---|
502 | booking_date = schema.Datetime( |
---|
503 | title = _(u'Booking Date'), |
---|
504 | required = False, |
---|
505 | readonly = True, |
---|
506 | ) |
---|
507 | |
---|
508 | booking_code = schema.TextLine( |
---|
509 | title = _(u'Booking Activation Code'), |
---|
510 | required = False, |
---|
511 | readonly = True, |
---|
512 | ) |
---|
513 | |
---|
514 | def getSessionString(): |
---|
515 | """Returns the title of academic_sessions_vocab term. |
---|
516 | |
---|
517 | """ |
---|
518 | |
---|
519 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
520 | """A container for student payment objects. |
---|
521 | |
---|
522 | """ |
---|
523 | |
---|
524 | class IStudentOnlinePayment(IOnlinePayment): |
---|
525 | """A student payment via payment gateways. |
---|
526 | |
---|
527 | """ |
---|
528 | |
---|
529 | p_level = schema.Int( |
---|
530 | title = _(u'Payment Level'), |
---|
531 | required = False, |
---|
532 | readonly = True, |
---|
533 | ) |
---|
534 | |
---|
535 | def doAfterStudentPayment(): |
---|
536 | """Process student after payment was made. |
---|
537 | |
---|
538 | """ |
---|
539 | |
---|
540 | def doAfterStudentPaymentApproval(): |
---|
541 | """Process student after payment was approved. |
---|
542 | |
---|
543 | """ |
---|
544 | |
---|
545 | def approveStudentPayment(): |
---|
546 | """Approve payment and process student. |
---|
547 | |
---|
548 | """ |
---|
549 | |
---|
550 | IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[ |
---|
551 | 'p_session'].order |
---|
552 | |
---|
553 | class ICSVStudentExporter(ICSVExporter): |
---|
554 | """A regular ICSVExporter that additionally supports exporting |
---|
555 | data from a given student object. |
---|
556 | """ |
---|
557 | |
---|
558 | def export_student(student, filepath=None): |
---|
559 | """Export data for a given student. |
---|
560 | """ |
---|