Next / Previous / Contents / Shipman's homepage

23.13. MonthCell.__locDef(): Display a locality definition

See Section 4.5, “XHTML for locality definitions”.

noteweb
# - - -   M o n t h C e l l . _ _ l o c D e f

    def __locDef ( self, parent, loc ):
        '''Display the definition of one locality.

          [ (parent is an et.Element) and
            (loc is a birdnotes.Loc instance) ->
              parent  +:=  a div element displaying loc ]
        '''

All the content generated by this method is wrapped in a div class=LOC_DEF_CLASS. In each case, the first content is “@” followed by the locality's code, a colon, and the locality's name.

noteweb
        #-- 1 --
        # [ parent  +:=  a div element with class=LOC_DEF_CLASS
        #   topDiv  :=  that div element ]
        topDiv  =  et.SubElement ( parent, 'div' )
        topDiv.attrib['class']  =  LOC_DEF_CLASS

        #-- 2 --
        # [ topDiv  +:=  '@' + loc.code + ': ' + loc.name ]
        topDiv.text  =  '@%s: %s' % (loc.code, loc.name )

If there is a narrative block for this locality, render it next inside a div class=LOC_NARRATIVE_CLASS. The text is just a string, not an instance of the Narrative class.

noteweb
        #-- 3 --
        # [ if bool(loc.text) ->
        #     topDiv  +:=  loc.text, wrapped in a div element
        #                  with class=LOC_NARRATIVE_CLASS
        #   else -> I ]
        if loc.text:
            narraDiv  =  et.SubElement ( topDiv, 'div' )
            narraDiv.attrib['class']  =  LOC_NARRATIVE_CLASS
            narraDiv.text  =  loc.text

The list of GPS waypoints follows, if there are any.

noteweb
        #-- 4 --
        # [ topDiv  +:=  a sequence of divs with class
        #       LOC_NARRATIVE_CLASS containing GPS descriptions
        #       from loc, if any ]
        for gps in loc.genGps():
            narraDiv  =  et.SubElement ( topDiv, 'div' )
            narraDiv.attrib['class']  =  LOC_NARRATIVE_CLASS
            narraDiv.text  =  ( 'GPS: %s %s' %
                (gps.waypoint, gps.text) )