source: main/waeup.sirp/trunk/src/waeup/sirp/university/courserefs.txt @ 9174

Last change on this file since 9174 was 6737, checked in by uli, 13 years ago

Register courserefs.txt from university subpkg manually.
Remove autoregistration via z3c.testsetup.

File size: 3.5 KB
RevLine 
[5978]1Course referrers
2****************
[4488]3
[5978]4Courses are referred to by certificate courses.
[4488]5
[5978]6We can be sure, that when removing courses or referrers of them,
[6737]7other data will be handled in a way we expect. That is,
[4488]8
[5978]9* when we remove a course, we want all referrers to it be removed as
[4488]10  well
11
[5978]12* when we remove a referrer of a course, nothing else should be
13  touched but only this very referrer.
[4488]14
15
[5978]16As correct deletion of referrer needs support of catalogs (we lookup
17catalogs to find referrers), we need a fully blown ZODB here,
[4921]18including an instance of :class:`waeup.sirp.app.University`, as this is our
[4488]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
[4921]25    >>> from waeup.sirp.app import University
[4488]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'
[4749]38    >>> root['app']['faculties'].addFaculty(faculty)
39    >>> fac = root['app']['faculties']['FAC']
[4488]40
41    >>> dept = createObject('waeup.Department')
42    >>> dept.code = 'DEPT'
[4749]43    >>> root['app']['faculties']['FAC'].addDepartment(dept)
[4488]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'
[4749]53    >>> root['app']['faculties']['FAC'].addDepartment(dept2)
[4488]54
55    >>> course = createObject('waeup.Course')
56    >>> course.code = 'CRS2'
57    >>> fac['DEPT2'].courses.addCourse(course)
58
[5978]59Finally, we add a certificate with referrers (certificate courses) to
[4488]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'].addCourseRef(
67    ...   fac['DEPT'].courses['CRS1'])
68
69    >>> fac['DEPT'].certificates['CERT'].addCourseRef(
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'].addCourseRef(
75    ...   fac['DEPT2'].courses['CRS2'], level=200)
76
[5978]77So, we have three referrers in our certificate of two different
[4488]78courses stored somewhere in the application:
79
80    >>> list(fac['DEPT'].certificates['CERT'])
81    [u'CRS1_100', u'CRS2_100', u'CRS2_200']
82
[5978]83Both, the courses themselves and the referrers of them, are the same
[4488]84(not only equal):
85
[4749]86    >>> a = root['app']['faculties']['FAC']['DEPT']
[4488]87    >>> b1 = a.courses['CRS1']
88    >>> b2 = a.certificates['CERT']['CRS1_100'].course
89    >>> b1 is b2
90    True
91
[5978]92If we remove the course, also the select item in the certificate course
[4488]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
[4749]101    >>> del root['app']['faculties']['FAC']['DEPT'].courses['CRS1']
[4488]102    >>> list(a.certificates['CERT'])
103    [u'CRS2_100', u'CRS2_200']
104
105    >>> list(a.courses)
106    []
107
[5978]108If we remove a referrer of a course, this will not touch the course
109nor other referrers:
[4488]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.