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 | |
---|
10 | class Faculty(grok.Container): |
---|
11 | """A university faculty. |
---|
12 | """ |
---|
13 | grok.implements(IFaculty, IFacultyAdd) |
---|
14 | |
---|
15 | def __init__(self, |
---|
16 | title=u'Unnamed Faculty', |
---|
17 | title_prefix=u'faculty', |
---|
18 | code=u'NA', **kw): |
---|
19 | super(Faculty, self).__init__(**kw) |
---|
20 | self.title = title |
---|
21 | self.title_prefix = title_prefix |
---|
22 | self.code = code |
---|
23 | |
---|
24 | def addDepartment(self, department): |
---|
25 | """Add a department to the faculty. |
---|
26 | """ |
---|
27 | if not IDepartment.providedBy(department): |
---|
28 | raise TypeError('Faculties contain only IDepartment instances') |
---|
29 | self[department.code] = department |
---|
30 | |
---|
31 | def clear(self): |
---|
32 | """Remove all departments from faculty. |
---|
33 | """ |
---|
34 | keys = self.keys() |
---|
35 | for key in keys: |
---|
36 | del self[key] |
---|
37 | |
---|
38 | #def getName(self, key): |
---|
39 | # """Get complete department name. |
---|
40 | # """ |
---|
41 | # if key in self.keys(): |
---|
42 | # dept = self[key] |
---|
43 | # prefix = dept.title_prefix |
---|
44 | # prefix = prefix[0].upper() + prefix[1:] |
---|
45 | # return '%s of %s' % (prefix, dept.title) |
---|
46 | |
---|
47 | |
---|
48 | class FacultyFactory(grok.GlobalUtility): |
---|
49 | """A factory for faculty containers. |
---|
50 | """ |
---|
51 | grok.implements(IFactory) |
---|
52 | grok.name(u'waeup.Faculty') |
---|
53 | title = u"Create a new faculty.", |
---|
54 | description = u"This factory instantiates new faculty instances." |
---|
55 | |
---|
56 | def __call__(self, *args, **kw): |
---|
57 | return Faculty() |
---|
58 | |
---|
59 | def getInterfaces(self): |
---|
60 | return implementedBy(Faculty) |
---|