Next / Previous / Contents / TCC Help System / NM Tech homepage

10.3. buildWeb(): Build all Web pages

This method generates the index page and all form pages.

# - - -   b u i l d W e b

def buildWeb(rootTaxon):
    '''Build all web pages.

      [ rootTaxon is a TaxonPhotoSet ->
          index page  :=  taxonomy with links to form pages from
          form pages from rootTaxon  :=  content from rootTaxon ]

First we use the webPage() function to set up what will become the index page.

    #-- 1
    # [ indexPage  :=  a new XHTML page as an et.ElementTree
    #   body  :=  the body element of that page ]
    indexPage, body = webPage("Shipman's bird photo index",

The content of the page is added by visiting each node in the taxonomic tree made up of TaxonPhotoSet instances. The .walk() method on the root TaxonPhotoSet instance takes care of this visitation process. It yields each node of the tree in sequence, using pre-order traversal (that is, the root node comes first, followed recursively by its child subtrees).

At each node, we call the node's .buildPage() method to add the node's content to the index page, including generation of all the form pages for forms referred to that node's taxon.

    #-- 2
    # [ body  :=  body with content added for all nodes in the
    #       tree of TaxonPhotoSet instances rooted at rootTaxon ]
    for taxonSet in rootTaxon.walk():
        #-- 2 body
        # [ taxonSet is a TaxonPhotoSet instance ->
        #     body  :=  body with content added from node
        #     form pages for forms in node  :=  content from
        #         forms in node ]

Now that the index page has been built, write it out.

    #-- 3
    # [ if  index page can be created anew ->
    #     index page  :=  indexPage, serialized ]
    indexFile = open(INDEX_PAGE, "w")
    indexPage.write(indexFile, pretty_print=True)