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