mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-01 22:11:16 +00:00
Fix for empty years
This commit is contained in:
parent
1fd44aeb5c
commit
c2c57db8e6
2 changed files with 17 additions and 7 deletions
|
@ -20,7 +20,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
{% with year=paginated_year|last %}
|
{% with year=paginated_years|last %}
|
||||||
{% if year %}
|
{% if year %}
|
||||||
<div class="column has-text-right">
|
<div class="column has-text-right">
|
||||||
<a href="{% url 'annual-summary' year %}">
|
<a href="{% url 'annual-summary' year %}">
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
<h1 class="title is-1 is-serif has-text-centered mb-5">{% blocktrans %}{{ year }} <em>in the books</em>{% endblocktrans %}</h1>
|
<h1 class="title is-1 is-serif has-text-centered mb-5">{% blocktrans %}{{ year }} <em>in the books</em>{% endblocktrans %}</h1>
|
||||||
|
|
||||||
{% if not books %}
|
{% if not books %}
|
||||||
{% blocktrans %}Sadly you didn't finish any book in {{ year }}{% endblocktrans %}
|
<p class="has-text-centered is-size-5">{% blocktrans %}Sadly you didn't finish any book in {{ year }}{% endblocktrans %}</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
<div class="columns is-mobile">
|
<div class="columns is-mobile">
|
||||||
|
|
|
@ -50,6 +50,11 @@ class AnnualSummary(View):
|
||||||
if not is_year_available(year):
|
if not is_year_available(year):
|
||||||
raise Http404(f"The summary for {year} is unavailable")
|
raise Http404(f"The summary for {year} is unavailable")
|
||||||
|
|
||||||
|
paginated_years = (
|
||||||
|
int(year) - 1,
|
||||||
|
int(year) + 1 if is_year_available(int(year) + 1) else None
|
||||||
|
)
|
||||||
|
|
||||||
user = request.user
|
user = request.user
|
||||||
read_shelf = get_object_or_404(user.shelf_set, identifier="read")
|
read_shelf = get_object_or_404(user.shelf_set, identifier="read")
|
||||||
read_book_ids_in_year = (
|
read_book_ids_in_year = (
|
||||||
|
@ -59,6 +64,16 @@ class AnnualSummary(View):
|
||||||
.order_by("shelved_date", "created_date", "updated_date")
|
.order_by("shelved_date", "created_date", "updated_date")
|
||||||
.values_list("book", flat=True)
|
.values_list("book", flat=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if len(read_book_ids_in_year) == 0:
|
||||||
|
data = {
|
||||||
|
"year": year,
|
||||||
|
"book_total": 0,
|
||||||
|
"books": [],
|
||||||
|
"paginated_years": paginated_years,
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, "annual_summary/layout.html", data)
|
||||||
|
|
||||||
read_shelf_order = Case(
|
read_shelf_order = Case(
|
||||||
*[When(pk=pk, then=pos) for pos, pk in enumerate(read_book_ids_in_year)]
|
*[When(pk=pk, then=pos) for pos, pk in enumerate(read_book_ids_in_year)]
|
||||||
)
|
)
|
||||||
|
@ -85,11 +100,6 @@ class AnnualSummary(View):
|
||||||
best_ratings_books_ids = [review.book.id for review in ratings.filter(rating=5)]
|
best_ratings_books_ids = [review.book.id for review in ratings.filter(rating=5)]
|
||||||
ratings_stats = ratings.aggregate(Avg("rating"))
|
ratings_stats = ratings.aggregate(Avg("rating"))
|
||||||
|
|
||||||
paginated_years = (
|
|
||||||
int(year) - 1,
|
|
||||||
int(year) + 1 if is_year_available(int(year) + 1) else None
|
|
||||||
)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"year": year,
|
"year": year,
|
||||||
"books_total": len(read_books_in_year),
|
"books_total": len(read_books_in_year),
|
||||||
|
|
Loading…
Reference in a new issue