From 16994908d88e8e2daf8175078da6ff2d0609ff0d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 21 Mar 2021 12:53:30 -0700 Subject: [PATCH 1/7] Lets users opt in to directory --- bookwyrm/migrations/0057_user_discoverable.py | 19 +++++++++++++++++++ bookwyrm/models/user.py | 1 + 2 files changed, 20 insertions(+) create mode 100644 bookwyrm/migrations/0057_user_discoverable.py diff --git a/bookwyrm/migrations/0057_user_discoverable.py b/bookwyrm/migrations/0057_user_discoverable.py new file mode 100644 index 00000000..522f0869 --- /dev/null +++ b/bookwyrm/migrations/0057_user_discoverable.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.6 on 2021-03-21 21:44 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0056_auto_20210321_0303'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='discoverable', + field=bookwyrm.models.fields.BooleanField(default=False), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 46f08509..84391e10 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -103,6 +103,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): last_active_date = models.DateTimeField(auto_now=True) manually_approves_followers = fields.BooleanField(default=False) show_goal = models.BooleanField(default=True) + show_in_directory = models.BooleanField(default=False) name_field = "username" From 3e75253ff179842dc4942f5acb21e49e6d09dd59 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 21 Mar 2021 14:50:36 -0700 Subject: [PATCH 2/7] Updates activitpub and tests for discoverability --- bookwyrm/activitypub/person.py | 2 +- bookwyrm/models/user.py | 2 +- bookwyrm/templates/layout.html | 2 +- bookwyrm/tests/data/ap_user.json | 3 +++ bookwyrm/tests/views/test_inbox.py | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bookwyrm/activitypub/person.py b/bookwyrm/activitypub/person.py index f1298b92..dafd1910 100644 --- a/bookwyrm/activitypub/person.py +++ b/bookwyrm/activitypub/person.py @@ -30,5 +30,5 @@ class Person(ActivityObject): icon: Image = field(default_factory=lambda: {}) bookwyrmUser: bool = False manuallyApprovesFollowers: str = False - discoverable: str = True + discoverable: str = False type: str = "Person" diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 84391e10..c2a74c63 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -103,7 +103,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): last_active_date = models.DateTimeField(auto_now=True) manually_approves_followers = fields.BooleanField(default=False) show_goal = models.BooleanField(default=True) - show_in_directory = models.BooleanField(default=False) + discoverable = fields.BooleanField(default=False) name_field = "username" diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index c7d10b57..b25bef45 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -107,7 +107,7 @@ {% endif %} {% if perms.bookwyrm.create_invites %}
  • - + {% trans 'Invites' %}
  • diff --git a/bookwyrm/tests/data/ap_user.json b/bookwyrm/tests/data/ap_user.json index b159ae65..bc4488e3 100644 --- a/bookwyrm/tests/data/ap_user.json +++ b/bookwyrm/tests/data/ap_user.json @@ -28,6 +28,9 @@ }, "bookwyrmUser": true, "manuallyApprovesFollowers": false, + "discoverable": true, + "devices": "https://friend.camp/users/tripofmice/collections/devices", + "tag": [], "icon": { "type": "Image", "mediaType": "image/png", diff --git a/bookwyrm/tests/views/test_inbox.py b/bookwyrm/tests/views/test_inbox.py index b681b961..10f55f89 100644 --- a/bookwyrm/tests/views/test_inbox.py +++ b/bookwyrm/tests/views/test_inbox.py @@ -789,6 +789,7 @@ class Inbox(TestCase): self.assertEqual(user.name, "MOUSE?? MOUSE!!") self.assertEqual(user.username, "mouse@example.com") self.assertEqual(user.localname, "mouse") + self.assertTrue(user.discoverable) def test_handle_update_edition(self): """ update an existing edition """ From ba00672e66b19987c83897625f8fadd438422955 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 21 Mar 2021 16:37:52 -0700 Subject: [PATCH 3/7] Directory view --- bookwyrm/forms.py | 4 +- bookwyrm/templates/directory.html | 67 +++++++++++++++++++ bookwyrm/templates/edit_author.html | 4 +- bookwyrm/templates/preferences/edit_user.html | 8 +++ bookwyrm/templates/snippets/avatar.html | 2 +- bookwyrm/urls.py | 1 + bookwyrm/views/__init__.py | 1 + bookwyrm/views/directory.py | 32 +++++++++ bookwyrm/views/landing.py | 2 +- 9 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 bookwyrm/templates/directory.html create mode 100644 bookwyrm/views/directory.py diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index d330211c..4e92b32e 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -3,7 +3,6 @@ import datetime from collections import defaultdict from django import forms -from django.core.exceptions import ValidationError from django.forms import ModelForm, PasswordInput, widgets from django.forms.widgets import Textarea from django.utils import timezone @@ -130,8 +129,9 @@ class EditUserForm(CustomForm): "name", "email", "summary", - "manually_approves_followers", "show_goal", + "manually_approves_followers", + "discoverable", ] help_texts = {f: None for f in fields} diff --git a/bookwyrm/templates/directory.html b/bookwyrm/templates/directory.html new file mode 100644 index 00000000..9323752f --- /dev/null +++ b/bookwyrm/templates/directory.html @@ -0,0 +1,67 @@ +{% extends 'layout.html' %} +{% load i18n %} +{% load bookwyrm_tags %} +{% load humanize %} + +{% block title %}{% trans "Directory" %}{% endblock %} + +{% block content %} +
    +

    + {% trans "Directory" %} +

    +
    +
    + {% for user in users %} +
    +
    +
    +
    + + {% include 'snippets/avatar.html' with user=user large=True %} + +
    + + {{ user.display_name }} + @{{ user|username }} + + {% include 'snippets/follow_button.html' with user=user %} +
    +
    + + {% if user.summary %} +
    + {{ user.summary | to_markdown | safe | truncatechars_html:40 }} +
    + {% endif %} +
    +
    + + + +
    +
    +
    + {% endfor %} +
    + +
    + {% include 'snippets/pagination.html' with page=users path="/directory" %} +
    + +{% endblock %} diff --git a/bookwyrm/templates/edit_author.html b/bookwyrm/templates/edit_author.html index 0316a66f..542b57f9 100644 --- a/bookwyrm/templates/edit_author.html +++ b/bookwyrm/templates/edit_author.html @@ -2,11 +2,11 @@ {% load i18n %} {% load humanize %} -{% block title %}{% trans "Edit Author" %}: {{ author.name }}{% endblock %} +{% block title %}{% trans "Edit Author:" %} {{ author.name }}{% endblock %} {% block content %}
    -

    +

    Edit "{{ author.name }}"

    diff --git a/bookwyrm/templates/preferences/edit_user.html b/bookwyrm/templates/preferences/edit_user.html index ca0f81c2..327d745b 100644 --- a/bookwyrm/templates/preferences/edit_user.html +++ b/bookwyrm/templates/preferences/edit_user.html @@ -53,6 +53,14 @@ {{ form.manually_approves_followers }}
    +
    + + {% url 'directory' as path %} +

    {% blocktrans %}Your account will show up in the directory, and may be recommended to other BookWyrm users.{% endblocktrans %}

    +
    {% endblock %} diff --git a/bookwyrm/templates/snippets/avatar.html b/bookwyrm/templates/snippets/avatar.html index 6d27cd85..d53acf2b 100644 --- a/bookwyrm/templates/snippets/avatar.html +++ b/bookwyrm/templates/snippets/avatar.html @@ -1,3 +1,3 @@ {% load bookwyrm_tags %} -{{ user.alt_text }} +{{ user.alt_text }} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 4aced6fe..76622799 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -96,6 +96,7 @@ urlpatterns = [ path("", views.Home.as_view(), name="landing"), re_path(r"^discover/?$", views.Discover.as_view()), re_path(r"^notifications/?$", views.Notifications.as_view()), + re_path(r"^directory/?", views.Directory.as_view(), name="directory"), # feeds re_path(r"^(?Phome|local|federated)/?$", views.Feed.as_view()), re_path( diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 3402e65f..f1ebfc4c 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -4,6 +4,7 @@ from .author import Author, EditAuthor from .block import Block, unblock from .books import Book, EditBook, ConfirmEditBook, Editions 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 .federation import Federation from .feed import DirectMessage, Feed, Replies, Status diff --git a/bookwyrm/views/directory.py b/bookwyrm/views/directory.py new file mode 100644 index 00000000..bbfbffe8 --- /dev/null +++ b/bookwyrm/views/directory.py @@ -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) diff --git a/bookwyrm/views/landing.py b/bookwyrm/views/landing.py index 86f7d3e9..407451fb 100644 --- a/bookwyrm/views/landing.py +++ b/bookwyrm/views/landing.py @@ -2,7 +2,7 @@ from django.template.response import TemplateResponse from django.views import View -from bookwyrm import forms, models +from bookwyrm import forms from .feed import Feed from . import helpers From 6e3a203b466d24ef02518b1f6aa442801e308364 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 21 Mar 2021 16:43:13 -0700 Subject: [PATCH 4/7] Adds directory to main menu --- bookwyrm/templates/layout.html | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index b25bef45..e57f6152 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -83,18 +83,18 @@