1 | ## $Id: interfaces.py 8182 2012-04-16 20:56:59Z 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, IKofaUtils) |
---|
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 getPaymentDetails(category, student): |
---|
67 | """Get the payment dates of a student for the payment category |
---|
68 | 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 | class IStudentNavigation(IKofaObject): |
---|
129 | """Interface needed for student navigation. |
---|
130 | |
---|
131 | """ |
---|
132 | def getStudent(): |
---|
133 | """Return student object. |
---|
134 | |
---|
135 | """ |
---|
136 | |
---|
137 | class IStudentBase(IKofaObject): |
---|
138 | """Representation of student base data. |
---|
139 | |
---|
140 | """ |
---|
141 | history = Attribute('Object history, a list of messages') |
---|
142 | state = Attribute('Returns the registration state of a student') |
---|
143 | password = Attribute('Encrypted password of a student') |
---|
144 | certcode = Attribute('The certificate code of any chosen study course') |
---|
145 | depcode = Attribute('The department code of any chosen study course') |
---|
146 | faccode = Attribute('The faculty code of any chosen study course') |
---|
147 | current_session = Attribute('The current session of the student') |
---|
148 | current_mode = Attribute('The current mode of the student') |
---|
149 | fullname = Attribute('All name parts separated by hyphens') |
---|
150 | display_fullname = Attribute('The fullname of an applicant') |
---|
151 | |
---|
152 | def loggerInfo(ob_class, comment): |
---|
153 | """Adds an INFO message to the log file. |
---|
154 | |
---|
155 | """ |
---|
156 | |
---|
157 | student_id = schema.TextLine( |
---|
158 | title = _(u'Student Id'), |
---|
159 | required = False, |
---|
160 | ) |
---|
161 | |
---|
162 | firstname = schema.TextLine( |
---|
163 | title = _(u'First Name'), |
---|
164 | required = True, |
---|
165 | ) |
---|
166 | |
---|
167 | middlename = schema.TextLine( |
---|
168 | title = _(u'Middle Name'), |
---|
169 | required = False, |
---|
170 | ) |
---|
171 | |
---|
172 | lastname = schema.TextLine( |
---|
173 | title = _(u'Last Name (Surname)'), |
---|
174 | required = True, |
---|
175 | ) |
---|
176 | |
---|
177 | sex = schema.Choice( |
---|
178 | title = _(u'Sex'), |
---|
179 | source = GenderSource(), |
---|
180 | required = True, |
---|
181 | ) |
---|
182 | |
---|
183 | reg_number = TextLineChoice( |
---|
184 | title = _(u'Registration Number'), |
---|
185 | required = True, |
---|
186 | readonly = False, |
---|
187 | source = contextual_reg_num_source, |
---|
188 | ) |
---|
189 | |
---|
190 | matric_number = TextLineChoice( |
---|
191 | title = _(u'Matriculation Number'), |
---|
192 | required = False, |
---|
193 | readonly = False, |
---|
194 | source = contextual_mat_num_source, |
---|
195 | ) |
---|
196 | |
---|
197 | adm_code = schema.TextLine( |
---|
198 | title = _(u'PWD Activation Code'), |
---|
199 | required = False, |
---|
200 | readonly = True, |
---|
201 | ) |
---|
202 | |
---|
203 | email = schema.ASCIILine( |
---|
204 | title = _(u'Email'), |
---|
205 | required = False, |
---|
206 | constraint=validate_email, |
---|
207 | ) |
---|
208 | phone = PhoneNumber( |
---|
209 | title = _(u'Phone'), |
---|
210 | description = u'', |
---|
211 | required = False, |
---|
212 | ) |
---|
213 | |
---|
214 | class IUGStudentClearance(IKofaObject): |
---|
215 | """Representation of undergraduate student clearance data. |
---|
216 | |
---|
217 | """ |
---|
218 | date_of_birth = FormattedDate( |
---|
219 | title = _(u'Date of Birth'), |
---|
220 | required = True, |
---|
221 | show_year = True, |
---|
222 | ) |
---|
223 | |
---|
224 | clearance_locked = schema.Bool( |
---|
225 | title = _(u'Clearance form locked'), |
---|
226 | default = False, |
---|
227 | ) |
---|
228 | |
---|
229 | clr_code = schema.TextLine( |
---|
230 | title = _(u'CLR Activation Code'), |
---|
231 | required = False, |
---|
232 | readonly = True, |
---|
233 | ) |
---|
234 | |
---|
235 | nationality = schema.Choice( |
---|
236 | vocabulary = nats_vocab, |
---|
237 | title = _(u'Nationality'), |
---|
238 | required = False, |
---|
239 | ) |
---|
240 | |
---|
241 | class IPGStudentClearance(IUGStudentClearance): |
---|
242 | """Representation of postgraduate student clearance data. |
---|
243 | |
---|
244 | """ |
---|
245 | employer = schema.TextLine( |
---|
246 | title = _(u'Employer'), |
---|
247 | required = False, |
---|
248 | readonly = False, |
---|
249 | ) |
---|
250 | |
---|
251 | class IStudentPersonal(IKofaObject): |
---|
252 | """Representation of student personal data. |
---|
253 | |
---|
254 | """ |
---|
255 | perm_address = schema.Text( |
---|
256 | title = _(u'Permanent Address'), |
---|
257 | required = False, |
---|
258 | ) |
---|
259 | |
---|
260 | class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance, |
---|
261 | IStudentPersonal): |
---|
262 | """Representation of a student. |
---|
263 | |
---|
264 | """ |
---|
265 | |
---|
266 | class IStudentUpdateByRegNo(IStudent): |
---|
267 | """Representation of a student. Skip regular reg_number validation. |
---|
268 | |
---|
269 | """ |
---|
270 | reg_number = schema.TextLine( |
---|
271 | title = _(u'Registration Number'), |
---|
272 | required = False, |
---|
273 | ) |
---|
274 | |
---|
275 | class IStudentUpdateByMatricNo(IStudent): |
---|
276 | """Representation of a student. Skip regular matric_number validation. |
---|
277 | |
---|
278 | """ |
---|
279 | matric_number = schema.TextLine( |
---|
280 | title = _(u'Matriculation Number'), |
---|
281 | required = False, |
---|
282 | ) |
---|
283 | |
---|
284 | class IStudentStudyCourse(IKofaObject): |
---|
285 | """A container for student study levels. |
---|
286 | |
---|
287 | """ |
---|
288 | certificate = schema.Choice( |
---|
289 | title = _(u'Certificate'), |
---|
290 | source = CertificateSource(), |
---|
291 | required = False, |
---|
292 | ) |
---|
293 | |
---|
294 | entry_mode = schema.Choice( |
---|
295 | title = _(u'Entry Mode'), |
---|
296 | source = StudyModeSource(), |
---|
297 | required = True, |
---|
298 | readonly = False, |
---|
299 | ) |
---|
300 | |
---|
301 | entry_session = schema.Choice( |
---|
302 | title = _(u'Entry Session'), |
---|
303 | source = academic_sessions_vocab, |
---|
304 | #default = datetime.now().year, |
---|
305 | required = True, |
---|
306 | readonly = False, |
---|
307 | ) |
---|
308 | |
---|
309 | current_session = schema.Choice( |
---|
310 | title = _(u'Current Session'), |
---|
311 | source = academic_sessions_vocab, |
---|
312 | required = True, |
---|
313 | readonly = False, |
---|
314 | ) |
---|
315 | |
---|
316 | current_level = schema.Choice( |
---|
317 | title = _(u'Current Level'), |
---|
318 | source = StudyLevelSource(), |
---|
319 | required = False, |
---|
320 | readonly = False, |
---|
321 | ) |
---|
322 | |
---|
323 | current_verdict = schema.Choice( |
---|
324 | title = _(u'Current Verdict'), |
---|
325 | source = VerdictSource(), |
---|
326 | default = '0', |
---|
327 | required = False, |
---|
328 | ) |
---|
329 | |
---|
330 | previous_verdict = schema.Choice( |
---|
331 | title = _(u'Previous Verdict'), |
---|
332 | source = VerdictSource(), |
---|
333 | default = '0', |
---|
334 | required = False, |
---|
335 | ) |
---|
336 | |
---|
337 | class IStudentVerdictUpdate(IKofaObject): |
---|
338 | """A interface for verdict imports. |
---|
339 | |
---|
340 | """ |
---|
341 | |
---|
342 | current_verdict = schema.Choice( |
---|
343 | title = _(u'Current Verdict'), |
---|
344 | source = VerdictSource(), |
---|
345 | required = True, |
---|
346 | ) |
---|
347 | |
---|
348 | current_session = schema.Choice( |
---|
349 | title = _(u'Current Session'), |
---|
350 | source = academic_sessions_vocab, |
---|
351 | required = True, |
---|
352 | ) |
---|
353 | |
---|
354 | current_level = schema.Choice( |
---|
355 | title = _(u'Current Level'), |
---|
356 | source = StudyLevelSource(), |
---|
357 | required = True, |
---|
358 | ) |
---|
359 | |
---|
360 | class IStudentStudyLevel(IKofaObject): |
---|
361 | """A container for course tickets. |
---|
362 | |
---|
363 | """ |
---|
364 | level = Attribute('The level code') |
---|
365 | validation_date = Attribute('The date of validation') |
---|
366 | validated_by = Attribute('User Id of course adviser') |
---|
367 | |
---|
368 | level_session = schema.Choice( |
---|
369 | title = _(u'Session'), |
---|
370 | source = academic_sessions_vocab, |
---|
371 | required = True, |
---|
372 | ) |
---|
373 | |
---|
374 | level_verdict = schema.Choice( |
---|
375 | title = _(u'Verdict'), |
---|
376 | source = VerdictSource(), |
---|
377 | default = '0', |
---|
378 | required = False, |
---|
379 | ) |
---|
380 | |
---|
381 | def addCourseTicket(courseticket): |
---|
382 | """Add a course ticket object. |
---|
383 | """ |
---|
384 | |
---|
385 | def getStudent(): |
---|
386 | """Return student |
---|
387 | """ |
---|
388 | |
---|
389 | class ICourseTicket(IKofaObject): |
---|
390 | """A course ticket. |
---|
391 | |
---|
392 | """ |
---|
393 | code = Attribute('code of the original course') |
---|
394 | title = Attribute('title of the original course') |
---|
395 | credits = Attribute('credits of the original course') |
---|
396 | passmark = Attribute('passmark of the original course') |
---|
397 | semester = Attribute('semester of the original course') |
---|
398 | fcode = Attribute('faculty code of the original course') |
---|
399 | dcode = Attribute('department code of the original course') |
---|
400 | |
---|
401 | mandatory = schema.Bool( |
---|
402 | title = _(u'Mandatory'), |
---|
403 | default = False, |
---|
404 | required = False, |
---|
405 | readonly = False, |
---|
406 | ) |
---|
407 | |
---|
408 | score = schema.Int( |
---|
409 | title = _(u'Score'), |
---|
410 | default = 0, |
---|
411 | required = False, |
---|
412 | readonly = False, |
---|
413 | ) |
---|
414 | |
---|
415 | automatic = schema.Bool( |
---|
416 | title = _(u'Automatical Creation'), |
---|
417 | default = False, |
---|
418 | required = False, |
---|
419 | readonly = True, |
---|
420 | ) |
---|
421 | |
---|
422 | carry_over = schema.Bool( |
---|
423 | title = _(u'Carry-over Course'), |
---|
424 | default = False, |
---|
425 | required = False, |
---|
426 | readonly = False, |
---|
427 | ) |
---|
428 | |
---|
429 | def getLevel(): |
---|
430 | """Returns the id of the level the ticket has been added to. |
---|
431 | """ |
---|
432 | |
---|
433 | def getLevelSession(): |
---|
434 | """Returns the session of the level the ticket has been added to. |
---|
435 | """ |
---|
436 | |
---|
437 | class ICourseTicketAdd(ICourseTicket): |
---|
438 | """An interface for adding course tickets. |
---|
439 | |
---|
440 | """ |
---|
441 | course = schema.Choice( |
---|
442 | title = _(u'Course'), |
---|
443 | source = CourseSource(), |
---|
444 | readonly = False, |
---|
445 | ) |
---|
446 | |
---|
447 | class IStudentAccommodation(IKofaObject): |
---|
448 | """A container for student accommodation objects. |
---|
449 | |
---|
450 | """ |
---|
451 | |
---|
452 | class IBedTicket(IKofaObject): |
---|
453 | """A ticket for accommodation booking. |
---|
454 | |
---|
455 | """ |
---|
456 | bed = Attribute('The bed object.') |
---|
457 | |
---|
458 | bed_coordinates = schema.TextLine( |
---|
459 | title = _(u'Bed Coordinates'), |
---|
460 | required = False, |
---|
461 | readonly = False, |
---|
462 | ) |
---|
463 | |
---|
464 | bed_type = schema.TextLine( |
---|
465 | title = _(u'Bed Type'), |
---|
466 | required = False, |
---|
467 | readonly = False, |
---|
468 | ) |
---|
469 | |
---|
470 | booking_session = schema.Choice( |
---|
471 | title = _(u'Session'), |
---|
472 | source = academic_sessions_vocab, |
---|
473 | required = True, |
---|
474 | readonly = True, |
---|
475 | ) |
---|
476 | |
---|
477 | booking_date = schema.Datetime( |
---|
478 | title = _(u'Booking Date'), |
---|
479 | required = False, |
---|
480 | readonly = True, |
---|
481 | ) |
---|
482 | |
---|
483 | booking_code = schema.TextLine( |
---|
484 | title = _(u'Booking Activation Code'), |
---|
485 | required = False, |
---|
486 | readonly = True, |
---|
487 | ) |
---|
488 | |
---|
489 | def getSessionString(): |
---|
490 | """Returns the title of academic_sessions_vocab term. |
---|
491 | |
---|
492 | """ |
---|
493 | |
---|
494 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
495 | """A container for student payment objects. |
---|
496 | |
---|
497 | """ |
---|
498 | |
---|
499 | class IStudentOnlinePayment(IOnlinePayment): |
---|
500 | """A student payment via payment gateways. |
---|
501 | |
---|
502 | """ |
---|
503 | p_session = schema.Choice( |
---|
504 | title = _(u'Payment Session'), |
---|
505 | source = academic_sessions_vocab, |
---|
506 | required = False, |
---|
507 | ) |
---|
508 | |
---|
509 | IStudentOnlinePayment['p_session'].order = IStudentOnlinePayment[ |
---|
510 | 'p_item'].order |
---|
511 | |
---|
512 | |
---|
513 | class IStudentChangePassword(IKofaObject): |
---|
514 | """Interface needed for change pasword page. |
---|
515 | |
---|
516 | """ |
---|
517 | reg_number = schema.TextLine( |
---|
518 | title = _(u'Registration Number'), |
---|
519 | required = True, |
---|
520 | readonly = False, |
---|
521 | ) |
---|
522 | |
---|
523 | email = schema.ASCIILine( |
---|
524 | title = _(u'Email Address'), |
---|
525 | required = True, |
---|
526 | constraint=validate_email, |
---|
527 | ) |
---|