Next / Previous / Contents / Shipman's homepage

11.6. BirdForm.getLocGroup(): Find the effective locality

This method uses inheritance to find the effective locality data.

birdnotes.py
# - - -   B i r d F o r m . g e t L o c G r o u p

    def getLocGroup ( self ):
        """Get the effective locality.
        """

First we get the effective default locality for the day. See Section 7.2, “DayNotes.defaultLoc(): Return the default location”, which returns a location code as a string, and Section 13, “class LocGroup: Sighting's locality” for the constructor that wraps that in a LocGroup instance.

birdnotes.py
        #-- 1 --
        # [ parentGroup  :=  a LocGroup instance representing the
        #       default locality for self.dayNotes ]
        parentGroup  =  LocGroup ( self.dayNotes.defaultLoc() )

If there is no locality data at this level, we'll just return the parent's locality. Otherwise, we'll use the LocGroup.inherit() method to build a new LocGroup instance with default values replaced by inherited values . See Section 13.3, “LocGroup.inherit(): Implement inheritance for locations”.

birdnotes.py
        #-- 2 --
        # [ if self.locGroup is None ->
        #     return parentGroup
        #   else ->
        #     return a new LocGroup instance made from
        #         self.locGroup inheriting from parentGroup ]
        if  self.locGroup:
            return  self.locGroup.inherit ( parentGroup )
        else:
            return  parentGroup