Show consistent book status regardless of edition

This commit is contained in:
Mouse Reeve 2020-12-16 09:15:26 -08:00
parent af823cf645
commit 729e50de63
3 changed files with 15 additions and 14 deletions

View file

@ -4,24 +4,24 @@
{% with book.id|uuid as uuid %}
{% active_shelf book as active_shelf %}
<div class="field is-grouped">
{% if active_shelf.identifier == 'read' %}
{% if active_shelf.shelf.identifier == 'read' %}
<button class="button is-small" disabled>
<span>Read</span> <span class="icon icon-check"></span>
</button>
{% elif active_shelf.identifier == 'reading' %}
{% elif active_shelf.shelf.identifier == 'reading' %}
<label class="button is-small" for="finish-reading-{{ uuid }}" role="button" tabindex="0">
I'm done!
</label>
{% include 'snippets/finish_reading_modal.html' %}
{% elif active_shelf.identifier == 'to-read' %}
{% include 'snippets/finish_reading_modal.html' with book=active_shelf.book %}
{% elif active_shelf.shelf.identifier == 'to-read' %}
<label class="button is-small" for="start-reading-{{ uuid }}" role="button" tabindex="0">
Start reading
</label>
{% include 'snippets/start_reading_modal.html' %}
{% include 'snippets/start_reading_modal.html' with book=active_shelf.book %}
{% else %}
<form name="shelve" action="/shelve/" method="post">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="book" value="{{ active_shelf.book.id }}">
<input type="hidden" name="shelf" value="to-read">
<button class="button is-small" type="submit">Want to read</button>
</form>
@ -40,17 +40,17 @@
<ul class="dropdown-content">
{% for shelf in request.user.shelf_set.all %}
<li role="menuitem">
{% if shelf.identifier == 'to-read' %}
{% if active_shelf.shelf.identifier == 'to-read' and shelf.identifier == 'reading' %}
<div class="dropdown-item pt-0 pb-0">
<label class="button is-small" for="start-reading-{{ uuid }}" role="button" tabindex="0">
Start reading
</label>
{% include 'snippets/start_reading_modal.html' %}
{% include 'snippets/start_reading_modal.html' with book=active_shelf.book %}
</div>
{% else %}
<form class="dropdown-item pt-0 pb-0" name="shelve" action="/shelve/" method="post">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="book" value="{{ active_shelf.book.id }}">
<button class="button is-small" name="shelf" type="submit" value="{{ shelf.identifier }}" {% if shelf in book.shelf_set.all %} disabled {% endif %}>
<span>{{ shelf.name }}</span>
{% if shelf in book.shelf_set.all %}<span class="icon icon-check"></span>{% endif %}

View file

@ -132,9 +132,10 @@ def time_since(date):
delta = now - date
if date < (now - relativedelta(weeks=1)):
formatter = '%b %-d'
if date.year != now.year:
return date.strftime('%b %-d %Y')
return date.strftime('%b %-d')
formatter += ' %Y'
return date.strftime(formatter)
delta = relativedelta(now, date)
if delta.days:
return '%dd' % delta.days
@ -150,9 +151,9 @@ def active_shelf(context, book):
''' check what shelf a user has a book on, if any '''
shelf = models.ShelfBook.objects.filter(
shelf__user=context['request'].user,
book=book
book__in=book.parent_work.editions.all()
).first()
return shelf.shelf if shelf else None
return shelf if shelf else {'book': book}
@register.simple_tag(takes_context=False)

View file

@ -675,7 +675,7 @@ def editions_page(request, book_id):
data = {
'title': 'Editions of %s' % work.title,
'editions': work.edition_set.all(),
'editions': work.editions.all(),
'work': work,
}
return TemplateResponse(request, 'editions.html', data)