Next / Previous / Contents / Shipman's homepage

23.19. MonthCell.__birdForm(): Render one BirdForm

For an overview of the generated output, see Section 4.8, “XHTML for the form element”. A div class=FORM_CLASS wraps all generated content, except for notable records, which get class=NOTABLE_FORM_CLASS.

noteweb
# - - -   M o n t h C e l l . _ _ b i r d F o r m

    def __birdForm ( self, parent, birdForm ):
        '''Output all the data from one BirdForm instance.

          [ (parent is an et.Element) and
            (birdForm is a birdnotes.BirdForm instance) ->
              parent  +:=  XHTML rendering of birdForm ]
        '''
        #-- 1 --
        # [ parent  +:=  a new div element with class=FORM_CLASS
        #   div  :=  that div element ]
        div  =  et.SubElement ( parent, 'div' )
        if birdForm.notable:
            div.attrib['class']  =  NOTABLE_FORM_CLASS
        else:
            div.attrib['class']  =  FORM_CLASS

Next comes the name of this bird form. We'll wrap it in a span class='notable' if the birdForm.notable flag is true, otherwise we'll use the regular span class='bird-name'.

The name of the bird form is a birdnotes.BirdId instance in birdForm.birdId; applying the str() function to a BirdId gives the full name, even for compound forms such as 'Gadwall x Mallard'. See Section 23.9, “MonthCell.__span(): Add a span inline”.

noteweb
        #-- 2 --
        # [ if birdForm.notable ->
        #     div  +:=  birdForm.birdId's name, wrapped in a
        #               span class=NOTABLE_CLASS
        #   else ->
        #     div  +:=  birdForm.birdId's name, wrapped in a
        #               span class=BIRD_NAME_CLASS ]
        if birdForm.notable:
            class_  =  NOTABLE_CLASS
        else:
            class_  =  BIRD_NAME_CLASS
        self.__span ( div, class_, birdForm.birdId.engComma() )
        tccpage2.addTextMixed ( div, NBSP )

At this point, the rendering depends on whether this one sighting or multiple sightings:

noteweb
        #-- 3 --
        # [ if birdForm contains one sighting ->
        #     div  +:=  (that sighting's age-sex-group) +
        #         (that sighting's loc-group, if any) +
        #         (that sighting's sighting-notes, if any)
        #   else ->
        #     div  +:=  (birdForm's loc-group content, if any) +
        #         (birdForm's sighting-notes, if any) +
        #         (birdForm's sightings packaged in separate divs) ]
        if len(birdForm) == 1:
            self.__singleSighting ( div, birdForm )
        else:
            self.__multiSighting ( div, birdForm )