Next / Previous / Contents / Shipman's homepage

23.5. MonthCell.__renderPage(): Add the notes content

Translate self.birdNoteSet to XHTML. The page argument is a tccpage2.TCCPage instance whose .content attribute is an element under which all the page content is placed. For an outline of the XHTML at this level, see Section 4.2, “XHTML for the month page”.

The page starts with a table of links to the daily data blocks, followed by one data block for each day. This rendering is driven by the self.birdNoteSet.genDays() method, which generates the daily blocks as a sequence birdnotes.DayNotes instances, in the order they occur in the input.

This process is complicated by the need to set up a system of anchor names so that the page's table of contents (TOC) can link correctly to the rendering of each DayNotes instance in the current month.

Because there may be more than one day-notes element with the same date, we can't simply use the “yyyy-dd-mm” date strings as anchor names. We'll have to add a suffix to separate them, e.g., “2008-04-11”, “2008-04-11a”, “2008-04-11b”, and so forth.

We'll need two local data structures to manage this process:

noteweb
# - - -   M o n t h C e l l . r e n d e r P a g e

    def __renderPage ( self, page ):
        '''Render the notes into XHTML.

          [ page is a tccpage2.TCCPage instance ->
              page  :=  page with self.birdNoteSet rendered as XHTML ]
        '''

First we add the short paragraph linking to the documentation so readers can interpret the notes.

noteweb
        #-- 1 --
        # [ page.content  +:=  paragraph linking to documentation ]
        intro  =  et.SubElement ( page.content, 'p' )
        introLink  =  et.SubElement ( intro, 'a',
            href=CONVENTIONS_URL )
        introLink.text  =  "How to read Shipman's field notes"

Next comes the page table of contents. See Section 23.6, “MonthCell.__pageTOC(): Generate page table of contents”.

noteweb
        #-- 2 --
        # [ page.content  +:=  a 'ul' containing the page table
        #       of contents (TOC)
        #   anchorMap  +:=  a dictionary whose keys are the DayNotes
        #       instances in self.birdNoteSet, and each
        #       corresponding value is the anchor name used for
        #       that instance in the generated TOC ]
        anchorMap  =  self.__pageTOC ( page.content )

Finally, we generate a block for each day-notes element in the month. See Section 23.10, “MonthCell.__dayBlock(): Render one daily note set”.

noteweb
        #-- 3 --
        # [ page.content  +:=  XHTML rendering of the day-notes
        #       elements inside self.birdNoteSet, using anchorMap
        #       for the mapping of those elements onto anchors ]
        for dayNotes in self.birdNoteSet.genDays():
            #-- 3 body --
            # [ dayNotes is a birdnotes.DayNotes instance ->
            #     page.content  +:=  XHTML rendering of dayNotes
            #         defining anchor anchorMap[dayNotes] ]
            self.__dayBlock ( page.content, dayNotes,
                            anchorMap[dayNotes] )