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.interfaces import IFaculty, IDepartment |
---|
8 | |
---|
9 | class Faculty(grok.Container): |
---|
10 | """A university faculty. |
---|
11 | """ |
---|
12 | grok.implements(IFaculty) |
---|
13 | |
---|
14 | def __init__(self, |
---|
15 | title=u'Unnamed Faculty', |
---|
16 | title_prefix=u'faculty', |
---|
17 | code=u'NA', **kw): |
---|
18 | super(Faculty, self).__init__(**kw) |
---|
19 | self.title = title |
---|
20 | self.title_prefix = title_prefix |
---|
21 | self.code = code |
---|
22 | |
---|
23 | def addDepartment(self, department): |
---|
24 | """Add a department to the faculty. |
---|
25 | """ |
---|
26 | if not IDepartment.providedBy(department): |
---|
27 | raise TypeError('Faculties contain only IDepartment instances') |
---|
28 | self[department.code] = department |
---|
29 | |
---|
30 | def clear(self): |
---|
31 | """Remove all departments from faculty. |
---|
32 | """ |
---|
33 | keys = self.keys() |
---|
34 | for key in keys: |
---|
35 | del self[key] |
---|
36 | |
---|
37 | def getName(self, key): |
---|
38 | """Get complete faculty name. |
---|
39 | """ |
---|
40 | if key in self.keys(): |
---|
41 | dept = self[key] |
---|
42 | prefix = dept.title_prefix |
---|
43 | prefix = prefix[0].upper() + prefix[1:] |
---|
44 | return '%s of %s' % (prefix, dept.title) |
---|
45 | |
---|
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) |
---|