ImportItem: preserve parsed timezones in date_started, date_read

This is a follow-up to b564e514f ("Handle parsed dates that already
have a timezone on import"), which was applied to `date_added` only.

(Appart from consistency, this will allow to apply future parsing fixes
more easily.)
This commit is contained in:
Adeodato Simó 2023-10-15 19:43:51 -03:00
parent 6667178703
commit 8f0f3e6ace
No known key found for this signature in database
GPG key ID: CDF447845F1A986F

View file

@ -259,12 +259,10 @@ class ImportItem(models.Model):
except ValueError: except ValueError:
return None return None
@property def _parse_datefield(self, field, /):
def date_added(self): if self.normalized_data.get(field):
"""when the book was added to this dataset"""
if self.normalized_data.get("date_added"):
parsed_date_added = dateutil.parser.parse( parsed_date_added = dateutil.parser.parse(
self.normalized_data.get("date_added") self.normalized_data.get(field)
) )
if timezone.is_aware(parsed_date_added): if timezone.is_aware(parsed_date_added):
@ -274,23 +272,20 @@ class ImportItem(models.Model):
return timezone.make_aware(parsed_date_added) return timezone.make_aware(parsed_date_added)
return None return None
@property
def date_added(self):
"""when the book was added to this dataset"""
return self._parse_datefield("date_added")
@property @property
def date_started(self): def date_started(self):
"""when the book was started""" """when the book was started"""
if self.normalized_data.get("date_started"): return self._parse_datefield("date_started")
return timezone.make_aware(
dateutil.parser.parse(self.normalized_data.get("date_started"))
)
return None
@property @property
def date_read(self): def date_read(self):
"""the date a book was completed""" """the date a book was completed"""
if self.normalized_data.get("date_finished"): return self._parse_datefield("date_finished")
return timezone.make_aware(
dateutil.parser.parse(self.normalized_data.get("date_finished"))
)
return None
@property @property
def reads(self): def reads(self):