## $Id: interfaces.py 9315 2012-10-08 11:35:26Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Interfaces of academics specific objects. """ from zope import schema from zope.interface import Attribute, invariant, Invalid from waeup.kofa.interfaces import (IKofaObject, IKofaContainer) from waeup.kofa.interfaces import MessageFactory as _ from waeup.kofa.university.vocabularies import ( course_levels, CourseSource, StudyModeSource, AppCatSource, InstTypeSource, SemesterSource, ) class IFaculty(IKofaContainer): """Representation of a university faculty. """ code = schema.TextLine( title = _(u'Code'), default = u'NA', required = True, readonly = True, ) title = schema.TextLine( title = _(u'Name of faculty'), default = _(u'Unnamed'), required = True, ) title_prefix = schema.Choice( title = _(u'Name prefix'), default = u'faculty', source = InstTypeSource(), required = True, ) def longtitle(): """ Returns the long title of a faculty. """ class IFacultyAdd(IFaculty): """Representation of a university faculty. """ code = schema.TextLine( title = _(u'Code'), description = _(u'This code will become part of the URL.'), default = u'NA', required = True, readonly = False, ) IFacultyAdd['code'].order = IFaculty['code'].order class IFacultiesContainer(IKofaContainer): """A container for faculties. """ def addFaculty(faculty): """Add an IFactulty object. """ class IDepartment(IKofaObject): """Representation of a department. """ code = schema.TextLine( title = _(u'Code'), default = u'NA', required = True, readonly = True, ) title = schema.TextLine( title = _(u'Name of department'), default = _(u'Unnamed'), required = True, ) title_prefix = schema.Choice( title = _(u'Name prefix'), source = InstTypeSource(), default = u'department', required = True, ) courses = Attribute("A container for courses.") certificates = Attribute("A container for certificates.") def longtitle(): """ Returns the long title of a department. """ class IDepartmentAdd(IDepartment): """Representation of a university department. """ code = schema.TextLine( title = _(u'Code'), description = _(u'This code will become part of the URL.'), default = u'NA', required = True, readonly = False, ) IDepartmentAdd['code'].order = IDepartment['code'].order class ICoursesContainer(IKofaContainer): """A container for faculties. """ def addCourse(course): """Add an ICourse object. Returns the key, under which the object was stored. """ class ICourse(IKofaObject): """Representation of a course. """ code = schema.TextLine( title = _(u'Code'), default = u'NA', required = True, readonly = True, ) title = schema.TextLine( title = _(u'Title of course'), default = _(u'Unnamed'), required = True, ) credits = schema.Int( title = _(u'Credits'), default = 0, required = True, ) passmark = schema.Int( title = _(u'Passmark'), default = 40, required = True, ) semester = schema.Choice( title = _(u'Semester/Term'), default = 9, source = SemesterSource(), required = True, ) former_course = schema.Bool( title = _(u'Former Course'), description = _( u'If this attribute is being set all certificate courses ' 'referring to this course will be automatically deleted.'), required = False, default = False, ) def longtitle(): """ Returns the long title of a course. """ class ICourseAdd(ICourse): """Representation of a course. """ code = schema.TextLine( title = _(u'Code'), description = _(u'Enter unique course code which will become part of the URL.'), default = u'NA', required = True, readonly = False, ) ICourseAdd['code'].order = ICourse['code'].order class ICertificate(IKofaObject): """Representation of a certificate. """ code = schema.TextLine( title = _(u'Code'), default = u'NA', required = True, readonly = True, ) title = schema.TextLine( title = _(u'Title'), default = _(u'Unnamed Certificate'), required = True, ) study_mode = schema.Choice( title = _(u'Study Mode'), source = StudyModeSource(), default = u'ug_ft', required = True, ) start_level = schema.Choice( title = _(u'Start Level'), vocabulary = course_levels, default = 100, required = True, ) end_level = schema.Choice( title = _(u'End Level'), vocabulary = course_levels, default = 500, required = True, ) application_category = schema.Choice( title = _(u'Application Category'), source = AppCatSource(), default = u'basic', required = True, ) school_fee_1 = schema.Float( title = _(u'Initial School Fee'), required = False, ) school_fee_2 = schema.Float( title = _(u'Returning School Fee'), required = False, ) school_fee_3 = schema.Float( title = _(u'Foreigner Initial School Fee'), required = False, ) school_fee_4 = schema.Float( title = _(u'Foreigner Returning School Fee'), required = False, ) def longtitle(): """ Returns the long title of a certificate. """ @invariant def check_pg_conditions(cert): if cert.start_level == 999 and not cert.end_level == 999: raise Invalid(_("Start level and end level must correspond.")) if cert.end_level == 999 and not cert.start_level == 999: raise Invalid(_("Start level and end level must correspond.")) if cert.study_mode.startswith('pg') and not cert.start_level == 999: raise Invalid(_( "Study mode, start level and end level must correspond.")) if cert.start_level == 999 and not cert.study_mode.startswith('pg'): raise Invalid(_( "Study mode, start level and end level must correspond.")) class ICertificateAdd(ICertificate): """Representation of a certificate. """ code = schema.TextLine( title = _(u'Code'), default = u'NA', description = _(u'Enter unique certificate code which will become part of the URL.'), required = True, readonly = False, ) ICertificateAdd['code'].order = ICertificate['code'].order class ICertificatesContainer(IKofaContainer): """A container for certificates. """ def addCertificate(certificate): """Add an ICertificate object. Returns the key, under which the object was stored. """ class ICertificateCourse(IKofaObject): """A certificatecourse is referring a course and provides some own attributes. """ course = schema.Choice( title = _(u'Course'), source = CourseSource(), readonly = True, ) level = schema.Choice( title = _(u'Level'), required = True, vocabulary = course_levels, readonly = False, ) mandatory = schema.Bool( title = _(u'Registration required'), required = False, default = True, ) def getCourseCode(): """Return the code of the course referred to. This is needed for cataloging. """ def longtitle(): """ Returns the long title of a certificatecourse. """ class ICertificateCourseAdd(ICertificateCourse): """A certificatecourse is referring a course and provides some own attributes. """ course = schema.Choice( title = _(u'Course'), source = CourseSource(), readonly = False, ) ICertificateCourseAdd['course'].order = ICertificateCourse['course'].order