[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) |
---|
[6145] | 9 | from waeup.sirp.university.vocabularies import inst_types |
---|
[3526] | 10 | |
---|
[4789] | 11 | class Faculty(grok.Container): |
---|
| 12 | """A university faculty. |
---|
| 13 | """ |
---|
[5953] | 14 | grok.implements(IFaculty, IFacultyAdd) |
---|
[3526] | 15 | |
---|
[6145] | 16 | @property # Make this method read_only and looking like an attr. |
---|
| 17 | def local_roles(cls): |
---|
[6655] | 18 | return ['waeup.local.DepartmentOfficer', 'waeup.local.ClearanceOfficer'] |
---|
[6145] | 19 | |
---|
[4789] | 20 | def __init__(self, |
---|
| 21 | title=u'Unnamed Faculty', |
---|
| 22 | title_prefix=u'faculty', |
---|
| 23 | code=u'NA', **kw): |
---|
[3526] | 24 | super(Faculty, self).__init__(**kw) |
---|
[4789] | 25 | self.title = title |
---|
| 26 | self.title_prefix = title_prefix |
---|
| 27 | self.code = code |
---|
[3526] | 28 | |
---|
[4789] | 29 | def addDepartment(self, department): |
---|
| 30 | """Add a department to the faculty. |
---|
| 31 | """ |
---|
| 32 | if not IDepartment.providedBy(department): |
---|
| 33 | raise TypeError('Faculties contain only IDepartment instances') |
---|
| 34 | self[department.code] = department |
---|
[3526] | 35 | |
---|
[4789] | 36 | def clear(self): |
---|
| 37 | """Remove all departments from faculty. |
---|
| 38 | """ |
---|
| 39 | keys = self.keys() |
---|
| 40 | for key in keys: |
---|
| 41 | del self[key] |
---|
[3526] | 42 | |
---|
[5988] | 43 | def longtitle(self): |
---|
[5994] | 44 | try: |
---|
| 45 | result = "%s %s (%s)" % ( |
---|
| 46 | inst_types.getTerm( |
---|
| 47 | self.title_prefix).title, |
---|
| 48 | self.title, self.code) |
---|
| 49 | except: |
---|
| 50 | result = "%s (%s)" % (self.title, self.code) |
---|
| 51 | return result |
---|
[6145] | 52 | |
---|
[4789] | 53 | class FacultyFactory(grok.GlobalUtility): |
---|
| 54 | """A factory for faculty containers. |
---|
| 55 | """ |
---|
| 56 | grok.implements(IFactory) |
---|
| 57 | grok.name(u'waeup.Faculty') |
---|
| 58 | title = u"Create a new faculty.", |
---|
| 59 | description = u"This factory instantiates new faculty instances." |
---|
| 60 | |
---|
| 61 | def __call__(self, *args, **kw): |
---|
| 62 | return Faculty() |
---|
| 63 | |
---|
| 64 | def getInterfaces(self): |
---|
| 65 | return implementedBy(Faculty) |
---|