1 | """Faculty components. |
---|
2 | """ |
---|
3 | |
---|
4 | import grok |
---|
5 | from zope.component.interfaces import IFactory |
---|
6 | from zope.interface import implementedBy |
---|
7 | from waeup.sirp.university.interfaces import ( |
---|
8 | IFaculty, IFacultyAdd, IDepartment) |
---|
9 | from waeup.sirp.university.vocabularies import inst_types |
---|
10 | |
---|
11 | class Faculty(grok.Container): |
---|
12 | """A university faculty. |
---|
13 | """ |
---|
14 | grok.implements(IFaculty, IFacultyAdd) |
---|
15 | |
---|
16 | @property # Make this method read_only and looking like an attr. |
---|
17 | def local_roles(cls): |
---|
18 | return ['waeup.local.DepartmentOfficer', |
---|
19 | 'waeup.local.ClearanceOfficer',] |
---|
20 | |
---|
21 | def __init__(self, |
---|
22 | title=u'Unnamed Faculty', |
---|
23 | title_prefix=u'faculty', |
---|
24 | code=u'NA', **kw): |
---|
25 | super(Faculty, self).__init__(**kw) |
---|
26 | self.title = title |
---|
27 | self.title_prefix = title_prefix |
---|
28 | self.code = code |
---|
29 | |
---|
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 |
---|
36 | |
---|
37 | def longtitle(self): |
---|
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 |
---|
46 | |
---|
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) |
---|