1 | ## $Id: interfaces.py 15422 2019-05-24 09:11:40Z 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 | """Interfaces of academics specific objects. |
---|
19 | """ |
---|
20 | |
---|
21 | from zope import schema |
---|
22 | from zope.interface import Attribute, invariant, Invalid |
---|
23 | from waeup.kofa.interfaces import ( |
---|
24 | IKofaObject, IKofaContainer, validate_id, academic_sessions_vocab) |
---|
25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
26 | from waeup.kofa.university.vocabularies import ( |
---|
27 | course_levels, |
---|
28 | CourseSource, |
---|
29 | StudyModeSource, |
---|
30 | AppCatSource, |
---|
31 | InstTypeSource, |
---|
32 | SemesterSource, |
---|
33 | DegreeSource, |
---|
34 | CourseCategorySource |
---|
35 | ) |
---|
36 | |
---|
37 | class IFaculty(IKofaContainer): |
---|
38 | """Representation of a university faculty. |
---|
39 | """ |
---|
40 | code = schema.TextLine( |
---|
41 | title = _(u'Code'), |
---|
42 | default = u'NA', |
---|
43 | required = True, |
---|
44 | constraint=validate_id, |
---|
45 | ) |
---|
46 | |
---|
47 | title = schema.TextLine( |
---|
48 | title = _(u'Name of faculty'), |
---|
49 | default = u'Unnamed', |
---|
50 | required = True, |
---|
51 | ) |
---|
52 | |
---|
53 | title_prefix = schema.Choice( |
---|
54 | title = _(u'Name prefix'), |
---|
55 | default = u'faculty', |
---|
56 | source = InstTypeSource(), |
---|
57 | required = True, |
---|
58 | ) |
---|
59 | |
---|
60 | officer_1 = schema.TextLine( |
---|
61 | title = _(u'Faculty Officer 1'), |
---|
62 | default = u'', |
---|
63 | required = False, |
---|
64 | ) |
---|
65 | |
---|
66 | officer_2 = schema.TextLine( |
---|
67 | title = _(u'Faculty Officer 2'), |
---|
68 | default = u'', |
---|
69 | required = False, |
---|
70 | ) |
---|
71 | |
---|
72 | |
---|
73 | class IFacultiesContainer(IKofaContainer): |
---|
74 | """A container for faculties. |
---|
75 | """ |
---|
76 | def addFaculty(faculty): |
---|
77 | """Add an IFactulty object. |
---|
78 | |
---|
79 | """ |
---|
80 | class IDepartment(IKofaObject): |
---|
81 | """Representation of a department. |
---|
82 | """ |
---|
83 | code = schema.TextLine( |
---|
84 | title = _(u'Code'), |
---|
85 | default = u'NA', |
---|
86 | required = True, |
---|
87 | constraint=validate_id, |
---|
88 | ) |
---|
89 | |
---|
90 | title = schema.TextLine( |
---|
91 | title = _(u'Name of department'), |
---|
92 | default = u'Unnamed', |
---|
93 | required = True, |
---|
94 | ) |
---|
95 | |
---|
96 | title_prefix = schema.Choice( |
---|
97 | title = _(u'Name prefix'), |
---|
98 | source = InstTypeSource(), |
---|
99 | default = u'department', |
---|
100 | required = True, |
---|
101 | ) |
---|
102 | |
---|
103 | score_editing_disabled = schema.Bool( |
---|
104 | title = _(u'Score editing disabled'), |
---|
105 | description = _( |
---|
106 | u'Lectures can not edit scores if ticked.'), |
---|
107 | required = False, |
---|
108 | default = False, |
---|
109 | ) |
---|
110 | |
---|
111 | officer_1 = schema.TextLine( |
---|
112 | title = _(u'Department Officer 1'), |
---|
113 | default = u'', |
---|
114 | required = False, |
---|
115 | ) |
---|
116 | |
---|
117 | officer_2 = schema.TextLine( |
---|
118 | title = _(u'Department Officer 2'), |
---|
119 | default = u'', |
---|
120 | required = False, |
---|
121 | ) |
---|
122 | |
---|
123 | officer_3 = schema.TextLine( |
---|
124 | title = _(u'Department Officer 3'), |
---|
125 | default = u'', |
---|
126 | required = False, |
---|
127 | ) |
---|
128 | |
---|
129 | officer_4 = schema.TextLine( |
---|
130 | title = _(u'Department Officer 4'), |
---|
131 | default = u'', |
---|
132 | required = False, |
---|
133 | ) |
---|
134 | |
---|
135 | courses = Attribute("A container for courses.") |
---|
136 | certificates = Attribute("A container for certificates.") |
---|
137 | |
---|
138 | |
---|
139 | class ICoursesContainer(IKofaContainer): |
---|
140 | """A container for faculties. |
---|
141 | """ |
---|
142 | def addCourse(course): |
---|
143 | """Add an ICourse object. |
---|
144 | |
---|
145 | Returns the key, under which the object was stored. |
---|
146 | """ |
---|
147 | |
---|
148 | class ICourse(IKofaObject): |
---|
149 | """Representation of a course. |
---|
150 | """ |
---|
151 | code = schema.TextLine( |
---|
152 | title = _(u'Code'), |
---|
153 | default = u'NA', |
---|
154 | required = True, |
---|
155 | constraint=validate_id, |
---|
156 | ) |
---|
157 | |
---|
158 | title = schema.TextLine( |
---|
159 | title = _(u'Title of course'), |
---|
160 | default = u'Unnamed', |
---|
161 | required = True, |
---|
162 | ) |
---|
163 | |
---|
164 | credits = schema.Int( |
---|
165 | title = _(u'Credits'), |
---|
166 | default = 0, |
---|
167 | required = True, |
---|
168 | ) |
---|
169 | |
---|
170 | passmark = schema.Int( |
---|
171 | title = _(u'Passmark'), |
---|
172 | default = 40, |
---|
173 | required = True, |
---|
174 | ) |
---|
175 | |
---|
176 | semester = schema.Choice( |
---|
177 | title = _(u'Semester/Term'), |
---|
178 | default = 9, |
---|
179 | source = SemesterSource(), |
---|
180 | required = True, |
---|
181 | ) |
---|
182 | |
---|
183 | former_course = schema.Bool( |
---|
184 | title = _(u'Former course'), |
---|
185 | description = _( |
---|
186 | u'If this attribute is being set all certificate courses ' |
---|
187 | 'referring to this course will be automatically deleted.'), |
---|
188 | required = False, |
---|
189 | default = False, |
---|
190 | ) |
---|
191 | |
---|
192 | results_validated_by = schema.TextLine( |
---|
193 | title = _(u'Results validated by'), |
---|
194 | default = None, |
---|
195 | required = False, |
---|
196 | ) |
---|
197 | |
---|
198 | results_validation_date = schema.Datetime( |
---|
199 | title = _(u'Results validation date'), |
---|
200 | required = False, |
---|
201 | readonly = False, |
---|
202 | ) |
---|
203 | |
---|
204 | results_validation_session = schema.Choice( |
---|
205 | title = _(u'Results validation session'), |
---|
206 | source = academic_sessions_vocab, |
---|
207 | required = False, |
---|
208 | readonly = False, |
---|
209 | ) |
---|
210 | |
---|
211 | class ICertificate(IKofaObject): |
---|
212 | """Representation of a certificate. |
---|
213 | """ |
---|
214 | code = schema.TextLine( |
---|
215 | title = _(u'Code'), |
---|
216 | default = u'NA', |
---|
217 | required = True, |
---|
218 | constraint=validate_id, |
---|
219 | ) |
---|
220 | |
---|
221 | title = schema.TextLine( |
---|
222 | title = _(u'Title'), |
---|
223 | default = u'Unnamed', |
---|
224 | required = True, |
---|
225 | ) |
---|
226 | |
---|
227 | study_mode = schema.Choice( |
---|
228 | title = _(u'Study Mode'), |
---|
229 | source = StudyModeSource(), |
---|
230 | default = u'ug_ft', |
---|
231 | required = True, |
---|
232 | ) |
---|
233 | |
---|
234 | degree = schema.Choice( |
---|
235 | title = _(u'Degree'), |
---|
236 | source = DegreeSource(), |
---|
237 | required = False, |
---|
238 | ) |
---|
239 | |
---|
240 | start_level = schema.Choice( |
---|
241 | title = _(u'Start Level'), |
---|
242 | vocabulary = course_levels, |
---|
243 | default = 100, |
---|
244 | required = True, |
---|
245 | ) |
---|
246 | |
---|
247 | end_level = schema.Choice( |
---|
248 | title = _(u'End Level'), |
---|
249 | vocabulary = course_levels, |
---|
250 | default = 500, |
---|
251 | required = True, |
---|
252 | ) |
---|
253 | |
---|
254 | application_category = schema.Choice( |
---|
255 | title = _(u'Application Category'), |
---|
256 | source = AppCatSource(), |
---|
257 | default = u'basic', |
---|
258 | required = True, |
---|
259 | ) |
---|
260 | |
---|
261 | school_fee_1 = schema.Float( |
---|
262 | title = _(u'Initial School Fee'), |
---|
263 | required = False, |
---|
264 | default = 0.0, |
---|
265 | ) |
---|
266 | |
---|
267 | school_fee_2 = schema.Float( |
---|
268 | title = _(u'Returning School Fee'), |
---|
269 | required = False, |
---|
270 | default = 0.0, |
---|
271 | ) |
---|
272 | |
---|
273 | school_fee_3 = schema.Float( |
---|
274 | title = _(u'Foreigner Initial School Fee'), |
---|
275 | required = False, |
---|
276 | default = 0.0, |
---|
277 | ) |
---|
278 | |
---|
279 | school_fee_4 = schema.Float( |
---|
280 | title = _(u'Foreigner Returning School Fee'), |
---|
281 | required = False, |
---|
282 | default = 0.0, |
---|
283 | ) |
---|
284 | |
---|
285 | ratio = schema.Float( |
---|
286 | title = _(u'Installment Ratio'), |
---|
287 | required = False, |
---|
288 | min = 0.0, |
---|
289 | max = 1.0, |
---|
290 | ) |
---|
291 | |
---|
292 | custom_textline_1 = schema.TextLine( |
---|
293 | title = _(u'Custom Textline 1 (not used)'), |
---|
294 | required = False, |
---|
295 | ) |
---|
296 | |
---|
297 | custom_textline_2 = schema.TextLine( |
---|
298 | title = _(u'Custom Textline 2 (not used)'), |
---|
299 | required = False, |
---|
300 | ) |
---|
301 | |
---|
302 | custom_float_1 = schema.Float( |
---|
303 | title = _(u'Custom Float 1 (not used)'), |
---|
304 | required = False, |
---|
305 | ) |
---|
306 | |
---|
307 | custom_float_2 = schema.Float( |
---|
308 | title = _(u'Custom Float 2 (not used)'), |
---|
309 | required = False, |
---|
310 | ) |
---|
311 | |
---|
312 | @invariant |
---|
313 | def check_pg_conditions(cert): |
---|
314 | if cert.start_level == 999 and not cert.end_level == 999: |
---|
315 | raise Invalid(_("Start level and end level must correspond.")) |
---|
316 | if cert.end_level == 999 and not cert.start_level == 999: |
---|
317 | raise Invalid(_("Start level and end level must correspond.")) |
---|
318 | if cert.study_mode.startswith('pg') and not cert.start_level == 999: |
---|
319 | raise Invalid(_( |
---|
320 | "Study mode, start level and end level must correspond.")) |
---|
321 | if cert.start_level == 999 and not cert.study_mode.startswith('pg'): |
---|
322 | raise Invalid(_( |
---|
323 | "Study mode, start level and end level must correspond.")) |
---|
324 | |
---|
325 | |
---|
326 | class ICertificatesContainer(IKofaContainer): |
---|
327 | """A container for certificates. |
---|
328 | """ |
---|
329 | def addCertificate(certificate): |
---|
330 | """Add an ICertificate object. |
---|
331 | |
---|
332 | Returns the key, under which the object was stored. |
---|
333 | """ |
---|
334 | |
---|
335 | class ICertificateCourse(IKofaObject): |
---|
336 | """A certificatecourse is referring a course and provides some own |
---|
337 | attributes. |
---|
338 | """ |
---|
339 | course = schema.Choice( |
---|
340 | title = _(u'Course'), |
---|
341 | source = CourseSource(), |
---|
342 | ) |
---|
343 | |
---|
344 | level = schema.Choice( |
---|
345 | title = _(u'Level'), |
---|
346 | required = True, |
---|
347 | vocabulary = course_levels, |
---|
348 | readonly = False, |
---|
349 | ) |
---|
350 | |
---|
351 | course_category = schema.Choice( |
---|
352 | title = _(u'Course Category'), |
---|
353 | source = CourseCategorySource(), |
---|
354 | required = False, |
---|
355 | ) |
---|
356 | |
---|
357 | mandatory = schema.Bool( |
---|
358 | title = _(u'Registration required'), |
---|
359 | required = False, |
---|
360 | default = True, |
---|
361 | ) |
---|
362 | |
---|
363 | def getCourseCode(): |
---|
364 | """Return the code of the course referred to. |
---|
365 | |
---|
366 | This is needed for cataloging. |
---|
367 | """ |
---|