This function builds one td cell in the
index table.
# - - - b u i l d M o n t h C e l l
def buildMonthCell ( tr, yearRow, monthKey ):
'''Add one month to the index table: a link or a non-breaking space.
[ (tr is an et.Element) and
(yearRow is a YearRow instance) and
(monthKey is in the sequence '01', '02', ... '12') ->
if yearRow[monthKey] exists ->
tr +:= a td element containing a link to
the month page for yearRow[monthKey]
else ->
tr +:= a td element containing a non-breaking
space ]
'''
Whether there is any month data or not, we must build a
td element, and give it the CSS class name
for the reporting season. For the mapping of month numbers
to seasons, see Section 10.2, “MONTH_SEASON_MAP: Define the season
for each month”.
#-- 1 --
# [ tr +:= a new td element
# td := that element ]
td = et.SubElement ( tr, 'td' )
#-- 2 --
# [ td +:= a 'class' attribute equal to the season for
# the month whose number is monthKey ]
td.attrib['class'] = MONTH_SEASON_MAP[monthKey]
Next, we check to see if there is any data for this month.
If not, add the non-breaking space and we're done; see
Section 10.15, “NBSP: Non-breaking space character”.
#-- 3 --
# [ if yearRow[monthKey] exists ->
# monthCell := the corresponding value
# else ->
# td.text := a non-breaking space
# return ]
try:
monthCell = yearRow[monthKey]
except KeyError:
td.text = NBSP
return
Generate a link to the URL for the month page, computed by
Section 23.2, “MonthCell.fileName(): Path to the
month's page”. For the mapping of
month numbers to month names, see Section 10.1, “MONTH_NAME_MAP: Translate month
numbers to month names”.
#-- 4 --
# [ td +:= a link to URL monthCell.fileName(), with the link
# text the name month number (monthKey) ]
monthFileName = monthCell.fileName()
a = et.SubElement ( td, 'a', href=monthFileName )
a.text = "%s %s" % (monthKey, MONTH_NAME_MAP[monthKey])