mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-15 04:36:34 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
e01581c28d
2 changed files with 127 additions and 9 deletions
|
@ -11,6 +11,90 @@
|
|||
{% trans "Directory" %}
|
||||
</h1>
|
||||
</header>
|
||||
|
||||
{% if not request.user.discoverable %}
|
||||
<div class="box has-text-centered content" data-hide="hide-join-directory"><div class="columns">
|
||||
<div class="column">
|
||||
<p>
|
||||
{% trans "Make your profile discoverable to other BookWyrm users." %}
|
||||
</p>
|
||||
<form name="directory" method="POST" action="{% url 'directory' %}">
|
||||
{% csrf_token %}
|
||||
<button class="button is-primary" type="submit">Join Directory</button>
|
||||
<p class="help">
|
||||
{% url 'settings-profile' as path %}
|
||||
{% blocktrans %}You can opt-out at any time in your <a href="{{ path }}">profile settings.</a>{% endblocktrans %}
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
{% trans "Dismiss message" as button_text %}
|
||||
<button type="button" class="delete set-display" data-id="hide-join-directory" data-value="true">
|
||||
<span>Dismiss message</span>
|
||||
</button>
|
||||
</div>
|
||||
</div></div>
|
||||
{% endif %}
|
||||
|
||||
<div class="notification content">
|
||||
<h2 class="columns is-mobile mb-0">
|
||||
<span class="column pb-0">Filters</span>
|
||||
|
||||
<span class="column is-narrow pb-0">
|
||||
{% trans "Show filters" as text %}
|
||||
{% include 'snippets/toggle/open_button.html' with text=text controls_text="filters" icon="arrow-down" class="is-small" focus="filters" %}
|
||||
{% trans "Hide filters" as text %}
|
||||
{% include 'snippets/toggle/close_button.html' with text=text controls_text="filters" icon="x" class="is-small" %}
|
||||
</span>
|
||||
</h2>
|
||||
|
||||
<form class="hidden mt-3" id="filters" method-"get" action="{% url 'directory' %}" tabindex="0">
|
||||
<div class="columns">
|
||||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
<legend class="label">{% trans "User type" %}</legend>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="software" value="bookwyrm" {% if not request.GET.sort or request.GET.software == 'bookwyrm' %}checked{% endif %}>
|
||||
{% trans "BookWyrm users" %}
|
||||
</label>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="software" value="all" {% if request.GET.software == 'all' %}checked{% endif %}>
|
||||
{% trans "All known users" %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
<legend class="label">{% trans "Community" %}</legend>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="scope" value="local" {% if request.GET.scope == "local" %}checked{% endif %}>
|
||||
{% trans "Local users" %}
|
||||
</label>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="scope" value="federated" {% if not request.GET.sort or request.GET.scope == "federated" %}checked{% endif %}>
|
||||
{% trans "Federated community" %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
<label class="label" for="id_sort">{% trans "Order by" %}</label>
|
||||
<div class="select">
|
||||
<select name="sort" id="id_sort">
|
||||
<option value="suggested" {% if not request.GET.sort or request.GET.sort == "suggested" %}checked{% endif %}>{% trans "Suggested" %}</option>
|
||||
<option value="recent" {% if request.GET.sort == "suggested" %}checked{% endif %}>{% trans "Recently active" %}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="button is-primary">{% trans "Apply filters" %}</button>
|
||||
</form>
|
||||
{% if request.GET %}
|
||||
<a class="help" href="{% url 'directory' %}">{% trans "Clear filters" %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="columns is-multiline">
|
||||
{% for user in users %}
|
||||
<div class="column is-one-third">
|
||||
|
@ -23,25 +107,27 @@
|
|||
<div class="media-content">
|
||||
<a href="{{ user.local_path }}" class="is-block mb-2">
|
||||
<span class="title is-4 is-block">{{ user.display_name }}</span>
|
||||
<span class="subtitle is-6 is-block">@{{ user|username }}</span>
|
||||
<span class="subtitle is-7 is-block">@{{ user|username }}</span>
|
||||
</a>
|
||||
{% include 'snippets/follow_button.html' with user=user %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if user.summary %}
|
||||
<div class="content">
|
||||
{% if user.summary %}
|
||||
{{ user.summary | to_markdown | safe | truncatechars_html:40 }}
|
||||
{% else %} {% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<footer class="card-footer content">
|
||||
{% if user != request.user %}
|
||||
<div class="card-footer-item">
|
||||
<div class="has-text-centered">
|
||||
<p class="title is-6 mb-0">{{ user.shelfbook_set.count }}</p>
|
||||
<p class="help">{% trans "books shelved" %}</p>
|
||||
<p class="title is-6 mb-0">{{ user.mutuals }}</p>
|
||||
<p class="help">{% trans "followers you follow" %}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="card-footer-item">
|
||||
<div class="has-text-centered">
|
||||
<p class="title is-6 mb-0">{{ user.status_set.count|intword }}</p>
|
||||
|
@ -65,3 +151,7 @@
|
|||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="/static/js/localstorage.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
""" who all's here? """
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Count, Q
|
||||
from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.views import View
|
||||
from django.utils.decorators import method_decorator
|
||||
|
@ -19,14 +21,40 @@ class Directory(View):
|
|||
except ValueError:
|
||||
page = 1
|
||||
|
||||
# filters
|
||||
filters = {}
|
||||
software = request.GET.get("software")
|
||||
if software == "bookwyrm":
|
||||
filters["bookwyrm_user"] = True
|
||||
scope = request.GET.get("scope")
|
||||
if scope == "local":
|
||||
filters["local"] = True
|
||||
|
||||
users = models.User.objects.filter(
|
||||
discoverable=True,
|
||||
bookwyrm_user=True,
|
||||
is_active=True,
|
||||
).order_by("-last_active_date")
|
||||
discoverable=True, is_active=True, **filters
|
||||
).annotate(
|
||||
mutuals=Count(
|
||||
"following",
|
||||
filter=Q(
|
||||
~Q(id=request.user.id), following__in=request.user.following.all()
|
||||
),
|
||||
)
|
||||
)
|
||||
sort = request.GET.get("sort")
|
||||
if sort == "recent":
|
||||
users = users.order_by("-last_active_date")
|
||||
else:
|
||||
users = users.order_by("-mutuals", "-last_active_date")
|
||||
|
||||
paginated = Paginator(users, 12)
|
||||
|
||||
data = {
|
||||
"users": paginated.page(page),
|
||||
}
|
||||
return TemplateResponse(request, "directory.html", data)
|
||||
|
||||
def post(self, request):
|
||||
""" join the directory """
|
||||
request.user.discoverable = True
|
||||
request.user.save()
|
||||
return redirect("directory")
|
||||
|
|
Loading…
Reference in a new issue