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

Last change on this file since 13347 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
RevLine 
[7195]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##
[5004]18"""Interfaces of academics specific objects.
19"""
[7670]20
[5004]21from zope import schema
[8472]22from zope.interface import Attribute, invariant, Invalid
[12414]23from waeup.kofa.interfaces import IKofaObject, IKofaContainer, validate_id
[7811]24from waeup.kofa.interfaces import MessageFactory as _
25from waeup.kofa.university.vocabularies import (
[5995]26    course_levels,
27    CourseSource,
[7681]28    StudyModeSource,
29    AppCatSource,
30    InstTypeSource,
31    SemesterSource,
[5995]32    )
[5004]33
[7819]34class IFaculty(IKofaContainer):
[5004]35    """Representation of a university faculty.
36    """
[5948]37    code = schema.TextLine(
[7707]38        title = _(u'Code'),
[5948]39        default = u'NA',
40        required = True,
[12414]41        constraint=validate_id,
[5948]42        )
43
[5004]44    title = schema.TextLine(
[7707]45        title = _(u'Name of faculty'),
[10787]46        default = u'Unnamed',
[5004]47        required = True,
48        )
49
[5988]50    title_prefix = schema.Choice(
[7707]51        title = _(u'Name prefix'),
[5004]52        default = u'faculty',
[7681]53        source = InstTypeSource(),
[5004]54        required = True,
55        )
[6561]56
57
[7819]58class IFacultiesContainer(IKofaContainer):
[5004]59    """A container for faculties.
60    """
61    def addFaculty(faculty):
62        """Add an IFactulty object.
63
64        """
[7819]65class IDepartment(IKofaObject):
[5004]66    """Representation of a department.
67    """
[5948]68    code = schema.TextLine(
[7707]69        title = _(u'Code'),
[5948]70        default = u'NA',
71        required = True,
[12414]72        constraint=validate_id,
[5948]73        )
74
[5004]75    title = schema.TextLine(
[7707]76        title = _(u'Name of department'),
[10787]77        default = u'Unnamed',
[5004]78        required = True,
79        )
80
[5988]81    title_prefix = schema.Choice(
[7707]82        title = _(u'Name prefix'),
[7681]83        source = InstTypeSource(),
[5004]84        default = u'department',
85        required = True,
86        )
87
[10634]88    score_editing_disabled = schema.Bool(
89        title = _(u'Score editing disabled'),
90        description = _(
[10642]91            u'Lectures can not edit scores if ticked.'),
[10634]92        required = False,
93        default = False,
94        )
95
[5004]96    courses = Attribute("A container for courses.")
97    certificates = Attribute("A container for certificates.")
[6561]98
99
[7819]100class ICoursesContainer(IKofaContainer):
[5004]101    """A container for faculties.
102    """
[6640]103    def addCourse(course):
[5004]104        """Add an ICourse object.
105
106        Returns the key, under which the object was stored.
107        """
108
[7819]109class ICourse(IKofaObject):
[5004]110    """Representation of a course.
111    """
112    code = schema.TextLine(
[7707]113        title = _(u'Code'),
[5004]114        default = u'NA',
115        required = True,
[12414]116        constraint=validate_id,
[5004]117        )
118
119    title = schema.TextLine(
[7707]120        title = _(u'Title of course'),
[10787]121        default = u'Unnamed',
[5004]122        required = True,
123        )
124
125    credits = schema.Int(
[7707]126        title = _(u'Credits'),
[5004]127        default = 0,
[9315]128        required = True,
[5004]129        )
[6561]130
[5004]131    passmark = schema.Int(
[7707]132        title = _(u'Passmark'),
[5004]133        default = 40,
[9315]134        required = True,
[5004]135        )
136
137    semester = schema.Choice(
[7707]138        title = _(u'Semester/Term'),
[7601]139        default = 9,
[7681]140        source = SemesterSource(),
[5004]141        required = True,
142        )
[6561]143
[9220]144    former_course = schema.Bool(
[10830]145        title = _(u'Former course'),
[9220]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
[5004]153
[7819]154class ICertificate(IKofaObject):
[5004]155    """Representation of a certificate.
156    """
157    code = schema.TextLine(
[7707]158        title = _(u'Code'),
[5004]159        default = u'NA',
160        required = True,
[12414]161        constraint=validate_id,
[5004]162        )
163
164    title = schema.TextLine(
[7707]165        title = _(u'Title'),
[11838]166        default = u'Unnamed',
[5004]167        required = True,
168        )
169
[5986]170    study_mode = schema.Choice(
[7707]171        title = _(u'Study Mode'),
[7681]172        source = StudyModeSource(),
[5951]173        default = u'ug_ft',
[5004]174        required = True,
175        )
176
[5977]177    start_level = schema.Choice(
[7707]178        title = _(u'Start Level'),
[5977]179        vocabulary = course_levels,
180        default = 100,
[5004]181        required = True,
182        )
[6561]183
[5977]184    end_level = schema.Choice(
[7707]185        title = _(u'End Level'),
[5977]186        vocabulary = course_levels,
187        default = 500,
[5004]188        required = True,
189        )
[6561]190
[5986]191    application_category = schema.Choice(
[7707]192        title = _(u'Application Category'),
[7681]193        source = AppCatSource(),
[5951]194        default = u'basic',
[5986]195        required = True,
[6561]196        )
[5004]197
[8299]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
[8967]208    school_fee_3 = schema.Float(
[8970]209        title = _(u'Foreigner Initial School Fee'),
[8967]210        required = False,
211        )
212
213    school_fee_4 = schema.Float(
[8970]214        title = _(u'Foreigner Returning School Fee'),
[8967]215        required = False,
216        )
217
[10166]218    ratio = schema.Float(
219        title = _(u'Installment Ratio'),
220        required = False,
221        min = 0.0,
222        max = 1.0,
223        )
224
[10185]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
[8472]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
[7819]259class ICertificatesContainer(IKofaContainer):
[5004]260    """A container for certificates.
261    """
[6640]262    def addCertificate(certificate):
[5004]263        """Add an ICertificate object.
264
265        Returns the key, under which the object was stored.
266        """
267
[7819]268class ICertificateCourse(IKofaObject):
[6561]269    """A certificatecourse is referring a course and provides some own
270       attributes.
[5004]271    """
272    course = schema.Choice(
[8920]273        title = _(u'Course'),
[5004]274        source = CourseSource(),
275        )
[6561]276
[5977]277    level = schema.Choice(
[7707]278        title = _(u'Level'),
[5004]279        required = True,
[5977]280        vocabulary = course_levels,
[5950]281        readonly = False,
[5004]282        )
283
[7665]284    mandatory = schema.Bool(
[9246]285        title = _(u'Registration required'),
[9035]286        required = False,
[5950]287        default = True,
[5004]288        )
289
290    def getCourseCode():
[5977]291        """Return the code of the course referred to.
[5004]292
293        This is needed for cataloging.
[10685]294        """
Note: See TracBrowser for help on using the repository browser.