[8920] | 1 | Certificate Courses |
---|
| 2 | ******************* |
---|
[4488] | 3 | |
---|
[5978] | 4 | Courses are referred to by certificate courses. |
---|
[4488] | 5 | |
---|
[5978] | 6 | We can be sure, that when removing courses or referrers of them, |
---|
[6737] | 7 | other 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] | 16 | As correct deletion of referrer needs support of catalogs (we lookup |
---|
| 17 | catalogs to find referrers), we need a fully blown ZODB here, |
---|
[7811] | 18 | including an instance of :class:`waeup.kofa.app.University`, as this is our |
---|
[4488] | 19 | `ISite` object where the catalogs are stored. |
---|
| 20 | |
---|
| 21 | We create a complete university tree, starting with a |
---|
| 22 | :class:`University` instance and going down to courses, certificats |
---|
| 23 | and course certificates: |
---|
| 24 | |
---|
[7811] | 25 | >>> from waeup.kofa.app import University |
---|
[4488] | 26 | >>> root = getRootFolder() |
---|
| 27 | >>> root['app'] = University() |
---|
| 28 | |
---|
| 29 | We 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 | |
---|
| 49 | Now 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] | 59 | Finally, we add a certificate with referrers (certificate courses) to |
---|
[4488] | 60 | the created courses: |
---|
| 61 | |
---|
| 62 | >>> cert = createObject('waeup.Certificate') |
---|
| 63 | >>> cert.code = 'CERT' |
---|
| 64 | >>> fac['DEPT'].certificates.addCertificate(cert) |
---|
| 65 | |
---|
[8920] | 66 | >>> fac['DEPT'].certificates['CERT'].addCertCourse( |
---|
[4488] | 67 | ... fac['DEPT'].courses['CRS1']) |
---|
| 68 | |
---|
[8920] | 69 | >>> fac['DEPT'].certificates['CERT'].addCertCourse( |
---|
[4488] | 70 | ... fac['DEPT2'].courses['CRS2']) |
---|
| 71 | |
---|
| 72 | We add the latter course again, but this time for the second level: |
---|
| 73 | |
---|
[8920] | 74 | >>> fac['DEPT'].certificates['CERT'].addCertCourse( |
---|
[4488] | 75 | ... fac['DEPT2'].courses['CRS2'], level=200) |
---|
| 76 | |
---|
[5978] | 77 | So, we have three referrers in our certificate of two different |
---|
[4488] | 78 | courses stored somewhere in the application: |
---|
| 79 | |
---|
| 80 | >>> list(fac['DEPT'].certificates['CERT']) |
---|
| 81 | [u'CRS1_100', u'CRS2_100', u'CRS2_200'] |
---|
| 82 | |
---|
[5978] | 83 | Both, 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] | 92 | If we remove the course, also the select item in the certificate course |
---|
[4488] | 93 | will 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] | 108 | If we remove a referrer of a course, this will not touch the course |
---|
| 109 | nor 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'] |
---|
[9828] | 117 | |
---|
| 118 | If a single course is registered for several levels in a single |
---|
| 119 | certificate, this will not block things if the course is removed |
---|
| 120 | (regression test): |
---|
| 121 | |
---|
| 122 | We add the same course as a reference for level 200 and level 300: |
---|
| 123 | |
---|
| 124 | >>> fac['DEPT'].certificates['CERT'].addCertCourse( |
---|
| 125 | ... fac['DEPT2'].courses['CRS2'], level=200) |
---|
| 126 | >>> fac['DEPT'].certificates['CERT'].addCertCourse( |
---|
| 127 | ... fac['DEPT2'].courses['CRS2'], level=300) |
---|
| 128 | |
---|
| 129 | Deleting the course (thus also the refererrers) will work: |
---|
| 130 | |
---|
| 131 | >>> del root['app']['faculties']['FAC']['DEPT2'].courses['CRS2'] |
---|
| 132 | |
---|
| 133 | Now all references are gone: |
---|
| 134 | |
---|
| 135 | >>> list(a.certificates['CERT']) |
---|
| 136 | [] |
---|
| 137 | |
---|
| 138 | and also the course itself vanished: |
---|
| 139 | |
---|
| 140 | >>> list(fac['DEPT2'].courses) |
---|
| 141 | [] |
---|