Ignore:
Timestamp:
9 May 2015, 21:48:17 (10 years ago)
Author:
Henrik Bettermann
Message:

Untegrate doctests into sphinx docu.

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
     3Persistence of Certificate Courses
     4==================================
     5
     6If a certificate course requires a certain course and this is course
     7is deleted, also the referring certificate course is deleted.
     8
     9We setup a data structure that reflects typical usage. It looks like
     10this::
     11
     12    Department-Instance
     13    |
     14    +---> courses
     15    |        |
     16    |        +--------------------> Course-Instance
     17    |                                        ^
     18    +---> certificates                       |
     19             |                               |
     20             +-----> Certificate-Instance    |
     21                        |                    |
     22                        +------> Certificate-Course
     23
     24The Certifcate Course here refers to a Course instance.
     25
     26In 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
     31In real world use this data will be stored in a ZODB. We setup our own
     32litte 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
     47Now we can use this ZODB as backend database and store our data
     48structure:
     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
     64The data is now stored in the ZODB. We can close the DB, reopen it
     65later and the data will still be there:
     66
     67    >>> db.close()
     68    >>> newdb = TinyZODB()
     69    >>> newdbroot = newdb.dbroot
     70    >>> list(newdbroot)
     71    ['mydept']
     72
     73The certificate course we stored in the certificate is indeed a
     74referrer 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
     81So, we can be sure that modifications to the course are immediately
     82reflected in the certcourse.
     83
     84We can also be sure, that when removing courses or referrers of them,
    785other data will be handled in a way we expect. That is,
    886
     
    140218    >>> list(fac['DEPT2'].courses)
    141219    []
     220
     221
  • main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.txt

    r12104 r12920  
    1 :mod:`waeup.kofa.university.certificate` -- Certificates for Kofa
    2 ******************************************************************
     1Certificates and Certificate Courses
     2************************************
    33
    44.. module:: waeup.kofa.university.certificate
     
    234234    <waeup.kofa.university.certificate.Certificate object at 0x...>
    235235
    236 CertificateCourses
    237 ------------------
     236Certificate Courses
     237-------------------
    238238
    239239:class:`CertificateCourse` instances comply with the
     
    258258    <waeup.kofa.university.certificate.CertificateCourse object at 0x...>
    259259
    260 .. _removecertificatecourses:
    261 
    262 Persistence of certificate courses
    263 ----------------------------------
    264 
    265 If a certificate course requires a certain course and this is course
    266 is deleted, also the referring certificate course is deleted.
    267 
    268 We setup a data structure that reflects typical usage. It looks like
    269 this::
    270 
    271     Department-Instance
    272     |
    273     +---> courses
    274     |        |
    275     |        +--------------------> Course-Instance
    276     |                                        ^
    277     +---> certificates                       |
    278              |                               |
    279              +-----> Certificate-Instance    |
    280                         |                    |
    281                         +------> Certificate-Course
    282 
    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 createObject
    288     >>> mydept = createObject('waeup.Department')
    289 
    290 In real world use this data will be stored in a ZODB. We setup our own
    291 litte 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 
    306 Now we can use this ZODB as backend database and store our data
    307 structure:
    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 
    323 The data is now stored in the ZODB. We can close the DB, reopen it
    324 later and the data will still be there:
    325 
    326     >>> db.close()
    327     >>> newdb = TinyZODB()
    328     >>> newdbroot = newdb.dbroot
    329     >>> list(newdbroot)
    330     ['mydept']
    331 
    332 The certificate course we stored in the certificate is indeed a
    333 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 course
    338     True
    339 
    340 So, we can be sure that modifications to the course are immediately
    341 reflected in the certcourse.
    342 
Note: See TracChangeset for help on using the changeset viewer.