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