"""Faculty components. """ import grok from zope.component.interfaces import IFactory from zope.interface import implementedBy from waeup.sirp.interfaces import IFaculty, IDepartment class Faculty(grok.Container): """A university faculty. """ grok.implements(IFaculty) def __init__(self, title=u'Unnamed Faculty', title_prefix=u'faculty', code=u'NA', **kw): super(Faculty, self).__init__(**kw) self.title = title self.title_prefix = title_prefix self.code = code def addDepartment(self, department): """Add a department to the faculty. """ if not IDepartment.providedBy(department): raise TypeError('Faculties contain only IDepartment instances') self[department.code] = department def clear(self): """Remove all departments from faculty. """ keys = self.keys() for key in keys: del self[key] def getName(self, key): """Get complete faculty name. """ if key in self.keys(): dept = self[key] prefix = dept.title_prefix prefix = prefix[0].upper() + prefix[1:] return '%s of %s' % (prefix, dept.title) class FacultyFactory(grok.GlobalUtility): """A factory for faculty containers. """ grok.implements(IFactory) grok.name(u'waeup.Faculty') title = u"Create a new faculty.", description = u"This factory instantiates new faculty instances." def __call__(self, *args, **kw): return Faculty() def getInterfaces(self): return implementedBy(Faculty)