1 | :mod:`waeup.kofa.university.faculty` -- Faculties |
---|
2 | ************************************************* |
---|
3 | |
---|
4 | .. module:: waeup.kofa.university.faculty |
---|
5 | |
---|
6 | Components that represent university faculties. |
---|
7 | |
---|
8 | .. :doctest: |
---|
9 | .. :layer: waeup.kofa.testing.KOFAUnitTestLayer |
---|
10 | |
---|
11 | |
---|
12 | Content Classes (models and containers) |
---|
13 | ======================================= |
---|
14 | |
---|
15 | |
---|
16 | :class:`Faculty` |
---|
17 | ---------------- |
---|
18 | |
---|
19 | .. class:: Faculty(title=u'Unnamed Faculty'[, title_prefix=u'faculty' [, code=u"NA"]]) |
---|
20 | |
---|
21 | Create a representation of a university faculty: |
---|
22 | |
---|
23 | >>> from waeup.kofa.university.faculty import Faculty |
---|
24 | >>> myfac = Faculty() |
---|
25 | >>> myfac |
---|
26 | <waeup.kofa.university.faculty.Faculty object at 0x...> |
---|
27 | |
---|
28 | Another way to create :class:`Faculty` instances is by asking |
---|
29 | for a factory called ``waeup.Faculty``. This way we can create a |
---|
30 | faculty without importing a class: |
---|
31 | |
---|
32 | >>> from zope.component import createObject |
---|
33 | >>> myfac = createObject(u'waeup.Faculty') |
---|
34 | >>> myfac |
---|
35 | <waeup.kofa.university.faculty.Faculty object at 0x...> |
---|
36 | |
---|
37 | :class:`Faculty` instances have the attributes required by the |
---|
38 | `IFaculty` interface: |
---|
39 | |
---|
40 | >>> from waeup.kofa.university.interfaces import IFaculty |
---|
41 | >>> IFaculty.providedBy(myfac) |
---|
42 | True |
---|
43 | |
---|
44 | >>> from zope.interface.verify import verifyObject |
---|
45 | >>> verifyObject(IFaculty, myfac) |
---|
46 | True |
---|
47 | |
---|
48 | .. method:: addDepartment(department) |
---|
49 | |
---|
50 | Add a department into this faculty. Faculties are containers for |
---|
51 | departments. Added objects are checked and only `IDepartment` |
---|
52 | objects accepted: |
---|
53 | |
---|
54 | >>> myfac.addDepartment(object()) |
---|
55 | Traceback (most recent call last): |
---|
56 | ... |
---|
57 | TypeError: Faculties contain only IDepartment instances |
---|
58 | |
---|
59 | >>> list(myfac.values()) |
---|
60 | [] |
---|
61 | |
---|
62 | Regular departments are accepted: |
---|
63 | |
---|
64 | >>> from waeup.kofa.university.department import Department |
---|
65 | >>> myfac.addDepartment(Department(title='Physics', |
---|
66 | ... code='DP')) |
---|
67 | |
---|
68 | >>> list(myfac.items()) |
---|
69 | [(u'DP', <waeup.kofa.university.department.Department object at 0x...>)] |
---|
70 | |
---|
71 | |
---|
72 | .. attribute:: title |
---|
73 | |
---|
74 | (string) The title of a faculty. |
---|
75 | |
---|
76 | Each faculty has a title: |
---|
77 | |
---|
78 | >>> myfac.title |
---|
79 | u'Unnamed Faculty' |
---|
80 | |
---|
81 | |
---|
82 | .. attribute:: title_prefix |
---|
83 | |
---|
84 | (string) The prefix of a faculty. |
---|
85 | |
---|
86 | Each faculty has a title prefix, which specifies the kind of |
---|
87 | institution: |
---|
88 | |
---|
89 | >>> myfac.title_prefix |
---|
90 | u'faculty' |
---|
91 | |
---|
92 | |
---|
93 | .. attribute:: code |
---|
94 | |
---|
95 | (string) An internally used unique code string. |
---|
96 | |
---|
97 | Each faculty holds a code, which might be a shortcut or |
---|
98 | abbreviation of the real faculty name. By default the code is |
---|
99 | ``NA`` (=not assigned): |
---|
100 | |
---|
101 | >>> myfac.code |
---|
102 | u'NA' |
---|
103 | |
---|
104 | |
---|
105 | Utilities |
---|
106 | ========= |
---|
107 | |
---|
108 | :class:`FacultyFactory` |
---|
109 | -------------------------- |
---|
110 | |
---|
111 | .. class:: FacultyFactory() |
---|
112 | |
---|
113 | .. attribute:: grok.name(u'waeup.Faculty') |
---|
114 | |
---|
115 | .. attribute:: grok.implements(IFactory) |
---|
116 | |
---|
117 | A named utility to deliver new instances of :class:`Faculty` |
---|
118 | without the need to import the implementation before: |
---|
119 | |
---|
120 | >>> from zope.component import createObject |
---|
121 | >>> myfaculty = createObject(u'waeup.Faculty') |
---|
122 | >>> myfaculty |
---|
123 | <waeup.kofa.university.faculty.Faculty object at 0x...> |
---|
124 | |
---|
125 | The factory complies with the specifications from the |
---|
126 | :class:`IFactory` insterface: |
---|
127 | |
---|
128 | >>> from zope.interface.verify import verifyClass |
---|
129 | >>> from zope.component.interfaces import IFactory |
---|
130 | >>> from waeup.kofa.university.faculty import FacultyFactory |
---|
131 | >>> verifyClass(IFactory, FacultyFactory) |
---|
132 | True |
---|
133 | |
---|
134 | This means also, that we can get the interfaces of the created |
---|
135 | object from the factory: |
---|
136 | |
---|
137 | >>> faculty_factory = FacultyFactory() |
---|
138 | >>> faculty_factory.getInterfaces() |
---|
139 | <implementedBy waeup.kofa.university.faculty.Faculty> |
---|
140 | |
---|
141 | |
---|
142 | Examples: |
---|
143 | ========= |
---|
144 | |
---|
145 | We can create faculties: |
---|
146 | |
---|
147 | >>> from waeup.kofa.university.faculty import Faculty |
---|
148 | >>> myfaculty = Faculty() |
---|
149 | >>> myfaculty |
---|
150 | <waeup.kofa.university.faculty.Faculty object at 0x...> |
---|
151 | |
---|
152 | Another way to create faculties is by asking for a factory called |
---|
153 | ``waeup.Faculty``. Now we can create a factory without importing a |
---|
154 | class: |
---|
155 | |
---|
156 | >>> from zope.component import createObject |
---|
157 | >>> myfaculty = createObject(u'waeup.Faculty') |
---|
158 | >>> myfaculty |
---|
159 | <waeup.kofa.university.faculty.Faculty object at 0x...> |
---|
160 | |
---|
161 | Faculty attributes |
---|
162 | ================== |
---|
163 | |
---|
164 | Faculties have the attributes required by the `IFaculty` interface: |
---|
165 | |
---|
166 | >>> from waeup.kofa.university.interfaces import IFaculty |
---|
167 | >>> IFaculty.providedBy(myfaculty) |
---|
168 | True |
---|
169 | |
---|
170 | >>> from zope.interface.verify import verifyObject |
---|
171 | >>> verifyObject(IFaculty, myfaculty) |
---|
172 | True |
---|
173 | |
---|
174 | Each of the following attributes is mandatory. |
---|
175 | |
---|
176 | `title` |
---|
177 | ------- |
---|
178 | |
---|
179 | Each faculty has a title: |
---|
180 | |
---|
181 | >>> myfaculty.title |
---|
182 | u'Unnamed Faculty' |
---|
183 | |
---|
184 | `title_prefix` |
---|
185 | -------------- |
---|
186 | |
---|
187 | Each faculty has a title prefix, which specifies the kind of |
---|
188 | institution: |
---|
189 | |
---|
190 | >>> myfaculty.title_prefix |
---|
191 | u'faculty' |
---|
192 | |
---|
193 | `code` |
---|
194 | ------ |
---|
195 | |
---|
196 | Each faculty holds a code, which might be a shortcut or abbreviation |
---|
197 | of the real faculty name. By default the code is ``NA`` (=not assigned): |
---|
198 | |
---|
199 | >>> myfaculty.code |
---|
200 | u'NA' |
---|