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

11.10. TaxonPhotoSet._webName(): Fill in scientific and English names

This method builds the XHTML for the taxon's scientific name and, if defined, its inverted English name. For design notes, see Section 4.2, “XHTML for the index page”.

# - - -   T a x o n P h o t o S e t . _ _ w e b N a m e

    def _webName(self, parent):
        '''Add the scientific and English names to a Web page.

          [ parent is an et.Element ->
              parent  :=  parent + (self.taxon's scientific name) +
                  (self.taxon's English name, if known) ]              

The principal complication is that we must italicize genus-level and lower-rank names by wrapping them in a span class='genus' element; see Section 5, “Styling with CSS”. The depth attribute of a taxonomic rank is 0 for class, 1 for order, and so on, so we can test the rank depth of self's taxon against the depth of the genus rank to determine whether to italicize.

        #-- 1
        # [ selfDepth  :=  taxonomic rank depth of self.taxon
        #   genusDepth  :=  taxonomic rank depth of the genus
        #       rank of the taxonomy used by self.taxon ]
        selfDepth = self.taxon.rank.depth
        genusDepth = self.taxon.txny.hier.genusRank().depth

If this rank is genus or deeper, we now add the span element, otherwise we don't. In either case we set the variable textParent to point to the node to which the name text is to be added.

        #-- 2
        # [ if  selfDepth >= genusDepth ->
        #     parent  :=  parent + (a new span element with
        #                 class=CSS_GENUS)
        #     textParent  :=  that new span element
        #   else ->
        #     textParent  :=  parent ]
        if  selfDepth >= genusDepth:
            textParent = subElement(parent,
            textParent = parent

Next, add the scientific name to textParent. We add the rank name to ranks above genus level (e.g., “Family Fringillidae”), but omit it for genera and deeper because the italicization tells the reader it's a scientific name.

        #-- 3
        # [ textParent  :=  textParent + (self.taxon's scientific
        #       name) ]
        if  selfDepth < genusDepth:
            addText(textParent, "{0} ".format(
        addText(textParent, self.taxon.sci)

Finally, display the English name if there is one. The xnomo3 module sets the .eng attribute to the same as the .sci attribute by default, so in that case, don't redundantly display it. This text is added to parent, not textParent, so that it will be outside the span if present.

        #-- 4
        # [ if self.taxon.eng != self.taxon.sci ->
        #     parent  :=  textParent + ": " + self.taxon.engComma
        if  self.taxon.eng != self.taxon.sci:
            addText(parent, ': {0}'.format(self.taxon.engComma))