Local discovery view

This commit is contained in:
Mouse Reeve 2021-08-07 14:38:19 -07:00
parent b5153f3df1
commit e3cbf30684
5 changed files with 166 additions and 68 deletions

View file

@ -5,50 +5,85 @@
{% block content %} {% block content %}
<header class="block"> <section class="block">
<h1 class="title has-text-centered">{% trans "Discover" %}</h1> <header class="block content has-text-centered">
</header> <h1 class="title">{% trans "Discover" %}</h1>
<p class="subtitle">
{% blocktrans trimmed with site_name=site.name %}
See what's new in the local {{ site_name }} community
{% endblocktrans %}
</p>
</header>
<section class="tile is-ancestor"> <div class="tile is-ancestor">
<div class="tile is-vertical"> <div class="tile is-6 is-parent">
<div class="tile is-parent">
<div class="tile is-child box has-background-white-ter"> <div class="tile is-child box has-background-white-ter">
{% include 'discover/large-book.html' with status=large.0 %} {% include 'discover/large-book.html' with status=large_activities.0 %}
</div> </div>
</div> </div>
<div class="tile"> <div class="tile is-6 is-parent">
<div class="tile is-parent is-6"> <div class="tile is-child box has-background-white-ter">
{% include 'discover/large-book.html' with status=large_activities.1 %}
</div>
</div>
</div>
<div class="tile is-ancestor">
<div class="tile is-vertical is-6">
<div class="tile is-parent">
<div class="tile is-child box has-background-white-ter"> <div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small.0 %} {% include 'discover/large-book.html' with status=large_activities.2 %}
</div> </div>
</div> </div>
<div class="tile is-parent is-6"> <div class="tile">
<div class="tile is-parent is-6">
<div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small_activities.0 %}
</div>
</div>
<div class="tile is-parent is-6">
<div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small_activities.1 %}
</div>
</div>
</div>
</div>
<div class="tile is-vertical is-6">
<div class="tile">
<div class="tile is-parent is-6">
<div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small_activities.2 %}
</div>
</div>
<div class="tile is-parent is-6">
<div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small_activities.3 %}
</div>
</div>
</div>
<div class="tile is-parent">
<div class="tile is-child box has-background-white-ter"> <div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small.1 %} {% include 'discover/large-book.html' with status=large_activities.3 %}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="tile is-vertical">
<div class="tile"> <div class="tile is-ancestor">
<div class="tile is-parent is-6"> <div class="tile is-6 is-parent">
<div class="tile is-child box has-background-white-ter"> <div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small.2 %} {% include 'discover/large-book.html' with status=large_activities.4 %}
</div>
</div>
<div class="tile is-parent is-6">
<div class="tile is-child box has-background-white-ter">
{% include 'discover/small-book.html' with status=small.3 %}
</div>
</div> </div>
</div> </div>
<div class="tile is-parent"> <div class="tile is-6 is-parent">
<div class="tile is-child box has-background-white-ter"> <div class="tile is-child box has-background-white-ter">
{% include 'discover/large-book.html' with status=large.1 %} {% include 'discover/large-book.html' with status=large_activities.5 %}
</div> </div>
</div> </div>
</div> </div>
</section> </section>
<div class="block">
{% include 'snippets/pagination.html' with page=large_activities %}
</div>
{% endblock %} {% endblock %}

View file

@ -1,37 +1,67 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load markdown %}
{% load i18n %} {% load i18n %}
{% if book %} {% if status %}
{% with book=book %} {% with book=status.book %}
<div class="columns is-gapless"> <div class="columns is-gapless">
<div class="column is-5-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 %}
</div> <h3 class="title is-6">
<div class="column mt-3-mobile ml-3-tablet">
<h3 class="title is-5">
<a href="{{ book.local_path }}">{{ book.title }}</a> <a href="{{ book.local_path }}">{{ book.title }}</a>
</h3> </h3>
{% if book.authors %} {% if book.authors %}
<p class="subtitle is-5"> <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 %}
{% if book|book_description %} {% include 'snippets/shelve_button/shelve_button.html' %}
<blockquote class="content"> </div>
{{ book|book_description|to_markdown|safe|truncatewords_html:50 }}
</blockquote> <div class="column mt-3-mobile ml-3-tablet">
{% endif %} <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">
{% include "snippets/status/content_status.html" with hide_book=True %}
</div>
</div> </div>
</div> </div>
{% endwith %} {% endwith %}

View file

