For applications where the sighting record must stand alone, an instance of this class gathers data from the sighting's context, and can generate a delimited record suitable for importation into a spreadsheet.
# - - - - - c l a s s F l a t S i g h t i n g
class FlatSighting(object):
'''Represents a Sighting with its context.
Exports:
FlatSighting(sighting):
[ sighting is a Sighting instance ->
return a new FlatSighting representing sighting
and its context ]
.txKey:
[ taxonomic key number for the smallest taxon that
contains the bird form for sighting ]
.abbr:
[ first or only bird code, stripped ]
.rel:
[ if this sighting is for a single form -> ""
else -> relationship code as in BirdId.rel ]
.abbr2:
[ if this sighting is for a single form -> ""
else -> second bird code, stripped ]
.eng:
[ English name as "Generic[, Specific]" ]
.age: [ age code or "" if unknown ]
.sex: [ sex code or "" if unknown ]
.q: [ questionable/uncountable flag or "" ]
.count: [ count field as in AgeSexGroup.count, or "" ]
.date: [ date as "YYYY-MM-DD" ]
.regionCode: [ region code as in DayNotes.regionCode ]
.locName: [ locality name string ]
.observer:
[ if seen by the primary observer -> ""
else -> observer's name ]
.delimited(delimiter='\t'):
[ delimiter is a string ->
return self as a string containing all the attributes
above in the same order, with (delimiter) between
each attribute value ]
'''
# - - - F l a t S i g h t i n g . _ _ i n i t _ _
def __init__(self, sighting):
'''Flatten a Sighting instance.
'''
birdForm = sighting.birdForm
dayNotes = birdForm.dayNotes
birdId = birdForm.birdId
self.txKey = birdId.taxon.txKey
self.abbr = birdId.abbr
self.rel = birdId.rel or ''
self.abbr2 = birdId.abbr2 or ''
self.eng = birdId.engComma()
ageSex = sighting.ageSexGroup
if ageSex is None:
self.age = ''
self.sex = ''
self.q = ''
self.count = ''
self.observer = ''
else:
self.age = ageSex.age or ''
self.sex = ageSex.sex or ''
self.q = ageSex.q or ''
self.count = ageSex.count or ''
self.observer = ageSex.fide or ''
self.date = dayNotes.date
self.regionCode = dayNotes.regionCode.upper()
self.locName = self.sanitize(sighting.getLocGroup().loc.name)