source: main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.txt @ 12858

Last change on this file since 12858 was 12104, checked in by Henrik Bettermann, 10 years ago

Ease customization of STUDENT_EXPORTER_NAMES.

File size: 10.0 KB
Line 
1:mod:`waeup.kofa.university.certificate` -- Certificates for Kofa
2******************************************************************
3
4.. module:: waeup.kofa.university.certificate
5
6Components that represent and manage certificates.
7
8.. :doctest:
9.. :layer: waeup.kofa.testing.KofaUnitTestLayer
10
11
12Content Classes (models and containers)
13=======================================
14
15
16:class:`Certificate`
17--------------------
18
19.. class:: Certificate([code=u'NA',[ title=u'Unnamed Certificate',[ study_mode=None,[ start_level=None,[ end_level=None,[ application_category=None,[ m_prefix=u'']]]]]]])
20
21   Create a certificate object with the given parameters.
22
23   .. attribute:: grok.implements(ICertificate)
24
25   All parameters are optional:
26
27     >>> from waeup.kofa.university.certificate import Certificate
28     >>> mycertificate = Certificate()
29
30   Certificates have the attributes required by the `ICertificate` interface:
31
32     >>> from waeup.kofa.university.interfaces import ICertificate
33     >>> ICertificate.providedBy(mycertificate)
34     True
35
36     >>> from zope.interface.verify import verifyObject
37     >>> verifyObject(ICertificate, mycertificate)
38     True
39
40   Beside the attributes, certificates are containers for
41   certificate-courses (see :class:`CertificateCourse`). Each
42   certificate course can be accessed by the code of the course it wraps.
43
44   .. attribute:: title
45
46      Each certificate has a title:
47
48        >>> mycertificate.title
49        u'Unnamed Certificate'
50
51   .. attribute:: code
52
53      Each certificate holds a code, which might be a shortcut or
54      abbreviation of the real certificate name. By default the code
55      is ``NA`` (=not assigned):
56
57        >>> mycertificate.code
58        u'NA'
59
60
61   .. attribute:: study_mode
62
63      Each :class:`Certificate` instance has a study mode:
64
65        >>> print mycertificate.study_mode
66        None
67
68      .. XXX: This is not a proper description
69
70   .. attribute:: start_level
71
72      Each :class:`Certificate` instance has a start level:
73
74        >>> print mycertificate.start_level
75        None
76
77      .. XXX: This is not a proper description
78
79   .. attribute:: end_level
80
81      Each :class:`Certificate` instance has a end level:
82
83        >>> print mycertificate.end_level
84        None
85
86      .. XXX: This is not a proper description
87   
88
89   .. attribute:: application_category
90
91      Each :class:`Certificate` instance has an application category:
92
93        >>> print mycertificate.application_category
94        None
95
96      .. XXX: This is not a proper description
97
98   .. method:: addCertCourse(course[, level=100,[ mandatory=True]])
99
100      Add a certificate course. A course is an object implementing
101      :class:`waeup.kofa.interfaces.ICourse`.
102
103      Please don't be confused by the term 'certificate course'.
104      As course objects will normaly be  stored
105      in a department, the certificate course refers to
106      the 'real' course in the department container.
107
108   .. method:: delCertCourses(code)
109
110      Remove a certificate course from a certificate.
111
112      The certificate course must be given by its code number.
113
114:class:`CertificateCourse`
115--------------------------
116
117.. class:: CertificateCourse(course[, level=100[, mandatory=True]])
118
119   Create a certificate course.
120
121   A certificate course are held in
122   certificates and refer to an existing :class:`Course` instance held
123   elsewhere.
124
125   A certificate can require several certificate courses and one
126   certificate course can be required by several certificates.
127
128   .. attribute:: course
129
130      An instance of :class:`ICourse`.
131
132   .. attribute:: level
133
134      An integer telling the level to which this course applies.
135
136   .. attribute:: mandatory
137
138      A bool stating whether this course is required or optional to
139      get the certificate.
140
141
142
143Utilities
144=========
145
146:class:`CertificateFactory`
147---------------------------
148
149.. class:: CertificateFactory()
150
151   .. attribute:: grok.name(u'waeup.Certificate')
152
153   .. attribute:: grok.implements(IFactory)
154
155   A named utility to deliver new instances of :class:`Certificate`
156   without the need to import the implementation before:
157
158     >>> from zope.component import createObject
159     >>> mycertificate = createObject(u'waeup.Certificate')
160     >>> mycertificate
161     <waeup.kofa.university.certificate.Certificate object at 0x...>
162
163   The factory complies with the specifications from the
164   :class:`IFactory` insterface:
165
166     >>> from zope.interface.verify import verifyClass
167     >>> from zope.component.interfaces import IFactory
168     >>> from waeup.kofa.university.certificate import CertificateFactory
169     >>> verifyClass(IFactory, CertificateFactory)
170     True
171
172   This means also, that we can get the interfaces of the created
173   object from the factory:
174
175     >>> certificate_factory = CertificateFactory()
176     >>> certificate_factory.getInterfaces()
177     <implementedBy waeup.kofa.university.certificate.Certificate>
178
179
180:class:`CertificateCourseFactory`
181---------------------------------
182
183.. class:: CertificateCourseFactory()
184
185   .. attribute:: grok.name(u'waeup.CertificateCourse')
186
187   .. attribute:: grok.implements(IFactory)
188
189   A named utility to deliver new instances of :class:`CertificateCourse`
190   without the need to import the implementation before:
191
192     >>> from zope.component import createObject
193     >>> mycertificatecourse = createObject(u'waeup.CertificateCourse')
194     >>> mycertificatecourse
195     <waeup.kofa.university.certificate.CertificateCourse object at 0x...>
196
197   The factory complies with the specifications from the
198   :class:`IFactory` insterface:
199
200     >>> from zope.interface.verify import verifyClass
201     >>> from zope.component.interfaces import IFactory
202     >>> from waeup.kofa.university.certificate import CertificateCourseFactory
203     >>> verifyClass(IFactory, CertificateCourseFactory)
204     True
205
206   This means also, that we can get the interfaces of the created
207   object from the factory:
208
209     >>> certcourse_factory = CertificateCourseFactory()
210     >>> certcourse_factory.getInterfaces()
211     <implementedBy waeup.kofa.university.certificate.CertificateCourse>
212
213
214Examples
215========
216
217Certificates
218------------
219
220We can create certificates:
221
222    >>> from waeup.kofa.university.certificate import Certificate
223    >>> mycertificate = Certificate()
224    >>> mycertificate
225    <waeup.kofa.university.certificate.Certificate object at 0x...>
226
227Another way to create certificates is by asking for a factory called
228``waeup.Certificate``. This way we can create a factory without
229importing a class:
230
231    >>> from zope.component import createObject
232    >>> mycertificate = createObject(u'waeup.Certificate')
233    >>> mycertificate
234    <waeup.kofa.university.certificate.Certificate object at 0x...>
235
236CertificateCourses
237------------------
238
239:class:`CertificateCourse` instances comply with the
240:class:`ICertificateCourse` interface:
241
242    >>> from waeup.kofa.university.interfaces import ICertificateCourse
243    >>> from waeup.kofa.university.certificate import CertificateCourse
244    >>> mycertcourse = CertificateCourse(None, 200, False)
245    >>> ICertificateCourse.providedBy(mycertcourse)
246    True
247
248    >>> from zope.interface.verify import verifyObject
249    >>> verifyObject(ICertificateCourse, mycertcourse)
250    True
251
252Also instances of :class:`CertificateCourse` can be created by asking
253the component architechture:
254
255    >>> from zope.component import createObject
256    >>> mycertcourse = createObject(u'waeup.CertificateCourse')
257    >>> mycertcourse
258    <waeup.kofa.university.certificate.CertificateCourse object at 0x...>
259
260.. _removecertificatecourses:
261
262Persistence of certificate courses
263----------------------------------
264
265If a certificate course requires a certain course and this is course
266is deleted, also the referring certificate course is deleted.
267
268We setup a data structure that reflects typical usage. It looks like
269this::
270
271    Department-Instance
272    |
273    +---> courses
274    |        |
275    |        +--------------------> Course-Instance
276    |                                        ^
277    +---> certificates                       |
278             |                               |
279             +-----> Certificate-Instance    |
280                        |                    |
281                        +------> Certificate-Course
282
283The certifcate-Course here refers to a Course-Instance.
284
285In Python we build such a structure like this (from top to bottom):
286
287    >>> from zope.component import createObject
288    >>> mydept = createObject('waeup.Department')
289
290In real world use this data will be stored in a ZODB. We setup our own
291litte ZODB backend (which is easy!):
292
293    >>> from ZODB import FileStorage, DB
294    >>> dbpath = 'tinyData.fs'
295    >>> class TinyZODB(object):
296    ...   def __init__(self, path=dbpath):
297    ...     self.storage = FileStorage.FileStorage(path)
298    ...     self.db = DB(self.storage)
299    ...     self.connection = self.db.open()
300    ...     self.dbroot = self.connection.root()
301    ...   def close(self):
302    ...     self.connection.close()
303    ...     self.db.close()
304    ...     self.storage.close()
305
306Now we can use this ZODB as backend database and store our data
307structure:
308
309    >>> import transaction
310    >>> db = TinyZODB()
311    >>> dbroot = db.dbroot
312    >>> dbroot['mydept'] = mydept
313    >>> mycourse = createObject('waeup.Course')
314    >>> mycourse.code = 'MYCOURSE'
315    >>> mydept.courses.addCourse(mycourse)
316    >>> mycert = createObject('waeup.Certificate')
317    >>> mycert.code = 'MYCERT'
318    >>> mydept.certificates.addCertificate(mycert)
319    >>> mycert.addCertCourse(mycourse)
320
321    >>> transaction.commit()
322
323The data is now stored in the ZODB. We can close the DB, reopen it
324later and the data will still be there:
325
326    >>> db.close()
327    >>> newdb = TinyZODB()
328    >>> newdbroot = newdb.dbroot
329    >>> list(newdbroot)
330    ['mydept']
331
332The certificate course we stored in the certificate is indeed a
333referrer of the course, not a copy of it:
334
335    >>> course = newdbroot['mydept'].courses['MYCOURSE']
336    >>> certcourse = newdbroot['mydept'].certificates['MYCERT']['MYCOURSE_100']
337    >>> certcourse.course is course
338    True
339
340So, we can be sure that modifications to the course are immediately
341reflected in the certcourse.
342
Note: See TracBrowser for help on using the repository browser.