Directory view

This commit is contained in:
Mouse Reeve 2021-03-21 16:37:52 -07:00
parent 3e75253ff1
commit ba00672e66
9 changed files with 115 additions and 6 deletions

View file

@ -3,7 +3,6 @@ import datetime
from collections import defaultdict from collections import defaultdict
from django import forms from django import forms
from django.core.exceptions import ValidationError
from django.forms import ModelForm, PasswordInput, widgets from django.forms import ModelForm, PasswordInput, widgets
from django.forms.widgets import Textarea from django.forms.widgets import Textarea
from django.utils import timezone from django.utils import timezone
@ -130,8 +129,9 @@ class EditUserForm(CustomForm):
"name", "name",
"email", "email",
"summary", "summary",
"manually_approves_followers",
"show_goal", "show_goal",
"manually_approves_followers",
"discoverable",
] ]
help_texts = {f: None for f in fields} help_texts = {f: None for f in fields}

View file

@ -0,0 +1,67 @@
{% extends 'layout.html' %}
{% load i18n %}
{% load bookwyrm_tags %}
{% load humanize %}
{% block title %}{% trans "Directory" %}{% endblock %}
{% block content %}
<header class="block">
<h1 class="title">
{% trans "Directory" %}
</h1>
</header>
<div class="columns is-multiline">
{% for user in users %}
<div class="column is-one-third">
<div class="card block">
<div class="card-content">
<div class="media">
<span class="media-left">
{% include 'snippets/avatar.html' with user=user large=True %}
</span>
<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>
</a>
{% include 'snippets/follow_button.html' with user=user %}
</div>
</div>
{% if user.summary %}
<div class="content">
{{ user.summary | to_markdown | safe | truncatechars_html:40 }}
</div>
{% endif %}
</div>
<footer class="card-footer content">
<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>
</div>
</div>
<div class="card-footer-item">
<div class="has-text-centered">
<p class="title is-6 mb-0">{{ user.status_set.count|intword }}</p>
<p class="help">{% trans "posts" %}</p>
</div>
</div>
<div class="card-footer-item">
<div class="has-text-centered">
<p class="title is-6 mb-0">{{ user.last_active_date|naturalday }}</p>
<p class="help">{% trans "last active" %}</p>
</div>
</div>
</footer>
</div>
</div>
{% endfor %}
</div>
<div>
{% include 'snippets/pagination.html' with page=users path="/directory" %}
</div>
{% endblock %}

View file

@ -2,11 +2,11 @@
{% load i18n %} {% load i18n %}
{% load humanize %} {% load humanize %}
{% block title %}{% trans "Edit Author" %}: {{ author.name }}{% endblock %} {% block title %}{% trans "Edit Author:" %} {{ author.name }}{% endblock %}
{% block content %} {% block content %}
<header class="block"> <header class="block">
<h1 class="title level-left"> <h1 class="title">
Edit "{{ author.name }}" Edit "{{ author.name }}"
</h1> </h1>
<div> <div>

View file

@ -53,6 +53,14 @@
{{ form.manually_approves_followers }} {{ form.manually_approves_followers }}
</label> </label>
</div> </div>
<div class="block">
<label class="checkbox label" for="id_discoverable">
{% trans "Show this account in suggested users:" %}
{{ form.discoverable }}
</label>
{% url 'directory' as path %}
<p class="help">{% blocktrans %}Your account will show up in the <a href="{{ path }}">directory</a>, and may be recommended to other BookWyrm users.{% endblocktrans %}</p>
</div>
<button class="button is-primary" type="submit">{% trans "Save" %}</button> <button class="button is-primary" type="submit">{% trans "Save" %}</button>
</form> </form>
{% endblock %} {% endblock %}

View file

@ -1,3 +1,3 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
<img class="avatar image {% if large %}is-96x96{% else %}is-32x32{% endif %}" src="{% if user.avatar %}/images/{{ user.avatar }}{% else %}/static/images/default_avi.jpg{% endif %}" {% if ariaHide %}aria-hidden="true"{% endif %} alt="{{ user.alt_text }}"> <img class="avatar image {% if large %}is-96x96{% elif medium %}is-48x48{% else %}is-32x32{% endif %}" src="{% if user.avatar %}/images/{{ user.avatar }}{% else %}/static/images/default_avi.jpg{% endif %}" {% if ariaHide %}aria-hidden="true"{% endif %} alt="{{ user.alt_text }}">

View file

@ -96,6 +96,7 @@ urlpatterns = [
path("", views.Home.as_view(), name="landing"), path("", views.Home.as_view(), name="landing"),
re_path(r"^discover/?$", views.Discover.as_view()), re_path(r"^discover/?$", views.Discover.as_view()),
re_path(r"^notifications/?$", views.Notifications.as_view()), re_path(r"^notifications/?$", views.Notifications.as_view()),
re_path(r"^directory/?", views.Directory.as_view(), name="directory"),
# feeds # feeds
re_path(r"^(?P<tab>home|local|federated)/?$", views.Feed.as_view()), re_path(r"^(?P<tab>home|local|federated)/?$", views.Feed.as_view()),
re_path( re_path(

View file

@ -4,6 +4,7 @@ from .author import Author, EditAuthor
from .block import Block, unblock from .block import Block, unblock
from .books import Book, EditBook, ConfirmEditBook, Editions from .books import Book, EditBook, ConfirmEditBook, Editions
from .books import upload_cover, add_description, switch_edition, resolve_book from .books import upload_cover, add_description, switch_edition, resolve_book
from .directory import Directory
from .error import not_found_page, server_error_page from .error import not_found_page, server_error_page
from .federation import Federation from .federation import Federation
from .feed import DirectMessage, Feed, Replies, Status from .feed import DirectMessage, Feed, Replies, Status

View file

@ -0,0 +1,32 @@
""" who all's here? """
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.template.response import TemplateResponse
from django.views import View
from django.utils.decorators import method_decorator
from bookwyrm import models
# pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch")
class Directory(View):
""" display of known bookwyrm users """
def get(self, request):
""" lets see your cute faces """
try:
page = int(request.GET.get("page", 1))
except ValueError:
page = 1
users = models.User.objects.filter(
discoverable=True,
bookwyrm_user=True,
is_active=True,
).order_by('-last_active_date')
paginated = Paginator(users, 12)
data = {
"users": paginated.page(page),
}
return TemplateResponse(request, "directory.html", data)

View file

@ -2,7 +2,7 @@
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.views import View from django.views import View
from bookwyrm import forms, models from bookwyrm import forms
from .feed import Feed from .feed import Feed
from . import helpers from . import helpers