diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 35c8757b..0abf1584 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -56,7 +56,13 @@ class ActivityStream(RedisStore): return ( models.Status.objects.select_subclasses() .filter(id__in=statuses) - .select_related("user", "reply_parent") + .select_related( + "user", + "reply_parent", + "comment__book", + "review__book", + "quotation__book", + ) .prefetch_related("mention_books", "mention_users") .order_by("-published_date") ) diff --git a/bookwyrm/templates/discover/large-book.html b/bookwyrm/templates/discover/large-book.html index ce341376..81654d57 100644 --- a/bookwyrm/templates/discover/large-book.html +++ b/bookwyrm/templates/discover/large-book.html @@ -1,73 +1,73 @@ {% load bookwyrm_tags %} {% load i18n %} +{% load utilities %} {% load status_display %} -{% if status %} - {% with book=status.book %} -
-
- {% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto-tablet' %} +{% if status.book or status.mention_books.exists %} + {% load_book status as book %} +
+
+ {% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto-tablet' %} - {% include 'snippets/stars.html' with rating=book|rating:request.user %} -

- {{ book.title }} -

+ {% include 'snippets/stars.html' with rating=book|rating:request.user %} +

+ {{ book|book_title }} +

- {% if book.authors %} -

- {% trans "by" %} - {% include 'snippets/authors.html' with limit=3 %} -

- {% endif %} + {% if book.authors %} +

+ {% trans "by" %} + {% include 'snippets/authors.html' with limit=3 %} +

+ {% endif %} - {% include 'snippets/shelve_button/shelve_button.html' %} -
- -
-
- -
-

- - {{ status.user.display_name }} - - - {% if status.status_type == 'GeneratedNote' %} - {{ status.content|safe }} - {% elif status.status_type == 'Rating' %} - {% trans "rated" %} - {% elif status.status_type == 'Review' %} - {% trans "reviewed" %} - {% elif status.status_type == 'Comment' %} - {% trans "commented on" %} - {% elif status.status_type == 'Quotation' %} - {% trans "quoted" %} - {% endif %} - - {{ book.title }} -

-
-
- -
- {% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %} -
- -
- {% include "snippets/status/content_status.html" with hide_book=True trim_length=70 hide_more=True %} -
- - {% trans "View status" %} - - -
+ {% include 'snippets/shelve_button/shelve_button.html' %}
- {% endwith %} + +
+
+ +
+

+ + {{ status.user.display_name }} + + + {% if status.status_type == 'GeneratedNote' %} + {{ status.content|safe }} + {% elif status.status_type == 'Rating' %} + {% trans "rated" %} + {% elif status.status_type == 'Review' %} + {% trans "reviewed" %} + {% elif status.status_type == 'Comment' %} + {% trans "commented on" %} + {% elif status.status_type == 'Quotation' %} + {% trans "quoted" %} + {% endif %} + + {{ book.title }} +

+
+
+ +
+ {% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %} +
+ +
+ {% include "snippets/status/content_status.html" with hide_book=True trim_length=70 hide_more=True %} +
+ + {% trans "View status" %} + + +
+
{% endif %} diff --git a/bookwyrm/templates/discover/small-book.html b/bookwyrm/templates/discover/small-book.html index 1318c8bd..79fbd77c 100644 --- a/bookwyrm/templates/discover/small-book.html +++ b/bookwyrm/templates/discover/small-book.html @@ -1,54 +1,59 @@ {% load bookwyrm_tags %} {% load utilities %} {% load i18n %} +{% load status_display %} -{% if status %} - {% with book=status.book %} - - {% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto align to-b to-l' %} - +{% if status.book or status.mention_books.exists %} + {% load_book status as book %} + + {% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto align to-b to-l' %} + -
- {% include 'snippets/shelve_button/shelve_button.html' %} -
+
+ {% include 'snippets/shelve_button/shelve_button.html' %} +
-
- -
-

- - {{ status.user.display_name }} - - - {% if status.status_type == 'GeneratedNote' %} - {{ status.content|safe }} - {% elif status.status_type == 'Rating' %} - {% trans "rated" %} - {% elif status.status_type == 'Review' %} - {% trans "reviewed" %} - {% elif status.status_type == 'Comment' %} - {% trans "commented on" %} - {% elif status.status_type == 'Quotation' %} - {% trans "quoted" %} - {% endif %} - - {{ book.title }} -

- {% if status.rating %} -

- {% include 'snippets/stars.html' with rating=status.rating %} -

+ {% if status.status_type == 'GeneratedNote' %} + {{ status.content|safe }} + {% elif status.status_type == 'Rating' %} + {% trans "rated" %} + {% elif status.status_type == 'Review' %} + {% trans "reviewed" %} + {% elif status.status_type == 'Comment' %} + {% trans "commented on" %} + {% elif status.status_type == 'Quotation' %} + {% trans "quoted" %} {% endif %} -
-
-
- {% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %} -
- {% endwith %} + {{ book.title }} + + {% if status.rating %} +

+ {% include 'snippets/stars.html' with rating=status.rating %} +

+ {% endif %} +
+ +
+ + {% trans "View status" %} + + +
+
+ {% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %} +
{% endif %} diff --git a/bookwyrm/templatetags/status_display.py b/bookwyrm/templatetags/status_display.py index 69c0c2a5..3339a8be 100644 --- a/bookwyrm/templatetags/status_display.py +++ b/bookwyrm/templatetags/status_display.py @@ -62,3 +62,9 @@ def get_published_date(date): if delta.days: return naturalday(date, "M j") return naturaltime(date) + + +@register.simple_tag(takes_context=False) +def load_book(status): + """how many users that you follow, follow them""" + return status.book if hasattr(status, "book") else status.mention_books.first() diff --git a/bookwyrm/views/discover.py b/bookwyrm/views/discover.py index 0b1fae2b..059365f9 100644 --- a/bookwyrm/views/discover.py +++ b/bookwyrm/views/discover.py @@ -6,8 +6,7 @@ from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View -from bookwyrm import models -from .helpers import privacy_filter +from bookwyrm import activitystreams # pylint: disable= no-self-use @@ -17,21 +16,28 @@ class Discover(View): def get(self, request): """tiled book activity page""" - activities = privacy_filter( - request.user, - models.Status.objects.select_subclasses().filter( + activities = ( + activitystreams.streams["local"] + .get_activity_stream(request.user) + .filter( Q(comment__isnull=False) | Q(review__isnull=False) - | Q(quotation__isnull=False), - user__local=True, - ), - privacy_levels=["public"], + | Q(quotation__isnull=False) + | Q(mention_books__isnull=False) + ) ) + large_activities = Paginator( - activities.filter(~Q(content=None), ~Q(content="")), 6 + activities.filter(mention_books__isnull=True) + .exclude(content=None, quotation__quote=None) + .exclude(content=""), + 6, ) small_activities = Paginator( - activities.filter(Q(content=None) | Q(content="")), 4 + activities.filter( + Q(mention_books__isnull=False) | Q(content=None) | Q(content="") + ), + 4, ) page = request.GET.get("page")