__all__=["MomentInfo"]"""MomentInfo class with details about photo moments."""
[docs]classMomentInfo:"""Info about a photo moment"""def__init__(self,db,moment_pk):"""Initialize with a moment PK; returns None if PK not found."""self._db=dbself._pk=moment_pkself._moment=self._db._db_moment_pk.get(moment_pk)ifnotself._moment:raiseValueError(f"No moment with PK {moment_pk}")@propertydefpk(self):"""Primary key of the moment."""returnself._pk@propertydeflocation(self):"""Location of the moment."""return(self._moment.get("latitude"),self._moment.get("longitude"))@propertydeftitle(self):"""Title of the moment."""returnself._moment.get("title")@propertydefsubtitle(self):"""Subtitle of the moment."""returnself._moment.get("subtitle")@propertydefstart_date(self):"""Start date of the moment."""returnself._moment.get("startDate")@propertydefend_date(self):"""Stop date of the moment."""returnself._moment.get("endDate")@propertydefdate(self):"""Date of the moment."""returnself._moment.get("representativeDate")@propertydefmodification_date(self):"""Modification date of the moment."""returnself._moment.get("modificationDate")@propertydefphotos(self):"""All photos in this moment"""try:returnself._photosexceptAttributeError:photo_uuids=[uuidforuuid,photoinself._db._dbphotos.items()ifphoto["momentID"]==self._pk]self._photos=self._db.photos_by_uuid(photo_uuids)returnself._photos
[docs]defasdict(self):"""Returns all moment info as dictionary"""return{"pk":self.pk,"location":self.location,"title":self.title,"subtitle":self.subtitle,"start_date":self.start_date.isoformat()ifself.start_dateelseNone,"end_date":self.end_date.isoformat()ifself.end_dateelseNone,"date":self.date.isoformat()ifself.dateelseNone,"modification_date":(self.modification_date.isoformat()ifself.modification_dateelseNone),"photos":self.photos,}