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