@ -5,23 +5,14 @@
{% if status %} {% if status %}
{% with book=status.book %} {% with book=status.book %}
<a href="{{ book.local_path }}"> <a href="{{ book.local_path }}">
{% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-h-l-tablet 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>
{% include 'snippets/stars.html' with rating=book|rating:request.user %} <div class="block mt-2">
{% include 'snippets/shelve_button/shelve_button.html' %}
</div>
<h3 class="title is-6"> <div class="media block mb-2">
<a href="{{ book.local_path }}">{{ book.title }}</a>
</h3>
{% if book.authors %}
<p class="subtitle is-6">
{% trans "by" %}
{% include 'snippets/authors.html' with limit=3 %}
</p>
{% endif %}
<div class="media">
<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" %}
@ -29,13 +20,35 @@
</figure> </figure>
<div class="media-content"> <div class="media-content">
<h3 class="has-text-weight-bold"> <h3 class="title is-6">
<a href="{{ status.user.local_path }}"> <a href="{{ status.user.local_path }}">
<span>{{ status.user.display_name }}</span> <span>{{ status.user.display_name }}</span>
</a> </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> </h3>
{% if status.rating %}
<p class="subtitle is-6">
{% include 'snippets/stars.html' with rating=status.rating %}
</p>
{% endif %}
</div> </div>
</div> </div>
<div class="block">
{% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %}
</div>
{% endwith %} {% endwith %}
{% endif %} {% endif %}

View file

@ -9,15 +9,29 @@
<form action="{% url 'follow' %}" method="POST" class="interaction follow-{{ user.id }} {% if request.user in user.followers.all or request.user in user.follower_requests.all %}is-hidden{%endif %}" data-id="follow-{{ user.id }}"> <form action="{% url 'follow' %}" method="POST" class="interaction follow-{{ user.id }} {% if request.user in user.followers.all or request.user in user.follower_requests.all %}is-hidden{%endif %}" data-id="follow-{{ user.id }}">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ user.username }}"> <input type="hidden" name="user" value="{{ user.username }}">
<button class="button is-small{% if not minimal %} is-link{% endif %}" type="submit">{% trans "Follow" %}</button> <button class="button is-small{% if not minimal %} is-link{% endif %}" type="submit">
{% if show_username %}
{% blocktrans with username=user.localname %}Follow @{{ username }}{% endblocktrans %}
{% else %}
{% trans "Follow" %}
{% endif %}
</button>
</form> </form>
<form action="{% url 'unfollow' %}" method="POST" class="interaction follow-{{ user.id }} {% if not request.user in user.followers.all and not request.user in user.follower_requests.all %}is-hidden{%endif %}" data-id="follow-{{ user.id }}"> <form action="{% url 'unfollow' %}" method="POST" class="interaction follow-{{ user.id }} {% if not request.user in user.followers.all and not request.user in user.follower_requests.all %}is-hidden{%endif %}" data-id="follow-{{ user.id }}">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ user.username }}"> <input type="hidden" name="user" value="{{ user.username }}">
{% if user.manually_approves_followers and request.user not in user.followers.all %} {% if user.manually_approves_followers and request.user not in user.followers.all %}
<button class="button is-small is-danger is-light" type="submit">{% trans "Undo follow request" %}</button> <button class="button is-small is-danger is-light" type="submit">
{% trans "Undo follow request" %}
</button>
{% else %} {% else %}
<button class="button is-small is-danger is-light" type="submit">{% trans "Unfollow" %}</button> <button class="button is-small is-danger is-light" type="submit">
{% if show_username %}
{% blocktrans with username=user.localname %}Unfollow @{{ username }}{% endblocktrans %}
{% else %}
{% trans "Unfollow" %}
{% endif %}
</button>
{% endif %} {% endif %}
</form> </form>
</div> </div>

View file

@ -7,7 +7,6 @@ from django.utils.decorators import method_decorator
from django.views import View from django.views import View
from bookwyrm import models from bookwyrm import models
from bookwyrm.settings import PAGE_LENGTH
from .helpers import privacy_filter from .helpers import privacy_filter
@ -24,13 +23,20 @@ class Discover(View):
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 user__local=True,
), ),
#privacy_levels=["public"] privacy_levels=["public"],
) )
#paginated = Paginator(activities, PAGE_LENGTH) large_activities = Paginator(
activities.filter(~Q(content=None), ~Q(content="")), 6
)
small_activities = Paginator(
activities.filter(Q(content=None) | Q(content="")), 4
)
page = request.GET.get("page")
data = { data = {
"large": activities.filter(~Q(review__isnull=True, review__content=None))[:2], "large_activities": large_activities.get_page(page),
"small": activities.filter(~Q(content=None))[:4], "small_activities": small_activities.get_page(page),
} }
return TemplateResponse(request, "discover/discover.html", data) return TemplateResponse(request, "discover/discover.html", data)