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

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

Add custom fields to certificates (not used in base package).

  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1## $Id: interfaces.py 10185 2013-05-22 06:45:17Z 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    courses = Attribute("A container for courses.")
106    certificates = Attribute("A container for certificates.")
107
108    def longtitle():
109        """
110        Returns the long title of a department.
111        """
112
113class IDepartmentAdd(IDepartment):
114    """Representation of a university department.
115    """
116    code = schema.TextLine(
117        title = _(u'Code'),
118        description = _(u'This code will become part of the URL.'),
119        default = u'NA',
120        required = True,
121        readonly = False,
122        )
123
124IDepartmentAdd['code'].order =  IDepartment['code'].order
125
126class ICoursesContainer(IKofaContainer):
127    """A container for faculties.
128    """
129    def addCourse(course):
130        """Add an ICourse object.
131
132        Returns the key, under which the object was stored.
133        """
134
135class ICourse(IKofaObject):
136    """Representation of a course.
137    """
138    code = schema.TextLine(
139        title = _(u'Code'),
140        default = u'NA',
141        required = True,
142        readonly = True,
143        )
144
145    title = schema.TextLine(
146        title = _(u'Title of course'),
147        default = _(u'Unnamed'),
148        required = True,
149        )
150
151    credits = schema.Int(
152        title = _(u'Credits'),
153        default = 0,
154        required = True,
155        )
156
157    passmark = schema.Int(
158        title = _(u'Passmark'),
159        default = 40,
160        required = True,
161        )
162
163    semester = schema.Choice(
164        title = _(u'Semester/Term'),
165        default = 9,
166        source = SemesterSource(),
167        required = True,
168        )
169
170    former_course = schema.Bool(
171        title = _(u'Former Course'),
172        description = _(
173            u'If this attribute is being set all certificate courses '
174            'referring to this course will be automatically deleted.'),
175        required = False,
176        default = False,
177        )
178
179    def longtitle():
180        """
181        Returns the long title of a course.
182        """
183
184class ICourseAdd(ICourse):
185    """Representation of a course.
186    """
187    code = schema.TextLine(
188        title = _(u'Code'),
189        description = _(u'Enter unique course code which will become part of the URL.'),
190        default = u'NA',
191        required = True,
192        readonly = False,
193        )
194
195ICourseAdd['code'].order =  ICourse['code'].order
196
197class ICertificate(IKofaObject):
198    """Representation of a certificate.
199    """
200    code = schema.TextLine(
201        title = _(u'Code'),
202        default = u'NA',
203        required = True,
204        readonly = True,
205        )
206
207    title = schema.TextLine(
208        title = _(u'Title'),
209        default = _(u'Unnamed Certificate'),
210        required = True,
211        )
212
213    study_mode = schema.Choice(
214        title = _(u'Study Mode'),
215        source = StudyModeSource(),
216        default = u'ug_ft',
217        required = True,
218        )
219
220    start_level = schema.Choice(
221        title = _(u'Start Level'),
222        vocabulary = course_levels,
223        default = 100,
224        required = True,
225        )
226
227    end_level = schema.Choice(
228        title = _(u'End Level'),
229        vocabulary = course_levels,
230        default = 500,
231        required = True,
232        )
233
234    application_category = schema.Choice(
235        title = _(u'Application Category'),
236        source = AppCatSource(),
237        default = u'basic',
238        required = True,
239        )
240
241    school_fee_1 = schema.Float(
242        title = _(u'Initial School Fee'),
243        required = False,
244        )
245
246    school_fee_2 = schema.Float(
247        title = _(u'Returning School Fee'),
248        required = False,
249        )
250
251    school_fee_3 = schema.Float(
252        title = _(u'Foreigner Initial School Fee'),
253        required = False,
254        )
255
256    school_fee_4 = schema.Float(
257        title = _(u'Foreigner Returning School Fee'),
258        required = False,
259        )
260
261    ratio = schema.Float(
262        title = _(u'Installment Ratio'),
263        required = False,
264        min = 0.0,
265        max = 1.0,
266        )
267
268    custom_textline_1 = schema.TextLine(
269        title = _(u'Custom Textline 1 (not used)'),
270        required = False,
271        )
272
273    custom_textline_2 = schema.TextLine(
274        title = _(u'Custom Textline 2 (not used)'),
275        required = False,
276        )
277
278    custom_float_1 = schema.Float(
279        title = _(u'Custom Float 1 (not used)'),
280        required = False,
281        )
282
283    custom_float_2 = schema.Float(
284        title = _(u'Custom Float 2 (not used)'),
285        required = False,
286        )
287
288    def longtitle():
289        """
290        Returns the long title of a certificate.
291        """
292
293    @invariant
294    def check_pg_conditions(cert):
295        if cert.start_level == 999 and not cert.end_level == 999:
296            raise Invalid(_("Start level and end level must correspond."))
297        if cert.end_level == 999 and not cert.start_level == 999:
298            raise Invalid(_("Start level and end level must correspond."))
299        if cert.study_mode.startswith('pg') and not cert.start_level == 999:
300            raise Invalid(_(
301                "Study mode, start level and end level must correspond."))
302        if cert.start_level == 999  and not cert.study_mode.startswith('pg'):
303            raise Invalid(_(
304                "Study mode, start level and end level must correspond."))
305
306
307class ICertificateAdd(ICertificate):
308    """Representation of a certificate.
309    """
310    code = schema.TextLine(
311        title = _(u'Code'),
312        default = u'NA',
313        description = _(u'Enter unique certificate code which will become part of the URL.'),
314        required = True,
315        readonly = False,
316        )
317
318ICertificateAdd['code'].order =  ICertificate['code'].order
319
320class ICertificatesContainer(IKofaContainer):
321    """A container for certificates.
322    """
323    def addCertificate(certificate):
324        """Add an ICertificate object.
325
326        Returns the key, under which the object was stored.
327        """
328
329class ICertificateCourse(IKofaObject):
330    """A certificatecourse is referring a course and provides some own
331       attributes.
332    """
333    course = schema.Choice(
334        title = _(u'Course'),
335        source = CourseSource(),
336        readonly = True,
337        )
338
339    level = schema.Choice(
340        title = _(u'Level'),
341        required = True,
342        vocabulary = course_levels,
343        readonly = False,
344        )
345
346    mandatory = schema.Bool(
347        title = _(u'Registration required'),
348        required = False,
349        default = True,
350        )
351
352    def getCourseCode():
353        """Return the code of the course referred to.
354
355        This is needed for cataloging.
356        """
357
358    def longtitle():
359        """
360        Returns the long title of a certificatecourse.
361        """
362
363
364class ICertificateCourseAdd(ICertificateCourse):
365    """A certificatecourse is referring a course and
366       provides some own attributes.
367    """
368    course = schema.Choice(
369        title = _(u'Course'),
370        source = CourseSource(),
371        readonly = False,
372        )
373
374ICertificateCourseAdd['course'].order =  ICertificateCourse['course'].order
Note: See TracBrowser for help on using the repository browser.