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