[4920] | 1 | :mod:`waeup.sirp.university.course` -- Courses |
---|
| 2 | ********************************************** |
---|
[4263] | 3 | |
---|
[4920] | 4 | .. module:: waeup.sirp.university.course |
---|
[4263] | 5 | |
---|
[4362] | 6 | Components that represent courses. |
---|
[4263] | 7 | |
---|
[4362] | 8 | :Test-Layer: unit |
---|
[4263] | 9 | |
---|
[4362] | 10 | Because this module makes use of components registered with the Zope |
---|
| 11 | Component Architecture (ZCA), we first have to grok the `waeup` |
---|
| 12 | package if we want to deploy it. This happens automatically in |
---|
| 13 | real-world use: |
---|
[4263] | 14 | |
---|
| 15 | >>> import grok |
---|
| 16 | >>> grok.testing.grok('waeup') |
---|
| 17 | |
---|
[4362] | 18 | Content Classes (models and containers) |
---|
| 19 | ======================================= |
---|
[4263] | 20 | |
---|
[4362] | 21 | :class:`Course` |
---|
| 22 | --------------- |
---|
[4263] | 23 | |
---|
[4362] | 24 | .. class:: Course([code=u'NA'[, title=u'Unnamed Course'[, level=None[, credits=0[, passmark=40[, semester=1]]]]]]) |
---|
[4263] | 25 | |
---|
[4362] | 26 | Create a course instance with the given parameters. |
---|
[4263] | 27 | |
---|
[4362] | 28 | .. attribute:: grok.implements(ICourse) |
---|
[4263] | 29 | |
---|
[4362] | 30 | All parameters are optional: |
---|
[4263] | 31 | |
---|
[4920] | 32 | >>> from waeup.sirp.university.course import Course |
---|
[4362] | 33 | >>> mycourse = Course() |
---|
| 34 | >>> mycourse |
---|
[4920] | 35 | <waeup.sirp.university.course.Course object at 0x...> |
---|
[4263] | 36 | |
---|
[4362] | 37 | Course instances have the attributes required by the |
---|
[4920] | 38 | :class:`waeup.sirp.interfaces.ICourse` interface: |
---|
[4263] | 39 | |
---|
[5005] | 40 | >>> from waeup.sirp.university.interfaces import ICourse |
---|
[4362] | 41 | >>> ICourse.providedBy(mycourse) |
---|
| 42 | True |
---|
[4263] | 43 | |
---|
[4362] | 44 | >>> from zope.interface.verify import verifyObject |
---|
| 45 | >>> verifyObject(ICourse, mycourse) |
---|
| 46 | True |
---|
[4263] | 47 | |
---|
[4362] | 48 | .. attribute:: title |
---|
[4263] | 49 | |
---|
[4362] | 50 | Each course has a title: |
---|
[4263] | 51 | |
---|
[4362] | 52 | >>> mycourse.title |
---|
| 53 | u'Unnamed Course' |
---|
[4263] | 54 | |
---|
[4362] | 55 | .. attribute:: code |
---|
[4263] | 56 | |
---|
[4362] | 57 | Each course holds a code, which might be a shortcut or |
---|
| 58 | abbreviation of the real course name. By default the code is |
---|
| 59 | ``NA`` (=not assigned). |
---|
[4263] | 60 | |
---|
[4362] | 61 | This value has to be unique if used in a :class:`Department` |
---|
| 62 | instance as it serves as a key: |
---|
[4263] | 63 | |
---|
[4362] | 64 | >>> mycourse.code |
---|
| 65 | u'NA' |
---|
[4263] | 66 | |
---|
[4362] | 67 | .. attribute:: passmark |
---|
[4263] | 68 | |
---|
[4362] | 69 | Each course holdes a passmark, which is ``40`` by default: |
---|
[4263] | 70 | |
---|
[4362] | 71 | >>> mycourse.passmark |
---|
| 72 | 40 |
---|
[4267] | 73 | |
---|
[4362] | 74 | .. attribute:: semester |
---|
[4267] | 75 | |
---|
[4362] | 76 | Each course holds a semester attribute which is ``1`` by |
---|
| 77 | default: |
---|
[4267] | 78 | |
---|
[4362] | 79 | >>> mycourse.semester |
---|
| 80 | 1 |
---|
[4263] | 81 | |
---|
[4362] | 82 | .. attribute:: credits |
---|
[4263] | 83 | |
---|
[4362] | 84 | Each course holds the number of credits that can be |
---|
| 85 | earned. Default is ``0``. |
---|
| 86 | |
---|
| 87 | >>> mycourse.credits |
---|
| 88 | 0 |
---|
| 89 | |
---|
| 90 | .. attribute:: level |
---|
| 91 | |
---|
| 92 | Courses can have a level. This attribute is not required and the |
---|
| 93 | default value is ``None``: |
---|
| 94 | |
---|
| 95 | >>> mycourse.level is None |
---|
| 96 | True |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | Utilities |
---|
| 100 | ========= |
---|
| 101 | |
---|
| 102 | :class:`CourseFactory` |
---|
| 103 | --------------------------- |
---|
| 104 | |
---|
| 105 | .. class:: CourseFactory() |
---|
| 106 | |
---|
| 107 | .. attribute:: grok.name(u'waeup.Course') |
---|
| 108 | |
---|
| 109 | .. attribute:: grok.implements(IFactory) |
---|
| 110 | |
---|
| 111 | A named utility to deliver new instances of :class:`Course` |
---|
| 112 | without the need to import the implementation before: |
---|
| 113 | |
---|
| 114 | >>> from zope.component import createObject |
---|
| 115 | >>> mycourse = createObject(u'waeup.Course') |
---|
| 116 | >>> mycourse |
---|
[4920] | 117 | <waeup.sirp.university.course.Course object at 0x...> |
---|
[4362] | 118 | |
---|
| 119 | The factory complies with the specifications from the |
---|
| 120 | :class:`IFactory` insterface: |
---|
| 121 | |
---|
| 122 | >>> from zope.interface.verify import verifyClass |
---|
| 123 | >>> from zope.component.interfaces import IFactory |
---|
[4920] | 124 | >>> from waeup.sirp.university.course import CourseFactory |
---|
[4362] | 125 | >>> verifyClass(IFactory, CourseFactory) |
---|
| 126 | True |
---|
| 127 | |
---|
| 128 | This means also, that we can get the interfaces of the created |
---|
| 129 | object from the factory: |
---|
| 130 | |
---|
| 131 | >>> course_factory = CourseFactory() |
---|
| 132 | >>> course_factory.getInterfaces() |
---|
[4920] | 133 | <implementedBy waeup.sirp.university.course.Course> |
---|
[4362] | 134 | |
---|
| 135 | Examples |
---|
| 136 | ======== |
---|
| 137 | |
---|
| 138 | Creating courses |
---|
| 139 | ---------------- |
---|
| 140 | |
---|
| 141 | The simplest way to create a :class:`Course` instance is to import the |
---|
| 142 | class and calling the constructor: |
---|
| 143 | |
---|
[4920] | 144 | >>> from waeup.sirp.university.course import Course |
---|
[4362] | 145 | >>> mycourse = Course() |
---|
| 146 | >>> mycourse |
---|
[4920] | 147 | <waeup.sirp.university.course.Course object at 0x...> |
---|
[4362] | 148 | |
---|
| 149 | Another way to create courses is by asking for a factory called |
---|
| 150 | ``waeup.Course``. This way we can create a factory without importing a |
---|
| 151 | class: |
---|
| 152 | |
---|
| 153 | >>> from zope.component import createObject |
---|
| 154 | >>> mycourse = createObject(u'waeup.Course') |
---|
| 155 | >>> mycourse |
---|
[4920] | 156 | <waeup.sirp.university.course.Course object at 0x...> |
---|
[4362] | 157 | |
---|