[4789] | 1 | """Faculty components. |
---|
| 2 | """ |
---|
| 3 | |
---|
[3526] | 4 | import grok |
---|
[4789] | 5 | from zope.component.interfaces import IFactory |
---|
| 6 | from zope.interface import implementedBy |
---|
[5953] | 7 | from waeup.sirp.university.interfaces import ( |
---|
| 8 | IFaculty, IFacultyAdd, IDepartment) |
---|
[3526] | 9 | |
---|
[4789] | 10 | class Faculty(grok.Container): |
---|
| 11 | """A university faculty. |
---|
| 12 | """ |
---|
[5953] | 13 | grok.implements(IFaculty, IFacultyAdd) |
---|
[3526] | 14 | |
---|
[4789] | 15 | def __init__(self, |
---|
| 16 | title=u'Unnamed Faculty', |
---|
| 17 | title_prefix=u'faculty', |
---|
| 18 | code=u'NA', **kw): |
---|
[3526] | 19 | super(Faculty, self).__init__(**kw) |
---|
[4789] | 20 | self.title = title |
---|
| 21 | self.title_prefix = title_prefix |
---|
| 22 | self.code = code |
---|
[3526] | 23 | |
---|
[4789] | 24 | def addDepartment(self, department): |
---|
| 25 | """Add a department to the faculty. |
---|
| 26 | """ |
---|
| 27 | if not IDepartment.providedBy(department): |
---|
| 28 | raise TypeError('Faculties contain only IDepartment instances') |
---|
| 29 | self[department.code] = department |
---|
[3526] | 30 | |
---|
[4789] | 31 | def clear(self): |
---|
| 32 | """Remove all departments from faculty. |
---|
| 33 | """ |
---|
| 34 | keys = self.keys() |
---|
| 35 | for key in keys: |
---|
| 36 | del self[key] |
---|
[3526] | 37 | |
---|
[5915] | 38 | #def getName(self, key): |
---|
| 39 | # """Get complete department name. |
---|
| 40 | # """ |
---|
| 41 | # if key in self.keys(): |
---|
| 42 | # dept = self[key] |
---|
| 43 | # prefix = dept.title_prefix |
---|
| 44 | # prefix = prefix[0].upper() + prefix[1:] |
---|
| 45 | # return '%s of %s' % (prefix, dept.title) |
---|
[4789] | 46 | |
---|
| 47 | |
---|
| 48 | class FacultyFactory(grok.GlobalUtility): |
---|
| 49 | """A factory for faculty containers. |
---|
| 50 | """ |
---|
| 51 | grok.implements(IFactory) |
---|
| 52 | grok.name(u'waeup.Faculty') |
---|
| 53 | title = u"Create a new faculty.", |
---|
| 54 | description = u"This factory instantiates new faculty instances." |
---|
| 55 | |
---|
| 56 | def __call__(self, *args, **kw): |
---|
| 57 | return Faculty() |
---|
| 58 | |
---|
| 59 | def getInterfaces(self): |
---|
| 60 | return implementedBy(Faculty) |
---|