[books] Calculate page data on scrobble save
This commit is contained in:
@ -571,6 +571,8 @@ class Scrobble(TimeStampedModel):
|
||||
return reverse("scrobbles:finish", kwargs={"uuid": self.uuid})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
class_name = self.media_obj.__class__.__name__
|
||||
|
||||
if not self.uuid:
|
||||
self.uuid = uuid4()
|
||||
|
||||
@ -593,6 +595,9 @@ class Scrobble(TimeStampedModel):
|
||||
self.stop_timestamp - self.timestamp
|
||||
).seconds
|
||||
|
||||
if class_name == "Book":
|
||||
self.calculate_reading_stats(commit=False)
|
||||
|
||||
if (
|
||||
self.log
|
||||
and isinstance(self.log, dict)
|
||||
@ -600,16 +605,14 @@ class Scrobble(TimeStampedModel):
|
||||
and self.log.get("page_end") is not None
|
||||
and "pages_read" not in self.log
|
||||
):
|
||||
self.log["pages_read"] = (
|
||||
self.log["page_end"] - self.log["page_start"] + 1
|
||||
)
|
||||
self.log["pages_read"] = self.log["page_end"] - self.log["page_start"] + 1
|
||||
|
||||
return super(Scrobble, self).save(*args, **kwargs)
|
||||
|
||||
def get_absolute_url(self):
|
||||
if not self.uuid:
|
||||
self.uuid = uuid4()
|
||||
self.save()
|
||||
self.save(update_fields=["uuid"])
|
||||
return reverse("scrobbles:detail", kwargs={"uuid": self.uuid})
|
||||
|
||||
def push_to_archivebox(self):
|
||||
|
||||
Reference in New Issue
Block a user