"""University departments. """ import grok from zope.component import createObject from zope.component.interfaces import IFactory from zope.interface import implementedBy from waeup.sirp.university.interfaces import IDepartment, IDepartmentAdd from waeup.sirp.university.vocabularies import inst_types class Department(grok.Container): """A university department. """ grok.implements(IDepartment, IDepartmentAdd) @property # Make this method read_only and looking like an attr. def local_roles(cls): return ['waeup.local.DepartmentOfficer', 'waeup.local.ClearanceOfficer',] # A simple counter for ids. next_id = 0L def __init__(self, title=u'Unnamed Department', title_prefix=u'department', code=u"NA", **kw): super(Department, self).__init__(**kw) self.title = title self.title_prefix = title_prefix self.code = code self.courses = createObject(u'waeup.CourseContainer') self.courses.__parent__ = self self.courses.__name__ = 'courses' self.certificates = createObject(u'waeup.CertificateContainer') self.certificates.__parent__ = self self.certificates.__name__ = 'certificates' def traverse(self, name): """Deliver appropriate containers, if someone wants to go to courses or departments. """ if name == 'courses': return self.courses elif name == 'certificates': return self.certificates return None def longtitle(self): return "%s %s (%s)" % ( inst_types.getTerm(self.title_prefix).title, self.title, self.code) class DepartmentFactory(grok.GlobalUtility): """A factory for department containers. """ grok.implements(IFactory) grok.name(u'waeup.Department') title = u"Create a new department.", description = u"This factory instantiates new department instances." def __call__(self, *args, **kw): return Department(*args, **kw) def getInterfaces(self): """Get interfaces of objects provided by this factory. """ return implementedBy(Department)