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 %}
<header class="block">
<h1 class="title has-text-centered">{% trans "Discover" %}</h1>
</header>
<section class="block">
<header class="block content has-text-centered">
<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-vertical">
<div class="tile is-parent">
<div class="tile is-ancestor">
<div class="tile is-6 is-parent">
<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 class="tile">
<div class="tile is-parent is-6">
<div class="tile is-6 is-parent">
<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">
{% include 'discover/small-book.html' with status=small.0 %}
{% include 'discover/large-book.html' with status=large_activities.2 %}
</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">
{% include 'discover/small-book.html' with status=small.1 %}
{% include 'discover/large-book.html' with status=large_activities.3 %}
</div>
</div>
</div>
</div>
<div class="tile is-vertical">
<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.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.3 %}
</div>
<div class="tile is-ancestor">
<div class="tile is-6 is-parent">
<div class="tile is-child box has-background-white-ter">
{% include 'discover/large-book.html' with status=large_activities.4 %}
</div>
</div>
<div class="tile is-parent">
<div class="tile is-6 is-parent">
<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>
</section>
<div class="block">
{% include 'snippets/pagination.html' with page=large_activities %}
</div>
{% endblock %}

View file

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

View file

@ -5,23 +5,14 @@
{% if status %}
{% with book=status.book %}
<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>
{% 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">
<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">
<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" %}
@ -29,13 +20,35 @@
</figure>
<div class="media-content">
<h3 class="has-text-weight-bold">
<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>
{% endif %}
</div>
</div>
<div class="block">
{% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %}
</div>
{% endwith %}
{% 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 }}">
{% csrf_token %}
<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 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 %}
<input type="hidden" name="user" value="{{ user.username }}">
{% 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 %}
<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 %}
</form>
</div>

View file

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