1
0
Fork 0

Fix tests

This commit is contained in:
Thomas Versteeg 2022-02-14 18:12:08 +01:00
parent c88b34814f
commit d63e5ab2d2
3 changed files with 16 additions and 19 deletions

View file

@ -20,10 +20,10 @@ Stop Reading "<em>{{ book_title }}</em>"
<div class="columns"> <div class="columns">
<div class="column is-half"> <div class="column is-half">
<div class="field"> <div class="field">
<label class="label" for="finish_id_start_date_{{ uuid }}"> <label class="label" for="stop_id_start_date_{{ uuid }}">
{% trans "Started reading" %} {% trans "Started reading" %}
</label> </label>
<input type="date" name="start_date" class="input" id="finish_id_start_date_{{ uuid }}" value="{{ readthrough.start_date | date:"Y-m-d" }}"> <input type="date" name="start_date" class="input" id="stop_id_start_date_{{ uuid }}" value="{{ readthrough.start_date | date:"Y-m-d" }}">
</div> </div>
</div> </div>
<div class="column is-half"> <div class="column is-half">

View file

@ -36,22 +36,19 @@ def get_next_shelf(current_shelf):
def active_shelf(context, book): def active_shelf(context, book):
"""check what shelf a user has a book on, if any""" """check what shelf a user has a book on, if any"""
user = context["request"].user user = context["request"].user
return ( return cache.get_or_set(
cache.get_or_set( f"active_shelf-{user.id}-{book.id}",
f"active_shelf-{user.id}-{book.id}", lambda u, b: (
lambda u, b: ( models.ShelfBook.objects.filter(
models.ShelfBook.objects.filter( shelf__user=u,
shelf__user=u, book__parent_work__editions=b,
book__parent_work__editions=b, ).first()
).first() or False
or False ),
), user,
user, book,
book, timeout=15552000,
timeout=15552000, ) or {"book": book}
)
or {"book": book}
)
@register.simple_tag(takes_context=False) @register.simple_tag(takes_context=False)

View file

@ -53,7 +53,7 @@ class User(TestCase):
def test_user_shelves(self): def test_user_shelves(self):
shelves = models.Shelf.objects.filter(user=self.user).all() shelves = models.Shelf.objects.filter(user=self.user).all()
self.assertEqual(len(shelves), 3) self.assertEqual(len(shelves), 4)
names = [s.name for s in shelves] names = [s.name for s in shelves]
self.assertTrue("To Read" in names) self.assertTrue("To Read" in names)
self.assertTrue("Currently Reading" in names) self.assertTrue("Currently Reading" in names)