[books] Really fix the subtitle bug

This commit is contained in:
2026-06-11 10:48:21 -04:00
parent 25c28e8335
commit 29cb6a4991

View File

@ -71,7 +71,7 @@ class BookLogData(BaseLogData, LongPlayLogData):
_excluded_fields = {"koreader_hash", "page_data"} _excluded_fields = {"koreader_hash", "page_data"}
def avg_seconds_per_page(self): def avg_seconds_per_page(self):
if self.page_data: if self.page_data and isinstance(self.page_data, dict):
total_duration = 0 total_duration = 0
for page_num, stats in self.page_data.items(): for page_num, stats in self.page_data.items():
total_duration += stats.get("duration", 0) total_duration += stats.get("duration", 0)
@ -173,6 +173,9 @@ class Book(LongPlayScrobblableMixin):
genre = TaggableManager(through=ObjectWithGenres, blank=True, verbose_name="Genre") genre = TaggableManager(through=ObjectWithGenres, blank=True, verbose_name="Genre")
def __str__(self) -> str: def __str__(self) -> str:
if not self.subtitle:
return self.title
return f"{self.title} - {self.subtitle}" return f"{self.title} - {self.subtitle}"
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
@ -184,14 +187,18 @@ class Book(LongPlayScrobblableMixin):
@property @property
def subtitle(self): def subtitle(self):
subtitle = "" subtitle_parts = []
if self.author: if self.author:
subtitle += self.author.name subtitle_parts.append(self.author.name)
if self.issue_number and "Issue" not in str(self.title): if self.issue_number and "Issue" not in str(self.title):
subtitle += " - Issue {self.issue_number}" subtitle_parts.append(f"Issue {self.issue_number}")
if self.volume_number and "Volume" not in str(self.title): if self.volume_number and "Volume" not in str(self.title):
subtitle += " - Volume {self.volume_number}" subtitle_parts.append(f"Volume {self.volume_number}")
return subtitle if len(subtitle_parts) > 1:
return " / ".join(subtitle_parts)
if len(subtitle_parts) == 1:
return subtitle_parts[0]
return ""
@property @property
def strings(self) -> ScrobblableConstants: def strings(self) -> ScrobblableConstants: