Changeset 12920 for main/waeup.kofa/trunk/src/waeup/kofa/university
- Timestamp:
- 9 May 2015, 21:48:17 (10 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/university
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/certcourses.txt
r9828 r12920 1 Certificate Courses 2 ******************* 3 4 Courses are referred to by certificate courses. 5 6 We can be sure, that when removing courses or referrers of them, 1 .. _removecertificatecourses: 2 3 Persistence of Certificate Courses 4 ================================== 5 6 If a certificate course requires a certain course and this is course 7 is deleted, also the referring certificate course is deleted. 8 9 We setup a data structure that reflects typical usage. It looks like 10 this:: 11 12 Department-Instance 13 | 14 +---> courses 15 | | 16 | +--------------------> Course-Instance 17 | ^ 18 +---> certificates | 19 | | 20 +-----> Certificate-Instance | 21 | | 22 +------> Certificate-Course 23 24 The Certifcate Course here refers to a Course instance. 25 26 In Python we build such a structure like this (from top to bottom): 27 28 >>> from zope.component import createObject 29 >>> mydept = createObject('waeup.Department') 30 31 In real world use this data will be stored in a ZODB. We setup our own 32 litte ZODB backend (which is easy!): 33 34 >>> from ZODB import FileStorage, DB 35 >>> dbpath = 'tinyData.fs' 36 >>> class TinyZODB(object): 37 ... def __init__(self, path=dbpath): 38 ... self.storage = FileStorage.FileStorage(path) 39 ... self.db = DB(self.storage) 40 ... self.connection = self.db.open() 41 ... self.dbroot = self.connection.root() 42 ... def close(self): 43 ... self.connection.close() 44 ... self.db.close() 45 ... self.storage.close() 46 47 Now we can use this ZODB as backend database and store our data 48 structure: 49 50 >>> import transaction 51 >>> db = TinyZODB() 52 >>> dbroot = db.dbroot 53 >>> dbroot['mydept'] = mydept 54 >>> mycourse = createObject('waeup.Course') 55 >>> mycourse.code = 'MYCOURSE' 56 >>> mydept.courses.addCourse(mycourse) 57 >>> mycert = createObject('waeup.Certificate') 58 >>> mycert.code = 'MYCERT' 59 >>> mydept.certificates.addCertificate(mycert) 60 >>> mycert.addCertCourse(mycourse) 61 62 >>> transaction.commit() 63 64 The data is now stored in the ZODB. We can close the DB, reopen it 65 later and the data will still be there: 66 67 >>> db.close() 68 >>> newdb = TinyZODB() 69 >>> newdbroot = newdb.dbroot 70 >>> list(newdbroot) 71 ['mydept'] 72 73 The certificate course we stored in the certificate is indeed a 74 referrer of the course, not a copy of it: 75 76 >>> course = newdbroot['mydept'].courses['MYCOURSE'] 77 >>> certcourse = newdbroot['mydept'].certificates['MYCERT']['MYCOURSE_100'] 78 >>> certcourse.course is course 79 True 80 81 So, we can be sure that modifications to the course are immediately 82 reflected in the certcourse. 83 84 We can also be sure, that when removing courses or referrers of them, 7 85 other data will be handled in a way we expect. That is, 8 86 … … 140 218 >>> list(fac['DEPT2'].courses) 141 219 [] 220 221 -
main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.txt
r12104 r12920 1 :mod:`waeup.kofa.university.certificate` -- Certificates for Kofa 2 ************************************ ******************************1 Certificates and Certificate Courses 2 ************************************ 3 3 4 4 .. module:: waeup.kofa.university.certificate … … 234 234 <waeup.kofa.university.certificate.Certificate object at 0x...> 235 235 236 Certificate Courses237 ------------------ 236 Certificate Courses 237 ------------------- 238 238 239 239 :class:`CertificateCourse` instances comply with the … … 258 258 <waeup.kofa.university.certificate.CertificateCourse object at 0x...> 259 259 260 .. _removecertificatecourses:261 262 Persistence of certificate courses263 ----------------------------------264 265 If a certificate course requires a certain course and this is course266 is deleted, also the referring certificate course is deleted.267 268 We setup a data structure that reflects typical usage. It looks like269 this::270 271 Department-Instance272 |273 +---> courses274 | |275 | +--------------------> Course-Instance276 | ^277 +---> certificates |278 | |279 +-----> Certificate-Instance |280 | |281 +------> Certificate-Course282 283 The certifcate-Course here refers to a Course-Instance.284 285 In Python we build such a structure like this (from top to bottom):286 287 >>> from zope.component import createObject288 >>> mydept = createObject('waeup.Department')289 290 In real world use this data will be stored in a ZODB. We setup our own291 litte ZODB backend (which is easy!):292 293 >>> from ZODB import FileStorage, DB294 >>> 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 306 Now we can use this ZODB as backend database and store our data307 structure:308 309 >>> import transaction310 >>> db = TinyZODB()311 >>> dbroot = db.dbroot312 >>> dbroot['mydept'] = mydept313 >>> 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 323 The data is now stored in the ZODB. We can close the DB, reopen it324 later and the data will still be there:325 326 >>> db.close()327 >>> newdb = TinyZODB()328 >>> newdbroot = newdb.dbroot329 >>> list(newdbroot)330 ['mydept']331 332 The certificate course we stored in the certificate is indeed a333 referrer 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 course338 True339 340 So, we can be sure that modifications to the course are immediately341 reflected in the certcourse.342
Note: See TracChangeset for help on using the changeset viewer.