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