Next / Previous / Contents / TCC Help System / NM Tech homepage

11.9. TaxonPhotoSet._buildSingleForm(): The taxon has only one form

This method adds the content for one taxon to the index page when there is only one form referred to that taxon. It also builds the form page for that form.

# - - -   T a x o n P h o t o S e t . _ _ b u i l d S i n g l e F o r m

    def _buildSingleForm(self, div):
        '''Build index and form content for the single-form case.

          [ (self._formMap has only one entry) and
            (div is an et.Element) ->
              div  :=  div + (link to form page containing self's
                       inverted name, and the form name if
                       different than self's inverted name
              form page for self._formMap's value  :=  content
                  displaying thumbnails and catalog info for
                  self._formMap's value ]              

To review the XHTML build in this case, refer to Section 4.2, “XHTML for the index page”. The subtree we generate here is rooted in an “a” (hyperlink) element whose href attribute points at the form page. The link text is the scientific name, followed by the inverted English name. If the inverted English name of the sole form differs from the taxon's standard English name, we add the content “(as otherName)”.

By our precondition, self._formMap has only one entry; extract it, a FormPhotoSet instance. Also extract its inverted name so we can test later whether the entry was made under a different name.

        #-- 1
        # [ formSet  :=  the single value from self._formMap
        #   formEng  :=  the inverted English name of the single value
        #                from self._formMap ]
        (formSet,) = self._formMap.values()
        formEng = formSet.birdId.engComma()

Next, build the “a” element that links to the pathname to its form page (which hasn't been built yet).

        #-- 2
        # [ div  :=  div with a new 'a' element added whose href
        #       attribute is formSet.pathName()
        #   link  :=  that 'a' element ]
        link = subElement(div, E.a(href=formSet.pathName()))

For the logic that adds the name or names, see Section 11.10, “TaxonPhotoSet._webName(): Fill in scientific and English names”.

        #-- 3
        # [ link  :=  link + (text of self's names) ]

If the form's inverted English name is different, add the “(as otherName)” content.

        #-- 4
        # [ if formEng != (inverted name from self.taxon) ->
        #     link  +:=  "(as " + formENg + ")"
        #   else -> I ]
        if formEng != self.taxon.engComma:
            addText(link, " (as {0})".format(formEng))

All that remains is to generate formSet's form page.

        #-- 5
        # [ form page for formSet  :=  content displaying
        #       thumbnails and catalog data for formSet ]