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