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