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

Last change on this file since 12500 was 12414, checked in by Henrik Bettermann, 10 years ago

Validate all codes in Kofa.

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