This function writes the usual “Content-type” header and blank line, then
generates the chapter page according to its database
entry. For the generated HTML, see Section 7, “reader.cgi: An example script
with cookies”.
# - - - g e n e r a t e C h a p t e r
def generateChapter ( userRecord ):
'''Generate the usual HTML displaying one chapter.
[ dbValue is a string of the form "(chapterNo),(expiration)" ->
sys.stdout +:= (HTML header) + (blank line) +
(page showing chapter (chapterNo)) ]
'''
We'll use Section 7.10, “genericPage(): Build a generic Web
page” to set up an
empty Web page. For the page titles, see Section 7.6.19, “PAGE_TITLE”.
#-- 1 --
# [ page := a minimal Web page as an et.ElementTree,
# carrying title PAGE_TITLE
# body := the body element of that page ]
page, body = genericPage ( PAGE_TITLE )
The form element has all the remaining
content; it is created by Section 7.16, “generateForm(): Build the form element”. Writing the headers
(see Section 7.6.20, “HTML_HEADER”), and the generated
page, works just the same as in Section 7.9, “deletionPage(): Generate the
deletion-successful page”.
#-- 2 --
# [ body +:= a form element displaying the chapter as
# specified by userRecord ]
generateForm ( body, userRecord )
See Section 7.6.20, “HTML_HEADER” and Section 7.6.18, “DOCTYPE: Document type declaration”.
#-- 3 --
# [ sys.stdout +:= (HTML header) + (blank line) +
# (page as HTML) ]
print HTML_HEADER
print
print DOCTYPE
page.write ( sys.stdout, pretty_print=True )