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

14. accessRow(): Add one row to an access report table

Given a HitCount instance, and the tbody element of an access report table, this function adds a row in the table displaying that HitCount.

webstats.py
# - - -   a c c e s s R o w

def accessRow ( tbody, hitCount ):
    '''Add one row to an access table.

      [ (tbody is an et.Element) and
        (hitCount is a HitCount instance) ->
          tbody  +:=  an access report row displaying hitCount ]
    '''
    #-- 1 --
    # [ pct  :=  percentage off-campus from hitCount as a string ]
    pct  =  "%.1f%%" % ( ( 100.0 * hitCount.nFar ) / hitCount.nTotal )

Each URL cell in the table is also a link to the page. When converting a URL relative to the server into an absolute URL, we discard the initial "/" because WebPath.relative() uses os.path.join() to unite the pieces, and if the second piece starts with "/", it will be considered an absolute path, and the first piece will be ignored.

webstats.py
    #-- 2 --
    # [ tbody  +:=  a 'tr' element displaying three values: 
    #       hitCount.nTotal, pct, and a link to hitCount.url ]
    pageUrl  =  NMT_WEB_PATH.relative(hitCount.url[1:]).url
    tbody.append (
        E.tr (
            E.td ( R_ALIGN, str(hitCount.nTotal) ),
            E.td ( R_ALIGN, pct ),
            E.td ( L_ALIGN, 
                E.a ( hitCount.url, href=pageUrl ) ) ) )