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

20. buildReportPage(): Build one access report page

This function builds the access report for a given user or official directory name.

webstats.py
# - - -   b u i l d R e p o r t P a g e

def buildReportPage ( userName, webPath, tilde, accessSummary,
    genUrls ):
    '''Build the access report for one personal web.

      [ (userName is a user name as a string) and
        (webPath is a WebPath instance) and
        (tilde is "~" for personal pages, "" for official) and
        (accessSummary is an AccessSummary instance) and
        (genUrls is a bound method that generates all the URLs
        for a given user or directory name) ->
          personal-report for (userName)  :=  personal-content
              for (userName) from accessSummary at webPath ]
    '''

First we construct a new TCCPage instance to hold the report. For LEAF_NAV_LINKS, see Section 6.4, “Constants for HTML generation”. For ACCESS_REPORT_TITLE, see Section 6.5, “Report label text”.

webstats.py
    #-- 1 --
    # [ page  :=  a new tccpage2.TCCPage instance with title
    #       ACCESS_REPORT_TITLE and navigation list LEAF_NAV_LINKS
    #       at path webPath ]
    pageTitle  =  ( ACCESS_REPORT_TITLE %
                    (NMT_WEB_PATH.url, tilde, userName) )
    page  =  tccpage2.TCCPage ( pageTitle, LEAF_NAV_LINKS,
                                url=webPath.url )

Next we add a new table element to the page that will hold the access report. See Section 13, “accessReport(): Start a new access report table”.

webstats.py
    #-- 2 --
    # [ page.content  +:=  a new access report as a 'table' element
    #   tbody  :=  the 'tbody' element of that table ]
    tbody  =  accessReport ( page.content )

The genUrls argument is a generator that, when passed a user or official directory name, generates all the URLs within that structure. Each URL is then passed to accessSummary.getUrl() to obtain a HitCount instance enumerating the URL's access count, which is then added to the table body by Section 14, “accessRow(): Add one row to an access report table”.

webstats.py
    #-- 3 --
    # [ tbody  +:=  rows showing the hit counts for URLs
    #               generated by genUrls() ]
    for url in genUrls(userName):
        #-- 3 body --
        # [ tbody  +:=  a row showing the hit counts for URL
        #               from accessSummary ]
        hitCount  =  accessSummary.getUrl ( url )
        accessRow ( tbody, hitCount )

Serialize the completed page to the path specified in webPath.absPath.

webstats.py
    #-- 4 --
    # [ file webPath.absPath  :=  page, serialized ]
    try:
        pageFile  =  open ( webPath.absPath, 'w' )
    except IOError, detail:
        fatal ( "Can't open access report page '%s': %s" %
                (webPath.absPath, detail) )
    page.write ( pageFile )
    pageFile.close()