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