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 { |
---|
19 | 'waeup.local.DepartmentOfficer':'Department Officer', |
---|
20 | } |
---|
21 | |
---|
22 | def __init__(self, |
---|
23 | title=u'Unnamed Faculty', |
---|
24 | title_prefix=u'faculty', |
---|
25 | code=u'NA', **kw): |
---|
26 | super(Faculty, self).__init__(**kw) |
---|
27 | self.title = title |
---|
28 | self.title_prefix = title_prefix |
---|
29 | self.code = code |
---|
30 | |
---|
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 |
---|
37 | |
---|
38 | def clear(self): |
---|
39 | """Remove all departments from faculty. |
---|
40 | """ |
---|
41 | keys = self.keys() |
---|
42 | for key in keys: |
---|
43 | del self[key] |
---|
44 | |
---|
45 | def longtitle(self): |
---|
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 |
---|
54 | |
---|
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) |
---|