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.

catweb
# - - -   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.

catweb
        #-- 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).

catweb
        #-- 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”.

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

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

catweb
        #-- 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.

catweb
        #-- 5
        # [ form page for formSet  :=  content displaying
        #       thumbnails and catalog data for formSet ]
        formSet.buildPage()