diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 86321cd83..ff3c55fbd 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -55,6 +55,8 @@ class ActivityStream(RedisStore): return ( models.Status.objects.select_subclasses() .filter(id__in=statuses) + .select_related("user", "reply_parent") + .prefetch_related("mention_books", "mention_users") .order_by("-published_date") ) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 7d821c5ba..d9f3eba99 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -381,17 +381,16 @@ class AnnualGoal(BookWyrmModel): return {r.book.id: r.rating for r in reviews} @property - def progress_percent(self): - """how close to your goal, in percent form""" - return int(float(self.book_count / self.goal) * 100) - - @property - def book_count(self): + def progress(self): """how many books you've read this year""" - return self.user.readthrough_set.filter( + count = self.user.readthrough_set.filter( finish_date__year__gte=self.year, finish_date__year__lt=self.year + 1, ).count() + return { + "count": count, + "percent": int(float(count / self.goal) * 100), + } @app.task diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index fb0a45101..df76d8e11 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -1,7 +1,7 @@ {% extends 'layout.html' %} {% load i18n %}{% load bookwyrm_tags %}{% load humanize %}{% load utilities %} -{% block title %}{{ book.title }}{% endblock %} +{% block title %}{{ book|title }}{% endblock %} {% block content %} {% with user_authenticated=request.user.is_authenticated can_edit_book=perms.bookwyrm.edit_book %} @@ -137,7 +137,7 @@ {# user's relationship to the book #}
{% blocktrans with path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}This edition is on your {{ shelf_name }} shelf.{% endblocktrans %} {% include 'snippets/shelf_selector.html' with current=shelf.shelf %} diff --git a/bookwyrm/templates/get_started/book_preview.html b/bookwyrm/templates/get_started/book_preview.html index 578fef708..d8941ad50 100644 --- a/bookwyrm/templates/get_started/book_preview.html +++ b/bookwyrm/templates/get_started/book_preview.html @@ -5,7 +5,7 @@
- {% include 'snippets/block_button.html' with user=user %} + {% include 'snippets/block_button.html' with user=user blocks=True %}
{% endfor %} diff --git a/bookwyrm/templates/snippets/block_button.html b/bookwyrm/templates/snippets/block_button.html index 7e9fcaea3..3cad78f6d 100644 --- a/bookwyrm/templates/snippets/block_button.html +++ b/bookwyrm/templates/snippets/block_button.html @@ -1,5 +1,5 @@ {% load i18n %} -{% if not user in request.user.blocks.all %} +{% if not blocks %} - {% endwith %} +{% endwith %} diff --git a/bookwyrm/templates/snippets/fav_button.html b/bookwyrm/templates/snippets/fav_button.html index 40fa2d25f..6c4cfe9aa 100644 --- a/bookwyrm/templates/snippets/fav_button.html +++ b/bookwyrm/templates/snippets/fav_button.html @@ -3,7 +3,8 @@ {% load i18n %} {% with status.id|uuid as uuid %} - - {% endwith %} +{% endwith %} diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index 495bc3e98..0cbe6b8cd 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -1,7 +1,7 @@ {% load i18n %} {% if request.user == user or not request.user.is_authenticated %} {% elif user in request.user.blocks.all %} -{% include 'snippets/block_button.html' %} +{% include 'snippets/block_button.html' with blocks=True %} {% else %}- {% if goal.progress_percent >= 100 %} + {% if progress.percent >= 100 %} {% trans "Success!" %} - {% elif goal.progress_percent %} - {% blocktrans with percent=goal.progress_percent %}{{ percent }}% complete!{% endblocktrans %} + {% elif progress.percent %} + {% blocktrans with percent=progress.percent %}{{ percent }}% complete!{% endblocktrans %} {% endif %} {% if goal.user == request.user %} - {% blocktrans with read_count=goal.book_count|intcomma goal_count=goal.goal|intcomma path=goal.local_path %}You've read {{ read_count }} of {{ goal_count}} books.{% endblocktrans %} + {% blocktrans with read_count=progress.count|intcomma goal_count=goal.goal|intcomma path=goal.local_path %}You've read {{ read_count }} of {{ goal_count}} books.{% endblocktrans %} {% else %} - {% blocktrans with username=goal.user.display_name read_count=goal.book_count|intcomma goal_count=goal.goal|intcomma path=goal.local_path %}{{ username }} has read {{ read_count }} of {{ goal_count}} books.{% endblocktrans %} + {% blocktrans with username=goal.user.display_name read_count=progress.count|intcomma goal_count=goal.goal|intcomma path=goal.local_path %}{{ username }} has read {{ read_count }} of {{ goal_count}} books.{% endblocktrans %} {% endif %}
- + +{% endwith %} diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html index 0036a4e90..ca5a39f6e 100644 --- a/bookwyrm/templates/snippets/shelf_selector.html +++ b/bookwyrm/templates/snippets/shelf_selector.html @@ -6,7 +6,7 @@ {% endblock %} {% block dropdown-list %} -{% for shelf in request.user.shelf_set.all %} +{% for shelf in user_shelves %}