source: main/waeup.sirp/trunk/src/waeup/sirp/university/course.txt @ 5920

Last change on this file since 5920 was 5140, checked in by uli, 14 years ago

Update all unit tests that use the ZCA to run inside the new unit test layer.

File size: 3.8 KB
RevLine 
[4920]1:mod:`waeup.sirp.university.course` -- Courses
2**********************************************
[4263]3
[4920]4.. module:: waeup.sirp.university.course
[4263]5
[4362]6Components that represent courses.
[4263]7
[5140]8.. :doctest:
9.. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer
[4263]10
[4362]11Content Classes (models and containers)
12=======================================
[4263]13
[4362]14:class:`Course`
15---------------
[4263]16
[4362]17.. class:: Course([code=u'NA'[, title=u'Unnamed Course'[, level=None[, 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
[4920]25     >>> from waeup.sirp.university.course import Course
[4362]26     >>> mycourse = Course()
27     >>> mycourse
[4920]28     <waeup.sirp.university.course.Course object at 0x...>
[4263]29
[4362]30   Course instances have the attributes required by the
[4920]31   :class:`waeup.sirp.interfaces.ICourse` interface:
[4263]32
[5005]33     >>> from waeup.sirp.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   .. attribute:: level
84
85      Courses can have a level. This attribute is not required and the
86      default value is ``None``:
87
88        >>> mycourse.level is None
89        True
90
91
92Utilities
93=========
94
95:class:`CourseFactory`
96---------------------------
97
98.. class:: CourseFactory()
99
100   .. attribute:: grok.name(u'waeup.Course')
101
102   .. attribute:: grok.implements(IFactory)
103
104   A named utility to deliver new instances of :class:`Course`
105   without the need to import the implementation before:
106
107     >>> from zope.component import createObject
108     >>> mycourse = createObject(u'waeup.Course')
109     >>> mycourse
[4920]110     <waeup.sirp.university.course.Course object at 0x...>
[4362]111
112   The factory complies with the specifications from the
113   :class:`IFactory` insterface:
114
115     >>> from zope.interface.verify import verifyClass
116     >>> from zope.component.interfaces import IFactory
[4920]117     >>> from waeup.sirp.university.course import CourseFactory
[4362]118     >>> verifyClass(IFactory, CourseFactory)
119     True
120
121   This means also, that we can get the interfaces of the created
122   object from the factory:
123
124     >>> course_factory = CourseFactory()
125     >>> course_factory.getInterfaces()
[4920]126     <implementedBy waeup.sirp.university.course.Course>
[4362]127
128Examples
129========
130
131Creating courses
132----------------
133
134The simplest way to create a :class:`Course` instance is to import the
135class and calling the constructor:
136
[4920]137    >>> from waeup.sirp.university.course import Course
[4362]138    >>> mycourse = Course()
139    >>> mycourse
[4920]140    <waeup.sirp.university.course.Course object at 0x...>
[4362]141
142Another way to create courses is by asking for a factory called
143``waeup.Course``. This way we can create a factory without importing a
144class:
145
146    >>> from zope.component import createObject
147    >>> mycourse = createObject(u'waeup.Course')
148    >>> mycourse
[4920]149    <waeup.sirp.university.course.Course object at 0x...>
[4362]150
Note: See TracBrowser for help on using the repository browser.