mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-17 20:56:08 +00:00
Use activitystreams to populate discovery view
This commit is contained in:
parent
590338138c
commit
c14bcf19cc
5 changed files with 142 additions and 119 deletions
|
@ -56,7 +56,13 @@ class ActivityStream(RedisStore):
|
||||||
return (
|
return (
|
||||||
models.Status.objects.select_subclasses()
|
models.Status.objects.select_subclasses()
|
||||||
.filter(id__in=statuses)
|
.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")
|
.prefetch_related("mention_books", "mention_users")
|
||||||
.order_by("-published_date")
|
.order_by("-published_date")
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,73 +1,73 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load bookwyrm_tags %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load utilities %}
|
||||||
{% load status_display %}
|
{% load status_display %}
|
||||||
|
|
||||||
{% if status %}
|
{% if status.book or status.mention_books.exists %}
|
||||||
{% with book=status.book %}
|
{% load_book status as book %}
|
||||||
<div class="columns is-gapless">
|
<div class="columns is-gapless">
|
||||||
<div class="column is-6-tablet is-cover">
|
<div class="column is-6-tablet is-cover">
|
||||||
<a
|
<a
|
||||||
class="align to-b to-l"
|
class="align to-b to-l"
|
||||||
href="{{ book.local_path }}"
|
href="{{ book.local_path }}"
|
||||||
>{% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto-tablet' %}</a>
|
>{% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto-tablet' %}</a>
|
||||||
|
|
||||||
{% include 'snippets/stars.html' with rating=book|rating:request.user %}
|
{% include 'snippets/stars.html' with rating=book|rating:request.user %}
|
||||||
<h3 class="title is-6">
|
<h3 class="title is-6">
|
||||||
<a href="{{ book.local_path }}">{{ book.title }}</a>
|
<a href="{{ book.local_path }}">{{ book|book_title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
{% if book.authors %}
|
{% if book.authors %}
|
||||||
<p class="subtitle is-6 mb-2">
|
<p class="subtitle is-6 mb-2">
|
||||||
{% trans "by" %}
|
{% trans "by" %}
|
||||||
{% include 'snippets/authors.html' with limit=3 %}
|
{% include 'snippets/authors.html' with limit=3 %}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% include 'snippets/shelve_button/shelve_button.html' %}
|
{% include 'snippets/shelve_button/shelve_button.html' %}
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="column mt-3-mobile ml-3-tablet">
|
|
||||||
<div class="media block mb-2">
|
|
||||||
<figure class="media-left" aria-hidden="true">
|
|
||||||
<a class="image is-48x48" href="{{ status.user.local_path }}">
|
|
||||||
{% include 'snippets/avatar.html' with user=status.user ariaHide="true" medium="true" %}
|
|
||||||
</a>
|
|
||||||
</figure>
|
|
||||||
<div class="media-content">
|
|
||||||
<h3 class="title is-6">
|
|
||||||
<a href="{{ status.user.local_path }}">
|
|
||||||
<span>{{ status.user.display_name }}</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{% 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 %}
|
|
||||||
|
|
||||||
<a href="{{ book.local_path }}">{{ book.title }}</a>
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="block">
|
|
||||||
{% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="notification has-background-white p-2 mb-2 clip-text">
|
|
||||||
{% include "snippets/status/content_status.html" with hide_book=True trim_length=70 hide_more=True %}
|
|
||||||
</div>
|
|
||||||
<a href="{{ status.remote_id }}">
|
|
||||||
<span>{% trans "View status" %}</span>
|
|
||||||
<span class="icon icon-arrow-right" aria-hidden="true"></span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% endwith %}
|
|
||||||
|
<div class="column mt-3-mobile ml-3-tablet">
|
||||||
|
<div class="media block mb-2">
|
||||||
|
<figure class="media-left" aria-hidden="true">
|
||||||
|
<a class="image is-48x48" href="{{ status.user.local_path }}">
|
||||||
|
{% include 'snippets/avatar.html' with user=status.user ariaHide="true" medium="true" %}
|
||||||
|
</a>
|
||||||
|
</figure>
|
||||||
|
<div class="media-content">
|
||||||
|
<h3 class="title is-6">
|
||||||
|
<a href="{{ status.user.local_path }}">
|
||||||
|
<span>{{ status.user.display_name }}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{% 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 %}
|
||||||
|
|
||||||
|
<a href="{{ book.local_path }}">{{ book.title }}</a>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="block">
|
||||||
|
{% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="notification has-background-white p-2 mb-2 clip-text">
|
||||||
|
{% include "snippets/status/content_status.html" with hide_book=True trim_length=70 hide_more=True %}
|
||||||
|
</div>
|
||||||
|
<a href="{{ status.remote_id }}">
|
||||||
|
<span>{% trans "View status" %}</span>
|
||||||
|
<span class="icon icon-arrow-right" aria-hidden="true"></span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,54 +1,59 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load bookwyrm_tags %}
|
||||||
{% load utilities %}
|
{% load utilities %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load status_display %}
|
||||||
|
|
||||||
{% if status %}
|
{% if status.book or status.mention_books.exists %}
|
||||||
{% with book=status.book %}
|
{% load_book status as book %}
|
||||||
<a href="{{ book.local_path }}">
|
<a href="{{ book.local_path }}">
|
||||||
{% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto align to-b to-l' %}
|
{% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto align to-b to-l' %}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="block mt-2">
|
<div class="block mt-2">
|
||||||
{% include 'snippets/shelve_button/shelve_button.html' %}
|
{% include 'snippets/shelve_button/shelve_button.html' %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="media block mb-2">
|
<div class="media block mb-2">
|
||||||
<figure class="media-left" aria-hidden="true">
|
<figure class="media-left" aria-hidden="true">
|
||||||
<a class="image is-48x48" href="{{ status.user.local_path }}">
|
<a class="image is-48x48" href="{{ status.user.local_path }}">
|
||||||
{% include 'snippets/avatar.html' with user=status.user ariaHide="true" medium="true" %}
|
{% include 'snippets/avatar.html' with user=status.user ariaHide="true" medium="true" %}
|
||||||
|
</a>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<div class="media-content">
|
||||||
|
<h3 class="title is-6">
|
||||||
|
<a href="{{ status.user.local_path }}">
|
||||||
|
<span>{{ status.user.display_name }}</span>
|
||||||
</a>
|
</a>
|
||||||
</figure>
|
|
||||||
|
|
||||||
<div class="media-content">
|
{% if status.status_type == 'GeneratedNote' %}
|
||||||
<h3 class="title is-6">
|
{{ status.content|safe }}
|
||||||
<a href="{{ status.user.local_path }}">
|
{% elif status.status_type == 'Rating' %}
|
||||||
<span>{{ status.user.display_name }}</span>
|
{% trans "rated" %}
|
||||||
</a>
|
{% elif status.status_type == 'Review' %}
|
||||||
|
{% trans "reviewed" %}
|
||||||
{% if status.status_type == 'GeneratedNote' %}
|
{% elif status.status_type == 'Comment' %}
|
||||||
{{ status.content|safe }}
|
{% trans "commented on" %}
|
||||||
{% elif status.status_type == 'Rating' %}
|
{% elif status.status_type == 'Quotation' %}
|
||||||
{% trans "rated" %}
|
{% trans "quoted" %}
|
||||||
{% elif status.status_type == 'Review' %}
|
|
||||||
{% trans "reviewed" %}
|
|
||||||
{% elif status.status_type == 'Comment' %}
|
|
||||||
{% trans "commented on" %}
|
|
||||||
{% elif status.status_type == 'Quotation' %}
|
|
||||||
{% trans "quoted" %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<a href="{{ book.local_path }}">{{ book.title }}</a>
|
|
||||||
</h3>
|
|
||||||
{% if status.rating %}
|
|
||||||
<p class="subtitle is-6">
|
|
||||||
{% include 'snippets/stars.html' with rating=status.rating %}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="block">
|
|
||||||
{% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endwith %}
|
<a href="{{ book.local_path }}">{{ book.title }}</a>
|
||||||
|
</h3>
|
||||||
|
{% if status.rating %}
|
||||||
|
<p class="subtitle is-6">
|
||||||
|
{% include 'snippets/stars.html' with rating=status.rating %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="block">
|
||||||
|
<a href="{{ status.remote_id }}">
|
||||||
|
<span>{% trans "View status" %}</span>
|
||||||
|
<span class="icon icon-arrow-right" aria-hidden="true"></span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="block">
|
||||||
|
{% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -62,3 +62,9 @@ def get_published_date(date):
|
||||||
if delta.days:
|
if delta.days:
|
||||||
return naturalday(date, "M j")
|
return naturalday(date, "M j")
|
||||||
return naturaltime(date)
|
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()
|
||||||
|
|
|
@ -6,8 +6,7 @@ from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import activitystreams
|
||||||
from .helpers import privacy_filter
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable= no-self-use
|
# pylint: disable= no-self-use
|
||||||
|
@ -17,21 +16,28 @@ class Discover(View):
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""tiled book activity page"""
|
"""tiled book activity page"""
|
||||||
activities = privacy_filter(
|
activities = (
|
||||||
request.user,
|
activitystreams.streams["local"]
|
||||||
models.Status.objects.select_subclasses().filter(
|
.get_activity_stream(request.user)
|
||||||
|
.filter(
|
||||||
Q(comment__isnull=False)
|
Q(comment__isnull=False)
|
||||||
| Q(review__isnull=False)
|
| Q(review__isnull=False)
|
||||||
| Q(quotation__isnull=False),
|
| Q(quotation__isnull=False)
|
||||||
user__local=True,
|
| Q(mention_books__isnull=False)
|
||||||
),
|
)
|
||||||
privacy_levels=["public"],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
large_activities = Paginator(
|
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(
|
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")
|
page = request.GET.get("page")
|
||||||
|
|
Loading…
Reference in a new issue