import grok from zope import schema from zope.interface import Attribute, invariant, Invalid from waeup.kofa.interfaces import (IKofaObject, IKofaContainer, validate_email) from waeup.kofa.university.interfaces import ICertificate from waeup.kofa.university.certificatescontainer import CertificatesContainer from waeup.kofa.university.faculty import ( Faculty, FacultyFactory) from waeup.kofa.university.department import ( Department, DepartmentFactory) from waeup.kofa.university.certificate import ( Certificate, CertificateFactory) from waeup.kofa.university.vocabularies import ( course_levels, CourseSource, StudyModeSource, AppCatSource, InstTypeSource, SemesterSource, ) from waeup.kofa.interfaces import MessageFactory as _ class ICustomFaculty(IKofaContainer): """Representation of a university faculty. """ code = schema.TextLine( title = _(u'Code'), default = u'NA', required = 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, ) address = schema.Text( title = _(u'Permanent Address'), required = False, ) email = schema.ASCIILine( title = _(u'Email'), required = False, constraint=validate_email, ) class CustomFaculty(Faculty): """A university faculty. """ grok.implements(ICustomFaculty) local_roles = [ 'waeup.local.DepartmentOfficer', 'waeup.local.DepartmentManager', ] def __init__(self, title=u'Unnamed Faculty', title_prefix=u'faculty', address=None, email=None, code=u'NA', **kw): super(Faculty, self).__init__(**kw) self.title = title self.title_prefix = title_prefix self.code = code self.address = address self.email = email class CustomFacultyFactory(FacultyFactory): """A factory for faculty containers. """ def __call__(self, *args, **kw): return CustomFaculty() def getInterfaces(self): return implementedBy(CustomFaculty) class ICustomDepartment(IKofaObject): """Representation of a department. """ code = schema.TextLine( title = _(u'Code'), default = u'NA', required = 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, ) address = schema.Text( title = _(u'Permanent Address'), required = False, ) email = schema.ASCIILine( title = _(u'Email'), required = False, constraint=validate_email, ) certificates = Attribute("A container for certificates.") class CustomDepartment(Department): """A university department. """ grok.implements(ICustomDepartment) local_roles = [ 'waeup.local.ApplicationsManager', 'waeup.local.DepartmentOfficer', 'waeup.local.DepartmentManager', ] def __init__(self, title=u'Unnamed Department', title_prefix=u'department', address=None, email=None, code=u"NA", **kw): super(Department, self).__init__(**kw) self.title = title self.title_prefix = title_prefix self.code = code self.certificates = CertificatesContainer() self.certificates.__parent__ = self self.certificates.__name__ = 'certificates' self.score_editing_disabled = False self.address = address self.email = email class CustomDepartmentFactory(DepartmentFactory): """A factory for department containers. """ def __call__(self, *args, **kw): return CustomDepartment(*args, **kw) def getInterfaces(self): """Get interfaces of objects provided by this factory. """ return implementedBy(CustomDepartment) class CustomCertificate(Certificate): """A certificate. """ grok.implements(ICertificate) local_roles = [ 'waeup.local.DepartmentOfficer', ] class CustomCertificateFactory(CertificateFactory): """A factory for certificates. """ def __call__(self, *args, **kw): return CustomCertificate(*args, **kw) def getInterfaces(self): return implementedBy(CustomCertificate)