[4920] | 1 | :mod:`waeup.sirp.university.faculty` -- Faculties |
---|
| 2 | ************************************************* |
---|
[4157] | 3 | |
---|
[4920] | 4 | .. module:: waeup.sirp.university.faculty |
---|
[4423] | 5 | |
---|
| 6 | Components that represent university faculties. |
---|
| 7 | |
---|
[5140] | 8 | .. :doctest: |
---|
| 9 | .. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer |
---|
[4157] | 10 | |
---|
| 11 | |
---|
[4423] | 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 | |
---|
[4920] | 23 | >>> from waeup.sirp.university.faculty import Faculty |
---|
[4423] | 24 | >>> myfac = Faculty() |
---|
| 25 | >>> myfac |
---|
[4920] | 26 | <waeup.sirp.university.faculty.Faculty object at 0x...> |
---|
[4423] | 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 |
---|
[4920] | 35 | <waeup.sirp.university.faculty.Faculty object at 0x...> |
---|
[4423] | 36 | |
---|
| 37 | :class:`Faculty` instances have the attributes required by the |
---|
| 38 | `IFaculty` interface: |
---|
| 39 | |
---|
[5005] | 40 | >>> from waeup.sirp.university.interfaces import IFaculty |
---|
[4423] | 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 | |
---|
[4920] | 64 | >>> from waeup.sirp.university.department import Department |
---|
[4423] | 65 | >>> myfac.addDepartment(Department(title='Physics', |
---|
| 66 | ... code='DP')) |
---|
| 67 | |
---|
| 68 | >>> list(myfac.items()) |
---|
[4920] | 69 | [(u'DP', <waeup.sirp.university.department.Department object at 0x...>)] |
---|
[4423] | 70 | |
---|
| 71 | .. method:: clear() |
---|
| 72 | |
---|
| 73 | Remove all departments from this faculty: |
---|
| 74 | |
---|
| 75 | >>> myfac.clear() |
---|
| 76 | >>> list(myfac.items()) |
---|
| 77 | [] |
---|
| 78 | |
---|
| 79 | .. attribute:: title |
---|
| 80 | |
---|
| 81 | (string) The title of a faculty. |
---|
| 82 | |
---|
| 83 | Each faculty has a title: |
---|
| 84 | |
---|
| 85 | >>> myfac.title |
---|
| 86 | u'Unnamed Faculty' |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | .. attribute:: title_prefix |
---|
| 90 | |
---|
| 91 | (string) The prefix of a faculty. |
---|
| 92 | |
---|
| 93 | Each faculty has a title prefix, which specifies the kind of |
---|
| 94 | institution: |
---|
| 95 | |
---|
| 96 | >>> myfac.title_prefix |
---|
| 97 | u'faculty' |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | .. attribute:: code |
---|
| 101 | |
---|
| 102 | (string) An internally used unique code string. |
---|
| 103 | |
---|
| 104 | Each faculty holds a code, which might be a shortcut or |
---|
| 105 | abbreviation of the real faculty name. By default the code is |
---|
| 106 | ``NA`` (=not assigned): |
---|
| 107 | |
---|
| 108 | >>> myfac.code |
---|
| 109 | u'NA' |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | Utilities |
---|
| 113 | ========= |
---|
| 114 | |
---|
| 115 | :class:`FacultyFactory` |
---|
| 116 | -------------------------- |
---|
| 117 | |
---|
| 118 | .. class:: FacultyFactory() |
---|
| 119 | |
---|
| 120 | .. attribute:: grok.name(u'waeup.Faculty') |
---|
| 121 | |
---|
| 122 | .. attribute:: grok.implements(IFactory) |
---|
| 123 | |
---|
| 124 | A named utility to deliver new instances of :class:`Faculty` |
---|
| 125 | without the need to import the implementation before: |
---|
| 126 | |
---|
| 127 | >>> from zope.component import createObject |
---|
| 128 | >>> myfaculty = createObject(u'waeup.Faculty') |
---|
| 129 | >>> myfaculty |
---|
[4920] | 130 | <waeup.sirp.university.faculty.Faculty object at 0x...> |
---|
[4423] | 131 | |
---|
| 132 | The factory complies with the specifications from the |
---|
| 133 | :class:`IFactory` insterface: |
---|
| 134 | |
---|
| 135 | >>> from zope.interface.verify import verifyClass |
---|
| 136 | >>> from zope.component.interfaces import IFactory |
---|
[4920] | 137 | >>> from waeup.sirp.university.faculty import FacultyFactory |
---|
[4423] | 138 | >>> verifyClass(IFactory, FacultyFactory) |
---|
| 139 | True |
---|
| 140 | |
---|
| 141 | This means also, that we can get the interfaces of the created |
---|
| 142 | object from the factory: |
---|
| 143 | |
---|
| 144 | >>> faculty_factory = FacultyFactory() |
---|
| 145 | >>> faculty_factory.getInterfaces() |
---|
[4920] | 146 | <implementedBy waeup.sirp.university.faculty.Faculty> |
---|
[4423] | 147 | |
---|
| 148 | |
---|
| 149 | Examples: |
---|
| 150 | ========= |
---|
| 151 | |
---|
[4157] | 152 | We can create faculties: |
---|
| 153 | |
---|
[4920] | 154 | >>> from waeup.sirp.university.faculty import Faculty |
---|
[4157] | 155 | >>> myfaculty = Faculty() |
---|
| 156 | >>> myfaculty |
---|
[4920] | 157 | <waeup.sirp.university.faculty.Faculty object at 0x...> |
---|
[4157] | 158 | |
---|
| 159 | Another way to create faculties is by asking for a factory called |
---|
[4423] | 160 | ``waeup.Faculty``. Now we can create a factory without importing a |
---|
| 161 | class: |
---|
[4157] | 162 | |
---|
| 163 | >>> from zope.component import createObject |
---|
| 164 | >>> myfaculty = createObject(u'waeup.Faculty') |
---|
| 165 | >>> myfaculty |
---|
[4920] | 166 | <waeup.sirp.university.faculty.Faculty object at 0x...> |
---|
[4157] | 167 | |
---|
| 168 | Faculty attributes |
---|
| 169 | ================== |
---|
| 170 | |
---|
| 171 | Faculties have the attributes required by the `IFaculty` interface: |
---|
| 172 | |
---|
[5005] | 173 | >>> from waeup.sirp.university.interfaces import IFaculty |
---|
[4157] | 174 | >>> IFaculty.providedBy(myfaculty) |
---|
| 175 | True |
---|
| 176 | |
---|
| 177 | >>> from zope.interface.verify import verifyObject |
---|
| 178 | >>> verifyObject(IFaculty, myfaculty) |
---|
| 179 | True |
---|
| 180 | |
---|
| 181 | Each of the following attributes is mandatory. |
---|
| 182 | |
---|
| 183 | `title` |
---|
| 184 | ------- |
---|
| 185 | |
---|
| 186 | Each faculty has a title: |
---|
| 187 | |
---|
| 188 | >>> myfaculty.title |
---|
| 189 | u'Unnamed Faculty' |
---|
| 190 | |
---|
| 191 | `title_prefix` |
---|
| 192 | -------------- |
---|
| 193 | |
---|
| 194 | Each faculty has a title prefix, which specifies the kind of |
---|
| 195 | institution: |
---|
| 196 | |
---|
| 197 | >>> myfaculty.title_prefix |
---|
| 198 | u'faculty' |
---|
| 199 | |
---|
| 200 | `code` |
---|
| 201 | ------ |
---|
| 202 | |
---|
| 203 | Each faculty holds a code, which might be a shortcut or abbreviation |
---|
[4232] | 204 | of the real faculty name. By default the code is ``NA`` (=not assigned): |
---|
[4157] | 205 | |
---|
[4232] | 206 | >>> myfaculty.code |
---|
| 207 | u'NA' |
---|