source: main/waeup.kofa/trunk/src/waeup/kofa/university/certcourses.txt @ 9324

Last change on this file since 9324 was 8920, checked in by Henrik Bettermann, 12 years ago

Rename course referrers to certificate courses (according to the discussion long time ago).

Edit some button labels and titles.

Move code from view to content components.

File size: 3.5 KB
Line 
1Certificate Courses
2*******************
3
4Courses are referred to by certificate courses.
5
6We can be sure, that when removing courses or referrers of them,
7other data will be handled in a way we expect. That is,
8
9* when we remove a course, we want all referrers to it be removed as
10  well
11
12* when we remove a referrer of a course, nothing else should be
13  touched but only this very referrer.
14
15
16As correct deletion of referrer needs support of catalogs (we lookup
17catalogs to find referrers), we need a fully blown ZODB here,
18including an instance of :class:`waeup.kofa.app.University`, as this is our
19`ISite` object where the catalogs are stored.
20
21We create a complete university tree, starting with a
22:class:`University` instance and going down to courses, certificats
23and course certificates:
24
25    >>> from waeup.kofa.app import University
26    >>> root = getRootFolder()
27    >>> root['app'] = University()
28
29We have to set the site, to enable proper working of catalogs and
30`IObjectRemoved` handlers:
31
32    >>> from zope.app.component.hooks import setSite
33    >>> setSite(root['app'])
34
35    >>> from zope.component import createObject
36    >>> faculty = createObject('waeup.Faculty')
37    >>> faculty.code = 'FAC'
38    >>> root['app']['faculties'].addFaculty(faculty)
39    >>> fac = root['app']['faculties']['FAC']
40
41    >>> dept = createObject('waeup.Department')
42    >>> dept.code = 'DEPT'
43    >>> root['app']['faculties']['FAC'].addDepartment(dept)
44
45    >>> course = createObject('waeup.Course')
46    >>> course.code = 'CRS1'
47    >>> fac['DEPT'].courses.addCourse(course)
48
49Now let's add another department, which will also hold a course:
50
51    >>> dept2 = createObject('waeup.Department')
52    >>> dept2.code = 'DEPT2'
53    >>> root['app']['faculties']['FAC'].addDepartment(dept2)
54
55    >>> course = createObject('waeup.Course')
56    >>> course.code = 'CRS2'
57    >>> fac['DEPT2'].courses.addCourse(course)
58
59Finally, we add a certificate with referrers (certificate courses) to
60the created courses:
61
62    >>> cert = createObject('waeup.Certificate')
63    >>> cert.code = 'CERT'
64    >>> fac['DEPT'].certificates.addCertificate(cert)
65
66    >>> fac['DEPT'].certificates['CERT'].addCertCourse(
67    ...   fac['DEPT'].courses['CRS1'])
68
69    >>> fac['DEPT'].certificates['CERT'].addCertCourse(
70    ...   fac['DEPT2'].courses['CRS2'])
71
72We add the latter course again, but this time for the second level:
73
74    >>> fac['DEPT'].certificates['CERT'].addCertCourse(
75    ...   fac['DEPT2'].courses['CRS2'], level=200)
76
77So, we have three referrers in our certificate of two different
78courses stored somewhere in the application:
79
80    >>> list(fac['DEPT'].certificates['CERT'])
81    [u'CRS1_100', u'CRS2_100', u'CRS2_200']
82
83Both, the courses themselves and the referrers of them, are the same
84(not only equal):
85
86    >>> a = root['app']['faculties']['FAC']['DEPT']
87    >>> b1 = a.courses['CRS1']
88    >>> b2 = a.certificates['CERT']['CRS1_100'].course
89    >>> b1 is b2
90    True
91
92If we remove the course, also the select item in the certificate course
93will be gone:
94
95    >>> list(a.certificates['CERT'])
96    [u'CRS1_100', u'CRS2_100', u'CRS2_200']
97
98    >>> list(a.courses)
99    [u'CRS1']
100
101    >>> del root['app']['faculties']['FAC']['DEPT'].courses['CRS1']
102    >>> list(a.certificates['CERT'])
103    [u'CRS2_100', u'CRS2_200']
104
105    >>> list(a.courses)
106    []
107
108If we remove a referrer of a course, this will not touch the course
109nor other referrers:
110
111    >>> del fac['DEPT'].certificates['CERT']['CRS2_200']
112    >>> list(a.certificates['CERT'])
113    [u'CRS2_100']
114
115    >>> list(fac['DEPT2'].courses)
116    [u'CRS2']
Note: See TracBrowser for help on using the repository browser.