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

24. emptySubpage(): Set up an empty subpage

homelist2
# - - -   e m p t y S u b p a g e

def emptySubpage(dirPath, letterList, k):
    '''Create an empty subpage for letterList[k].

      [ (dirPath is a path relative to TCC_URL) and
        (letterList is the list of initial letters of keywords) and
        (0 <= k < len(letterList)) ->
          return ((absolute path to page for letterList[k]),
          (a new tp.TCCPage instance for letterList[k]
          with links to previous and next letters in letterLISt
          if any), (the table element on that page)) ]
    '''

First we find the letter for this subpage and upshift it. Then we figure out the subpage's URL, path, and title; see Section 22, “letterInfo(): Information about a subpage”.

homelist2
    #-- 1 --
    # [ letter  :=  letterList[k].upper()
    #   pageURL  :=  URL for that letter
    #   pageAbs  :=  absolute path name to subpage for that letter
    #   pageTitle  :=  title for that letter ]
    letter = letterList[k].upper()
    pageURL, pageAbs, pageTitle = letterInfo(dirPath, letter)

Then we have to determine whether the Next and Previous links are live or not. The constructor for tccpage2.NavList specifies navigational link targets as a list of (title, URL) tuples: an empty list results in a dead link.

homelist2
    #-- 2 --
    # [ if k > 0 ->
    #      prevTitleURL  :=  [(title of page for letterList[k-1],
    #                         URL of page for letterList[k-1])]
    #   else ->
    #      prevTitleURL  :=  an empty list ]
    if k > 0:
        prevLetter = letterList[k-1].upper()
        prevURL, prevPath, prevTitle = letterInfo(dirPath, prevLetter)
        prevTitleURL = [(prevTitle, prevURL)]
    else:
        prevTitleURL = []

    #-- 3 --
    # [ if (k+1) < len(letterList) ->
    #     nextTitleURL  :=  [(title of page for letterList[k+1],
    #                         URL of page for letterList[k+1])]
    #   else ->
    #     nextTitleURL  :=  an empty list ]
    if (k+1) < len(letterList):
        nextLetter = letterList[k+1].upper()
        nextURL, nextPath, nextTitle = letterInfo(dirPath, nextLetter)
        nextTitleURL = [(nextTitle, nextURL)]
    else:
        nextTitleURL = []

Now we're ready to build the TCCPage instance.

homelist2
    #-- 3 --
    # [ page  :=  a new tp.TCCPage instance with title (pageTitle),
    #       next page target (nextTitleURL), previous page target
    #       (prevTitleURL), and other standard TCC navigation ]
    navList = [
        tp.NavLink("Next", nextTitleURL),
        tp.NavLink("Previous", prevTitleURL),
        tp.NavLink("TCC help system",
          [("", "http://www.nmt.edu/tcc/help/")]),
        tp.NavLink("TCC homepage",
          [("", "http://www.nmt.edu/tcc/")]),
        tp.NavLink("NM Tech homepage",
          [("", "http://www.nmt.edu/")]) ]
    page = tp.TCCPage(pageTitle, navList, url=pageURL)

The only page content is the table. For the HTML structure, see Section 3.4, “Subpage design”.

homelist2
    #-- 4 --
    # [ page.content  +:=  a new table element
    #   table  :=  that table element ]
    table = subElement(page.content,
        E.table ( border='1', cellpadding='8' ) )

    #-- 5 --
    return (pageAbs, page, table)