[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): |
---|
| 18 | return [ |
---|
| 19 | {'name':'waeup.local.DepartmentOfficer', |
---|
| 20 | 'title':'Department Officer'}, |
---|
| 21 | ] |
---|
| 22 | |
---|
[4789] | 23 | def __init__(self, |
---|
| 24 | title=u'Unnamed Faculty', |
---|
| 25 | title_prefix=u'faculty', |
---|
| 26 | code=u'NA', **kw): |
---|
[3526] | 27 | super(Faculty, self).__init__(**kw) |
---|
[4789] | 28 | self.title = title |
---|
| 29 | self.title_prefix = title_prefix |
---|
| 30 | self.code = code |
---|
[3526] | 31 | |
---|
[4789] | 32 | def addDepartment(self, department): |
---|
| 33 | """Add a department to the faculty. |
---|
| 34 | """ |
---|
| 35 | if not IDepartment.providedBy(department): |
---|
| 36 | raise TypeError('Faculties contain only IDepartment instances') |
---|
| 37 | self[department.code] = department |
---|
[3526] | 38 | |
---|
[4789] | 39 | def clear(self): |
---|
| 40 | """Remove all departments from faculty. |
---|
| 41 | """ |
---|
| 42 | keys = self.keys() |
---|
| 43 | for key in keys: |
---|
| 44 | del self[key] |
---|
[3526] | 45 | |
---|
[5988] | 46 | def longtitle(self): |
---|
[5994] | 47 | try: |
---|
| 48 | result = "%s %s (%s)" % ( |
---|
| 49 | inst_types.getTerm( |
---|
| 50 | self.title_prefix).title, |
---|
| 51 | self.title, self.code) |
---|
| 52 | except: |
---|
| 53 | result = "%s (%s)" % (self.title, self.code) |
---|
| 54 | return result |
---|
[6145] | 55 | |
---|
[4789] | 56 | class FacultyFactory(grok.GlobalUtility): |
---|
| 57 | """A factory for faculty containers. |
---|
| 58 | """ |
---|
| 59 | grok.implements(IFactory) |
---|
| 60 | grok.name(u'waeup.Faculty') |
---|
| 61 | title = u"Create a new faculty.", |
---|
| 62 | description = u"This factory instantiates new faculty instances." |
---|
| 63 | |
---|
| 64 | def __call__(self, *args, **kw): |
---|
| 65 | return Faculty() |
---|
| 66 | |
---|
| 67 | def getInterfaces(self): |
---|
| 68 | return implementedBy(Faculty) |
---|