forked from mirrors/bookwyrm
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 (
|
||||
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")
|
||||
)
|
||||
|
|
|
@ -1,73 +1,73 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
{% load status_display %}
|
||||
|
||||
{% if status %}
|
||||
{% with book=status.book %}
|
||||
<div class="columns is-gapless">
|
||||
<div class="column is-6-tablet is-cover">
|
||||
<a
|
||||
class="align to-b to-l"
|
||||
href="{{ book.local_path }}"
|
||||
>{% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto-tablet' %}</a>
|
||||
{% if status.book or status.mention_books.exists %}
|
||||
{% load_book status as book %}
|
||||
<div class="columns is-gapless">
|
||||
<div class="column is-6-tablet is-cover">
|
||||
<a
|
||||
class="align to-b to-l"
|
||||
href="{{ book.local_path }}"
|
||||
>{% 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 %}
|
||||
<h3 class="title is-6">
|
||||
<a href="{{ book.local_path }}">{{ book.title }}</a>
|
||||
</h3>
|
||||
{% include 'snippets/stars.html' with rating=book|rating:request.user %}
|
||||
<h3 class="title is-6">
|
||||
<a href="{{ book.local_path }}">{{ book|book_title }}</a>
|
||||
</h3>
|
||||
|
||||
{% if book.authors %}
|
||||
<p class="subtitle is-6 mb-2">
|
||||
{% trans "by" %}
|
||||
{% include 'snippets/authors.html' with limit=3 %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if book.authors %}
|
||||
<p class="subtitle is-6 mb-2">
|
||||
{% trans "by" %}
|
||||
{% include 'snippets/authors.html' with limit=3 %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% 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>
|
||||
{% include 'snippets/shelve_button/shelve_button.html' %}
|
||||
</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 %}
|
||||
|
|
|
@ -1,54 +1,59 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% load i18n %}
|
||||
{% load status_display %}
|
||||
|
||||
{% if status %}
|
||||
{% with book=status.book %}
|
||||
<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' %}
|
||||
</a>
|
||||
{% if status.book or status.mention_books.exists %}
|
||||
{% load_book status as book %}
|
||||
<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' %}
|
||||
</a>
|
||||
|
||||
<div class="block mt-2">
|
||||
{% include 'snippets/shelve_button/shelve_button.html' %}
|
||||
</div>
|
||||
<div class="block mt-2">
|
||||
{% include 'snippets/shelve_button/shelve_button.html' %}
|
||||
</div>
|
||||
|
||||
<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" %}
|
||||
<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>
|
||||
</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>
|
||||
{% if status.rating %}
|
||||
<p class="subtitle is-6">
|
||||
{% include 'snippets/stars.html' with rating=status.rating %}
|
||||
</p>
|
||||
{% 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 %}
|
||||
</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 %}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue