Next / Previous / Contents / Shipman's homepage

23.24. MonthCell.__photo(): Generate a photo reference or link

For the XHTML generated here, see Section 4.12, “XHTML rendering of photo links”.

noteweb
# - - -   M o n t h C e l l . _ _ p h o t o

    def __photo ( self, parent, photo ):
        '''Render one photo instance: a link, or just the catalog number.

          [ (parent is an et.Element) and
            (photo is a birdnotes.Photo instance) ->
              parent  +:=  XHTML rendering of photo ]
        '''

If there is an URL associated with this photo, generate a link to it, otherwise just spit out the catalog number unadorned.

noteweb
        #-- 1 --
        # [ if photo.url is None ->
        #     parent  +:=  photo.catNo
        #     return
        #   else -> I ]
        if photo.url is None:
            tccpage2.addTextMixed ( parent, "%s " % photo.url )
            return

        #-- 2 --
        # [ parent  +:=  a new 'a' element with href=photo.url
        #   a  :=  that new element ]
        a  =  et.SubElement ( parent, 'a', href=photo.url )

        #-- 3 --
        # [a  +:=  a new 'img' element with src=(thumbnail for
        #          photo.catNo) and alt=photo.catNo ]
        thumbUrl  =  '/~shipman/thumb/%s.jpg' % photo.catNo
        img  =  et.SubElement ( a, 'img', alt=photo.catNo,
                                src=thumbUrl )