1 | ## $Id: interfaces.py 7723 2012-02-29 13:29:35Z 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.sirp.interfaces import ( |
---|
24 | ISIRPObject, academic_sessions_vocab, validate_email, ISIRPUtils) |
---|
25 | from waeup.sirp.interfaces import MessageFactory as _ |
---|
26 | from waeup.sirp.schema import TextLineChoice |
---|
27 | from waeup.sirp.university.vocabularies import CourseSource, StudyModeSource |
---|
28 | from waeup.sirp.students.vocabularies import ( |
---|
29 | CertificateSource, StudyLevelSource, |
---|
30 | contextual_reg_num_source, contextual_mat_num_source, |
---|
31 | GenderSource, nats_vocab, |
---|
32 | ) |
---|
33 | from waeup.sirp.payments.interfaces import IPaymentsContainer, IOnlinePayment |
---|
34 | |
---|
35 | # VerdictSource can't be placed into the vocabularies module because it |
---|
36 | # requires importing IStudentsUtils which then leads to circular imports. |
---|
37 | class VerdictSource(BasicContextualSourceFactory): |
---|
38 | """A verdicts source delivers all verdicts provided |
---|
39 | in the portal. |
---|
40 | """ |
---|
41 | def getValues(self, context): |
---|
42 | verdicts_dict = getUtility(IStudentsUtils).getVerdictsDict() |
---|
43 | return verdicts_dict.keys() |
---|
44 | |
---|
45 | def getToken(self, context, value): |
---|
46 | return value |
---|
47 | |
---|
48 | def getTitle(self, context, value): |
---|
49 | verdicts_dict = getUtility(IStudentsUtils).getVerdictsDict() |
---|
50 | return verdicts_dict[value] |
---|
51 | |
---|
52 | |
---|
53 | class IStudentsUtils(Interface): |
---|
54 | """A collection of methods which are subject to customization. |
---|
55 | |
---|
56 | """ |
---|
57 | def getPaymentDetails(category, student): |
---|
58 | """Get the payment dates of a student for the payment category |
---|
59 | specified. |
---|
60 | |
---|
61 | """ |
---|
62 | |
---|
63 | def getAccommodation_details(student): |
---|
64 | """Determine the accommodation dates of a student. |
---|
65 | |
---|
66 | """ |
---|
67 | |
---|
68 | def selectBed(available_beds): |
---|
69 | """Select a bed from a list of available beds. |
---|
70 | |
---|
71 | In the standard configuration we select the first bed found, |
---|
72 | but can also randomize the selection if we like. |
---|
73 | """ |
---|
74 | |
---|
75 | def renderPDF(view, subject='', filename='slip.pdf',): |
---|
76 | """Render pdf slips for various pages. |
---|
77 | |
---|
78 | """ |
---|
79 | |
---|
80 | class IStudentsContainer(ISIRPObject): |
---|
81 | """A students container contains university students. |
---|
82 | |
---|
83 | """ |
---|
84 | def addStudent(student): |
---|
85 | """Add an IStudent object and subcontainers. |
---|
86 | |
---|
87 | """ |
---|
88 | |
---|
89 | def archive(id=None): |
---|
90 | """Create on-dist archive of students. |
---|
91 | |
---|
92 | If id is `None`, all students are archived. |
---|
93 | |
---|
94 | If id contains a single id string, only the respective |
---|
95 | students are archived. |
---|
96 | |
---|
97 | If id contains a list of id strings all of the respective |
---|
98 | students types are saved to disk. |
---|
99 | """ |
---|
100 | |
---|
101 | def clear(id=None, archive=True): |
---|
102 | """Remove students of type given by 'id'. |
---|
103 | |
---|
104 | Optionally archive the students. |
---|
105 | |
---|
106 | If id is `None`, all students are archived. |
---|
107 | |
---|
108 | If id contains a single id string, only the respective |
---|
109 | students are archived. |
---|
110 | |
---|
111 | If id contains a list of id strings all of the respective |
---|
112 | student types are saved to disk. |
---|
113 | |
---|
114 | If `archive` is ``False`` none of the archive-handling is done |
---|
115 | and respective students are simply removed from the |
---|
116 | database. |
---|
117 | """ |
---|
118 | |
---|
119 | class IStudentNavigation(ISIRPObject): |
---|
120 | """Interface needed for student navigation. |
---|
121 | |
---|
122 | """ |
---|
123 | def getStudent(): |
---|
124 | """Return student object. |
---|
125 | |
---|
126 | """ |
---|
127 | |
---|
128 | class IStudentBase(ISIRPObject): |
---|
129 | """Representation of student base data. |
---|
130 | |
---|
131 | """ |
---|
132 | history = Attribute('Object history, a list of messages') |
---|
133 | state = Attribute('Returns the registration state of a student') |
---|
134 | password = Attribute('Encrypted password of a student') |
---|
135 | certcode = Attribute('The certificate code of any chosen study course') |
---|
136 | depcode = Attribute('The department code of any chosen study course') |
---|
137 | faccode = Attribute('The faculty code of any chosen study course') |
---|
138 | current_session = Attribute('The current session of the student') |
---|
139 | current_mode = Attribute('The current mode of the student') |
---|
140 | fullname = Attribute('All name parts separated by hyphens') |
---|
141 | display_fullname = Attribute('The fullname of an applicant') |
---|
142 | |
---|
143 | def loggerInfo(ob_class, comment): |
---|
144 | """Adds an INFO message to the log file. |
---|
145 | |
---|
146 | """ |
---|
147 | |
---|
148 | student_id = schema.TextLine( |
---|
149 | title = _(u'Student Id'), |
---|
150 | required = False, |
---|
151 | ) |
---|
152 | |
---|
153 | firstname = schema.TextLine( |
---|
154 | title = _(u'First Name'), |
---|
155 | required = True, |
---|
156 | ) |
---|
157 | |
---|
158 | middlename = schema.TextLine( |
---|
159 | title = _(u'Middle Name'), |
---|
160 | required = False, |
---|
161 | ) |
---|
162 | |
---|
163 | lastname = schema.TextLine( |
---|
164 | title = _(u'Last Name (Surname)'), |
---|
165 | required = True, |
---|
166 | ) |
---|
167 | |
---|
168 | sex = schema.Choice( |
---|
169 | title = _(u'Sex'), |
---|
170 | source = GenderSource(), |
---|
171 | default = u'm', |
---|
172 | required = True, |
---|
173 | ) |
---|
174 | |
---|
175 | reg_number = TextLineChoice( |
---|
176 | title = _(u'Registration Number'), |
---|
177 | required = True, |
---|
178 | readonly = False, |
---|
179 | source = contextual_reg_num_source, |
---|
180 | ) |
---|
181 | |
---|
182 | matric_number = TextLineChoice( |
---|
183 | title = _(u'Matriculation Number'), |
---|
184 | #default = u'', |
---|
185 | required = False, |
---|
186 | readonly = False, |
---|
187 | source = contextual_mat_num_source, |
---|
188 | ) |
---|
189 | |
---|
190 | adm_code = schema.TextLine( |
---|
191 | title = _(u'PWD Activation Code'), |
---|
192 | default = u'', |
---|
193 | required = False, |
---|
194 | readonly = True, |
---|
195 | ) |
---|
196 | |
---|
197 | email = schema.ASCIILine( |
---|
198 | title = _(u'Email'), |
---|
199 | required = False, |
---|
200 | constraint=validate_email, |
---|
201 | ) |
---|
202 | phone = schema.TextLine( |
---|
203 | title = _(u'Phone'), |
---|
204 | description = u'', |
---|
205 | required = False, |
---|
206 | ) |
---|
207 | |
---|
208 | class IStudentClearance(ISIRPObject): |
---|
209 | """Representation of student clearance data. |
---|
210 | |
---|
211 | """ |
---|
212 | date_of_birth = schema.Date( |
---|
213 | title = _(u'Date of Birth'), |
---|
214 | required = True, |
---|
215 | ) |
---|
216 | |
---|
217 | clearance_locked = schema.Bool( |
---|
218 | title = _(u'Clearance form locked'), |
---|
219 | default = False, |
---|
220 | ) |
---|
221 | |
---|
222 | clr_code = schema.TextLine( |
---|
223 | title = _(u'CLR Activation Code'), |
---|
224 | default = u'', |
---|
225 | required = False, |
---|
226 | readonly = True, |
---|
227 | ) |
---|
228 | |
---|
229 | nationality = schema.Choice( |
---|
230 | source = nats_vocab, |
---|
231 | title = _(u'Nationality'), |
---|
232 | default = 'nigeria', |
---|
233 | required = True, |
---|
234 | ) |
---|
235 | |
---|
236 | class IStudentPersonal(ISIRPObject): |
---|
237 | """Representation of student personal data. |
---|
238 | |
---|
239 | """ |
---|
240 | perm_address = schema.Text( |
---|
241 | title = _(u'Permanent Address'), |
---|
242 | required = False, |
---|
243 | ) |
---|
244 | |
---|
245 | class IStudent(IStudentBase,IStudentClearance,IStudentPersonal): |
---|
246 | """Representation of a student. |
---|
247 | |
---|
248 | """ |
---|
249 | |
---|
250 | class IStudentUpdateByRegNo(IStudent): |
---|
251 | """Representation of a student. Skip regular reg_number validation. |
---|
252 | |
---|
253 | """ |
---|
254 | reg_number = schema.TextLine( |
---|
255 | title = _(u'Registration Number'), |
---|
256 | default = None, |
---|
257 | required = False, |
---|
258 | ) |
---|
259 | |
---|
260 | class IStudentUpdateByMatricNo(IStudent): |
---|
261 | """Representation of a student. Skip regular matric_number validation. |
---|
262 | |
---|
263 | """ |
---|
264 | matric_number = schema.TextLine( |
---|
265 | title = _(u'Matriculation Number'), |
---|
266 | default = None, |
---|
267 | required = False, |
---|
268 | ) |
---|
269 | |
---|
270 | class IStudentStudyCourse(ISIRPObject): |
---|
271 | """A container for student study levels. |
---|
272 | |
---|
273 | """ |
---|
274 | certificate = schema.Choice( |
---|
275 | title = _(u'Certificate'), |
---|
276 | source = CertificateSource(), |
---|
277 | default = None, |
---|
278 | required = False, |
---|
279 | ) |
---|
280 | |
---|
281 | entry_mode = schema.Choice( |
---|
282 | title = _(u'Entry Mode'), |
---|
283 | source = StudyModeSource(), |
---|
284 | default = u'ug_ft', |
---|
285 | required = True, |
---|
286 | readonly = False, |
---|
287 | ) |
---|
288 | |
---|
289 | entry_session = schema.Choice( |
---|
290 | title = _(u'Entry Session'), |
---|
291 | source = academic_sessions_vocab, |
---|
292 | #default = datetime.now().year, |
---|
293 | default = None, |
---|
294 | required = True, |
---|
295 | readonly = False, |
---|
296 | ) |
---|
297 | |
---|
298 | current_session = schema.Choice( |
---|
299 | title = _(u'Current Session'), |
---|
300 | source = academic_sessions_vocab, |
---|
301 | default = None, |
---|
302 | required = True, |
---|
303 | readonly = False, |
---|
304 | ) |
---|
305 | |
---|
306 | current_level = schema.Choice( |
---|
307 | title = _(u'Current Level'), |
---|
308 | source = StudyLevelSource(), |
---|
309 | default = None, |
---|
310 | required = False, |
---|
311 | readonly = False, |
---|
312 | ) |
---|
313 | |
---|
314 | current_verdict = schema.Choice( |
---|
315 | title = _(u'Current Verdict'), |
---|
316 | source = VerdictSource(), |
---|
317 | default = '0', |
---|
318 | required = False, |
---|
319 | ) |
---|
320 | |
---|
321 | previous_verdict = schema.Choice( |
---|
322 | title = _(u'Previous Verdict'), |
---|
323 | source = VerdictSource(), |
---|
324 | default = '0', |
---|
325 | required = False, |
---|
326 | ) |
---|
327 | |
---|
328 | class IStudentStudyLevel(ISIRPObject): |
---|
329 | """A container for course tickets. |
---|
330 | |
---|
331 | """ |
---|
332 | level = Attribute('The level code') |
---|
333 | validation_date = Attribute('The date of validation') |
---|
334 | validated_by = Attribute('User Id of course adviser') |
---|
335 | |
---|
336 | level_session = schema.Choice( |
---|
337 | title = _(u'Session'), |
---|
338 | source = academic_sessions_vocab, |
---|
339 | default = None, |
---|
340 | required = True, |
---|
341 | ) |
---|
342 | |
---|
343 | level_verdict = schema.Choice( |
---|
344 | title = _(u'Verdict'), |
---|
345 | source = VerdictSource(), |
---|
346 | default = '0', |
---|
347 | required = False, |
---|
348 | ) |
---|
349 | |
---|
350 | class ICourseTicket(ISIRPObject): |
---|
351 | """A course ticket. |
---|
352 | |
---|
353 | """ |
---|
354 | code = Attribute('code of the original course') |
---|
355 | title = Attribute('title of the original course') |
---|
356 | credits = Attribute('credits of the original course') |
---|
357 | passmark = Attribute('passmark of the original course') |
---|
358 | semester = Attribute('semester of the original course') |
---|
359 | fcode = Attribute('faculty code of the original course') |
---|
360 | dcode = Attribute('department code of the original course') |
---|
361 | |
---|
362 | mandatory = schema.Bool( |
---|
363 | title = _(u'Mandatory'), |
---|
364 | default = False, |
---|
365 | required = False, |
---|
366 | readonly = False, |
---|
367 | ) |
---|
368 | |
---|
369 | score = schema.Int( |
---|
370 | title = _(u'Score'), |
---|
371 | default = 0, |
---|
372 | required = False, |
---|
373 | readonly = False, |
---|
374 | ) |
---|
375 | |
---|
376 | automatic = schema.Bool( |
---|
377 | title = _(u'Automatical Creation'), |
---|
378 | default = False, |
---|
379 | required = False, |
---|
380 | readonly = True, |
---|
381 | ) |
---|
382 | |
---|
383 | carry_over = schema.Bool( |
---|
384 | title = _(u'Carry-over Course'), |
---|
385 | default = False, |
---|
386 | required = False, |
---|
387 | readonly = False, |
---|
388 | ) |
---|
389 | |
---|
390 | def getLevel(): |
---|
391 | """Returns the id of the level the ticket has been added to. |
---|
392 | """ |
---|
393 | |
---|
394 | def getLevelSession(): |
---|
395 | """Returns the session of the level the ticket has been added to. |
---|
396 | """ |
---|
397 | |
---|
398 | class ICourseTicketAdd(ICourseTicket): |
---|
399 | """An interface for adding course tickets. |
---|
400 | |
---|
401 | """ |
---|
402 | course = schema.Choice( |
---|
403 | title = _(u'Course'), |
---|
404 | source = CourseSource(), |
---|
405 | readonly = False, |
---|
406 | ) |
---|
407 | |
---|
408 | class IStudentAccommodation(ISIRPObject): |
---|
409 | """A container for student accommodation objects. |
---|
410 | |
---|
411 | """ |
---|
412 | |
---|
413 | class IBedTicket(ISIRPObject): |
---|
414 | """A ticket for accommodation booking. |
---|
415 | |
---|
416 | """ |
---|
417 | bed = Attribute('The bed object.') |
---|
418 | |
---|
419 | bed_coordinates = schema.TextLine( |
---|
420 | title = _(u'Bed Coordinates'), |
---|
421 | default = None, |
---|
422 | required = False, |
---|
423 | readonly = False, |
---|
424 | ) |
---|
425 | |
---|
426 | bed_type = schema.TextLine( |
---|
427 | title = _(u'Bed Type'), |
---|
428 | default = None, |
---|
429 | required = False, |
---|
430 | readonly = False, |
---|
431 | ) |
---|
432 | |
---|
433 | booking_session = schema.Choice( |
---|
434 | title = _(u'Session'), |
---|
435 | source = academic_sessions_vocab, |
---|
436 | default = None, |
---|
437 | required = True, |
---|
438 | readonly = True, |
---|
439 | ) |
---|
440 | |
---|
441 | booking_date = schema.Datetime( |
---|
442 | title = _(u'Booking Date'), |
---|
443 | required = False, |
---|
444 | readonly = True, |
---|
445 | ) |
---|
446 | |
---|
447 | booking_code = schema.TextLine( |
---|
448 | title = _(u'Booking Activation Code'), |
---|
449 | default = u'', |
---|
450 | required = False, |
---|
451 | readonly = True, |
---|
452 | ) |
---|
453 | |
---|
454 | def getSessionString(): |
---|
455 | """Returns the title of academic_sessions_vocab term. |
---|
456 | |
---|
457 | """ |
---|
458 | |
---|
459 | class IStudentPaymentsContainer(IPaymentsContainer): |
---|
460 | """A container for student payment objects. |
---|
461 | |
---|
462 | """ |
---|
463 | |
---|
464 | class IStudentOnlinePayment(IOnlinePayment): |
---|
465 | """A student payment via payment gateways. |
---|
466 | |
---|
467 | """ |
---|
468 | p_session = schema.Choice( |
---|
469 | title = _(u'Payment Session'), |
---|
470 | source = academic_sessions_vocab, |
---|
471 | required = False, |
---|
472 | ) |
---|
473 | |
---|
474 | IStudentOnlinePayment['p_session'].order = IStudentOnlinePayment[ |
---|
475 | 'p_item'].order |
---|
476 | |
---|
477 | class IStudentChangePassword(ISIRPObject): |
---|
478 | """Interface needed for change pasword page. |
---|
479 | |
---|
480 | """ |
---|
481 | |
---|
482 | reg_number = schema.TextLine( |
---|
483 | title = _(u'Registration Number'), |
---|
484 | default = None, |
---|
485 | required = True, |
---|
486 | readonly = False, |
---|
487 | ) |
---|
488 | |
---|
489 | email = schema.ASCIILine( |
---|
490 | title = _(u'Email Address'), |
---|
491 | required = True, |
---|
492 | constraint=validate_email, |
---|
493 | ) |
---|