Next / Previous / Contents / Shipman's homepage

7.4. DayNotes.addForm(): Add a form to one day's notes

This method adds one BirdForm object to a DayNotes object. Each such object added over the life of the instance is indexed in the self.__seqMap directory with a unique serial number; self.__numberAdded keeps track of the number of entries added so far.

We also add the new BirdForm object to the self.__txMap dictionary, with its proper two-part key.

birdnotes.py
# - - -   D a y N o t e s . a d d F o r m

    def addForm ( self, newForm ):
        """Add a new BirdForm object to self.
        """

First we increment self.__numberAdded to account for the newly added form object, and remember the sequence number (counting from one) in the local variable seqNo.

birdnotes.py
        #-- 1 --
        # [ seqNo  :=  self.__numberAdded + 1
        #   self.__numberAdded  +:=  1 ]
        self.__numberAdded  +=  1
        seqNo  =  self.__numberAdded

Next, we build the two-tuple used as a key in self.__txMap: the first part is the record's taxonomic key, and the second part is its English name.

birdnotes.py
        #-- 2 --
        # [ phyloKey  :=  (taxonomic key of newForm,
        #       English name of newForm) ]
        phyloKey  =  ( newForm.birdId.taxon.txKey,
                       str(newForm.birdId) )

Then we add the new form object to the two internal dictionaries.

birdnotes.py
        #-- 2 --
        self.__seqMap[seqNo]  =  self.__txMap[phyloKey]  =  newForm