Next / Previous / Contents / Shipman's homepage

11.9. BirdForm.singleSighting(): Read a single sighting

This method builds a Sighting instance from a form element when there are no child floc elements.

birdnotes.py
# - - -   B i r d F o r m . s i n g l e S i g h t i n g

    def singleSighting ( self, dayNotes, node ):
        """Build a Sighting child for the single-sighting case.

          [ (dayNotes is the parent DayNotes instance) and
            (node is an rnc.FORM_N node) ->
              self  :=  self with a single Sighting child added,
                  made from node's age-sex-group, loc-group, and
                  sighting-notes content ]
        """

See Section 12.1, “Sighting.__init__() for the constructor.

birdnotes.py
        #-- 1 --
        # [ sighting  :=  a new, empty Sighting instance with
        #                 self as the parent ]
        sighting  =  Sighting ( self )

Next, check for loc-group content. If there is any, and it has a loc attribute, we'll also need to be sure that location code is defined. See Section 13.2, “LocGroup.readNode(): Extract loc-group content” and Section 7.3, “DayNotes.lookupLoc(): Look up a location code”.

birdnotes.py
        #-- 2 --
        # [ if node has any valid loc-group content ->
        #     sighting.locGroup  :=  that content as a LocGroup
        #                            instance
        #   else if node loc-group content with a loc that is
        #   not in dayNotes ->
        #     raise IOError
        #   else ->
        #     sighting.locGroup  :=  None ]
        sighting.locGroup  =  LocGroup.readNode ( node, dayNotes )

The other two kinds of content proceed similarly. See Section 14.2, “AgeSexGroup.readNode() (static method)” and Section 15.5, “SightNotes.readNode() (static method)”.

birdnotes.py
        #-- 3 --
        # [ if  node has any age-sex-group content ->
        #     sighting.ageSexGroup  :=  a new AgeSexGroup
        #         instance representing that content
        #   else ->
        #     sighting.ageSexGroup  :=  None ]
        sighting.ageSexGroup  =  AgeSexGroup.readNode ( node )

        #-- 4 --
        # [ if node has any sighting-notes content ->
        #     sighting.sightNotes  :=  a new SightNotes instance
        #         representing that content
        #   else ->
        #     sighting.sightNotes  :=  None ]
        sighting.sightNotes  =  SightNotes.readNode ( node )

To add the new child sighting, see Section 11.3, “BirdForm.addSighting().

birdnotes.py
        #-- 5 --
        # [ self  :=  self with sighting added ] 
        self.addSighting(sighting)