"""Interfaces of academics specific objects. """ from zc.sourcefactory.basic import BasicSourceFactory from zope import schema try: from zope.catalog.interfaces import ICatalog except ImportError: # BBB from zope.app.catalog.interfaces import ICatalog from zope.component import getUtility from zope.interface import Attribute from waeup.sirp.interfaces import (IWAeUPObject, IWAeUPContainer, SimpleWAeUPVocabulary) class CourseSource(BasicSourceFactory): """A course source delivers all courses inside the portal by looking up a catalog. """ def getValues(self): catalog = getUtility(ICatalog, name='courses_catalog') return list(catalog.searchResults(code=('', 'z*'))) def getToken(self, value): return value.code def getTitle(self, value): return "%s - %s" % (value.code, value.title[:64]) class IFaculty(IWAeUPContainer): """Representation of a university faculty. """ code = schema.TextLine( title = u'Code', description = u'Abbreviated code of the faculty', default = u'NA', required = True, readonly = True, ) title = schema.TextLine( title = u'Name of Faculty', default = u'Unnamed', required = True, ) title_prefix = schema.TextLine( title = u'Title prefix', default = u'faculty', required = True, ) class IFacultyAdd(IFaculty): """Representation of a university faculty. """ code = schema.TextLine( title = u'Code', description = u'Abbreviated code of the faculty', default = u'NA', required = True, readonly = False, ) IFacultyAdd['code'].order = IFaculty['code'].order class IFacultyContainer(IWAeUPContainer): """A container for faculties. """ def addFaculty(faculty): """Add an IFactulty object. Returns the key, under which the object was stored. """ class IDepartment(IWAeUPObject): """Representation of a department. """ code = schema.TextLine( title = u'Code', default = u'NA', description = u'Abbreviated code of the department', required = True, readonly = True, ) title = schema.TextLine( title = u'Name of Department', default = u'Unnamed', required = True, ) title_prefix = schema.TextLine( title = u'Title prefix', default = u'department', required = True, ) courses = Attribute("A container for courses.") certificates = Attribute("A container for certificates.") class IDepartmentAdd(IDepartment): """Representation of a university department. """ code = schema.TextLine( title = u'Code', default = u'NA', description = u'Abbreviated code of the department', required = True, readonly = False, ) IDepartmentAdd['code'].order = IDepartment['code'].order class ICourseContainer(IWAeUPContainer): """A container for faculties. """ def addCourse(faculty): """Add an ICourse object. Returns the key, under which the object was stored. """ class ICourse(IWAeUPObject): """Representation of a course. """ code = schema.TextLine( title = u'Code', default = u'NA', description = u'Abbreviated code of the course', 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 = False, ) passmark = schema.Int( title = u'Passmark', default = 40, required = False, ) semester = schema.Choice( title = u'Semester/Term', default = 0, vocabulary = SimpleWAeUPVocabulary( ('N/A', 0), ('First Semester', 1), ('Second Semester', 2), ('Combined', 3)), required = True, ) class ICourseAdd(ICourse): """Representation of a course. """ code = schema.TextLine( title = u'Code', default = u'NA', description = u'Abbreviated code of the course', required = True, readonly = False, ) ICourseAdd['code'].order = ICourse['code'].order class ICertificate(IWAeUPObject): """Representation of a certificate. """ code = schema.TextLine( title = u'Code', default = u'NA', description = u'Abbreviated code of the certificate.', required = True, readonly = True, ) #review_state = schema.Choice( # title = u'Review State', # default = 'unchecked', # values = ['unchecked', 'checked'] # ) title = schema.TextLine( title = u'Title', default = u'Unnamed', required = True, ) study_mode = schema.TextLine( title = u'Study Mode', default = u'ug_ft', required = True, ) start_level = schema.TextLine( title = u'Start Level', default = u'100', required = True, ) end_level = schema.TextLine( title = u'End Level', default = u'500', required = True, ) application_category = schema.TextLine( title = u'Application Category', default = u'basic', required = False, ) class ICertificateAdd(ICertificate): """Representation of a certificate. """ code = schema.TextLine( title = u'Code', default = u'NA', description = u'Abbreviated code of the certificate.', required = True, readonly = False, ) ICertificateAdd['code'].order = ICertificate['code'].order class ICertificateContainer(IWAeUPContainer): """A container for certificates. """ def addCertificate(faculty): """Add an ICertificate object. Returns the key, under which the object was stored. """ class ICertificateCourse(IWAeUPObject): """A certificatecourse is a course referenced by a certificate, which provides some own attributes. """ course = schema.Choice( title = u'Course referenced', source = CourseSource(), readonly = True, ) level = schema.Int( title = u'Level', required = True, default = 100, readonly = False, ) core_or_elective = schema.Bool( title = u'Is mandatory course (not elective)', required = True, default = True, ) def getCourseCode(): """Return the code of the referenced course. This is needed for cataloging. """ class ICertificateCourseAdd(ICertificateCourse): """A certificatecourse is a course referenced by a certificate, which provides some own attributes. """ course = schema.Choice( title = u'Course to be referenced', source = CourseSource(), readonly = False, ) ICertificateCourseAdd['course'].order = ICertificateCourse['course'].order