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
“” date strings as anchor names. We'll
have to add a suffix to separate them, e.g.,
“yyyy-dd-mm2008-04-11”, “2008-04-11a”, “2008-04-11b”, and so forth.
We'll need two local data structures to manage this process:
A Python set instance named anchorSet will accumulate the anchor strings
that we have used so far. This is needed only during
the process of assigning unique anchor values, which
occurs in Section 23.6, “MonthCell.__pageTOC(): Generate page
table of contents”, so it
is local to that method.
In order to remember which anchors correspond to
which DayNotes instances, we'll use a
rather interesting little Python trick. In Python,
you can use an instance as an index in a dictionary.
We'll keep the anchors as values in a dictionary
named anchorMap, and the keys will be
the DayNotes instances in this month.
That structure is returned by the .__pageTOC method.
# - - - 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.
#-- 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”.
#-- 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”.
#-- 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] )