forked from mirrors/bookwyrm
Adds filtering
This commit is contained in:
parent
c4901b9c4e
commit
53af667698
2 changed files with 59 additions and 24 deletions
|
@ -40,36 +40,48 @@
|
|||
</span>
|
||||
</h2>
|
||||
|
||||
<div class="hidden mt-3" id="filters">
|
||||
<form class="hidden mt-3" id="filters" method-"get" action="{% url 'directory' %}">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<legend class="label">User type</legend>
|
||||
<div class="box">
|
||||
<label class="label"><input type="radio" class="radio"> {% trans "BookWyrm instances" %}</label>
|
||||
<label class="label"><input type="radio" class="radio"> {% trans "All services" %}</label>
|
||||
<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">
|
||||
<legend class="label">Community</legend>
|
||||
<div class="box">
|
||||
<label class="label"><input type="radio" class="radio"> Local users</label>
|
||||
<label class="label"><input type="radio" class="radio"> Federated community</label>
|
||||
<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">
|
||||
<legend class="label">Order by</legend>
|
||||
<div class="box">
|
||||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
<legend class="label">{% trans "Order by" %}</legend>
|
||||
<div class="select">
|
||||
<select>
|
||||
<option checked>Suggested</option>
|
||||
<option>Recently active</option>
|
||||
<select name="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>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="columns is-multiline">
|
||||
|
@ -97,12 +109,14 @@
|
|||
</div>
|
||||
</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>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
""" 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
|
||||
|
@ -20,11 +21,31 @@ 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 = {
|
||||
|
|
Loading…
Reference in a new issue