Fix calculating pages read
This commit is contained in:
@ -451,11 +451,20 @@ class Scrobble(TimeStampedModel):
|
||||
@property
|
||||
def previous(self):
|
||||
return (
|
||||
self.media_obj.scrobble_set.filter(timestamp__lt=self.timestamp)
|
||||
.order_by("-timestamp")
|
||||
.last()
|
||||
self.media_obj.scrobble_set.order_by("-timestamp")
|
||||
.filter(timestamp__lt=self.timestamp)
|
||||
.first()
|
||||
)
|
||||
|
||||
@property
|
||||
def session_pages_read(self) -> Optional[int]:
|
||||
"""Look one scrobble back, if it isn't complete,"""
|
||||
if not self.book_pages_read:
|
||||
return
|
||||
if self.previous:
|
||||
return self.book_pages_read - self.previous.book_pages_read
|
||||
return self.book_pages_read
|
||||
|
||||
@property
|
||||
def percent_played(self) -> int:
|
||||
if not self.media_obj:
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<p>{{object.scrobble_set.count}} scrobbles</p>
|
||||
<p>{{object.scrobble_set.last.book_pages_read}} page read to {% if object.scrobble_set.last.long_play_complete %} and completed{% else %}{% endif %}</p>
|
||||
<p>Read {{object.scrobble_set.last.book_pages_read}} pages{% if object.scrobble_set.last.long_play_complete %} and completed{% else %}{% endif %}</p>
|
||||
<p>
|
||||
{% if object.scrobble_set.last.long_play_complete == True %}
|
||||
<a href="">Read again</a>
|
||||
@ -45,7 +45,7 @@
|
||||
<tr>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">Completed</th>
|
||||
<th scope="col">Page read to</th>
|
||||
<th scope="col">Pages read</th>
|
||||
<th scope="col">Authors</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -54,7 +54,7 @@
|
||||
<tr>
|
||||
<td>{{scrobble.timestamp}}</td>
|
||||
<td>{% if scrobble.long_play_complete == True %}Yes{% endif %}</td>
|
||||
<td>{% if scrobble.in_progress %}Now reading{% else %}{{scrobble.book_pages_read}}{% endif %}</td>
|
||||
<td>{% if scrobble.in_progress %}Now reading{% else %}{{scrobble.session_pages_read}}{% endif %}</td>
|
||||
<td>{% for author in scrobble.book.authors.all %}<a href="{{author.get_absolute_url}}">{{author}}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user