source: main/waeup.sirp/trunk/src/waeup/sirp/university/coursescontainer.txt @ 9079

Last change on this file since 9079 was 7333, checked in by Henrik Bettermann, 13 years ago

Rename certificatecontainer, coursecontainer and facultycontainer. Now we have e.g. a container for faculties. Synonyms are 'facultiescontainer', 'faculties', 'academics' or 'Academic Section'. The faculty container is the faculty itself which contains the departments.

File size: 4.3 KB
Line 
1:mod:`waeup.sirp.university.coursescontainer` -- Course containers
2******************************************************************
3
4.. module:: waeup.sirp.university.coursescontainer
5
6Containers for courses.
7
8.. :doctest:
9.. :layer: waeup.sirp.testing.SIRPUnitTestLayer
10
11
12Content Classes (models and containers)
13=======================================
14
15:class:`CoursesContainer`
16-------------------------
17
18.. class:: CoursesContainer()
19
20   Create a course container instance.
21
22   .. attribute:: grok.implements(ICoursesContainer)
23
24   .. attribute:: grok.require('waeup.manageUniversity')
25
26   :class:`CoursesContainer` instances are instances of
27   :class:`grok.Container` that hold and manage instances of
28   :class:`waeup.sirp.university.course.Course`.
29
30     >>> from waeup.sirp.university.coursescontainer import CoursesContainer
31     >>> mycontainer = CoursesContainer()
32     >>> mycontainer
33     <waeup.sirp.university.coursescontainer.CoursesContainer object at 0x...>
34
35   Course containers provide `ICoursesContainer`:
36
37     >>> from waeup.sirp.university.interfaces import ICoursesContainer
38     >>> ICoursesContainer.providedBy(mycontainer)
39     True
40
41   We can be sure, that the full interface is supported by the
42   CoursesContainer class:
43
44     >>> from zope.interface.verify import verifyClass
45     >>> verifyClass(ICoursesContainer, CoursesContainer)
46     True
47
48   As normal ``grok.Container``, :class:`CoursesContainer` instances
49   can be used like dicts:
50
51     >>> list(mycontainer.keys())
52     []
53
54   .. method:: addCourse(course)
55
56      Add a course.
57
58      *course* must be an instance of
59      :class:`waeup.sirp.university.course.Course`:
60
61        >>> from waeup.sirp.university.coursescontainer import CoursesContainer
62        >>> mycontainer = CoursesContainer()
63        >>> mycontainer.addCourse('blah')
64        Traceback (most recent call last):
65        ...
66        TypeError: CoursesContainers contain only ICourse instances
67
68      The key of added items is the ``code`` attribute:
69
70        >>> from waeup.sirp.university.course import Course
71        >>> mycourse = Course(code='COURSE1')
72        >>> mycontainer.addCourse(mycourse)
73        >>> list(mycontainer.keys())
74        [u'COURSE1']
75
76   .. method:: clear()
77
78      Remove all contained courses:
79
80        >>> len(mycontainer.items())
81        1
82
83        >>> mycontainer.clear()
84        >>> len(mycontainer.items())
85        0
86
87Utilities
88=========
89
90:class:`CoursesContainerFactory`
91--------------------------------
92
93.. class:: CoursesContainerFactory()
94
95   .. attribute:: grok.name(u'waeup.CoursesContainer')
96
97   .. attribute:: grok.implements(IFactory)
98
99   A named utility to deliver new instances of :class:`CoursesContainer`
100   without the need to import the implementation before:
101
102     >>> from zope.component import createObject
103     >>> mycoursescontainer = createObject(u'waeup.CoursesContainer')
104     >>> mycoursescontainer
105     <waeup.sirp.university.coursescontainer.CoursesContainer object at 0x...>
106
107   The factory complies with the specifications from the
108   :class:`IFactory` insterface:
109
110     >>> from zope.interface.verify import verifyClass
111     >>> from zope.component.interfaces import IFactory
112     >>> from waeup.sirp.university.coursescontainer import CoursesContainerFactory
113     >>> verifyClass(IFactory, CoursesContainerFactory)
114     True
115
116   This means also, that we can get the interfaces of the created
117   object from the factory:
118
119     >>> coursescontainer_factory = CoursesContainerFactory()
120     >>> coursescontainer_factory.getInterfaces()
121     <implementedBy waeup.sirp.university.coursescontainer.CoursesContainer>
122
123
124Examples
125========
126
127Getting a course container
128--------------------------
129
130We can easily create `CoursesContainers`:
131
132    >>> from waeup.sirp.university.coursescontainer import CoursesContainer
133    >>> mycontainer = CoursesContainer()
134
135
136Another way to get a course container -- without importing the class
137-- is via factories. We registered a factory for course containers
138under the name ``waeup.CoursesContainer``. Now we can ask for an object
139by calling the appropriate factory:
140
141    >>> from zope.component import createObject
142    >>> createObject(u'waeup.CoursesContainer')
143    <waeup.sirp.university.coursescontainer.CoursesContainer object at 0x...>
144
145This way we get a thing that implements ICoursesContainer without
146imports or similar.
147
Note: See TracBrowser for help on using the repository browser.