source: main/waeup.kofa/trunk/src/waeup/kofa/university/interfaces.py @ 10634

Last change on this file since 10634 was 10634, checked in by Henrik Bettermann, 11 years ago

Disable score editing on department manage page.

Add tests.

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