From 8ea60c66a3a0c13830ab59fbd6802a7a0308acc9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 17:02:45 -0700 Subject: [PATCH 1/4] Create connectors to federated bookwyrm servers This got messed up when I refactored how connectors work! Poor bookwyrm.social doesn't have a wyrms.de connector, but this will fix that. --- bookwyrm/connectors/connector_manager.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bookwyrm/connectors/connector_manager.py b/bookwyrm/connectors/connector_manager.py index 853609de4..caf6bcbe2 100644 --- a/bookwyrm/connectors/connector_manager.py +++ b/bookwyrm/connectors/connector_manager.py @@ -3,6 +3,9 @@ import importlib import re from urllib.parse import urlparse +from django.dispatch import receiver +from django.db.models import signals + from requests import HTTPError from bookwyrm import models @@ -44,6 +47,7 @@ def search(query, min_confidence=0.1): except (HTTPError, ConnectorException): continue + # if the search results look the same, ignore them result_set = [r for r in result_set if dedup_slug(r) not in result_index] # `|=` concats two sets. WE ARE GETTING FANCY HERE result_index |= set(dedup_slug(r) for r in result_set) @@ -85,7 +89,7 @@ def get_connectors(): def get_or_create_connector(remote_id): - """ get the connector related to the author's server """ + """ get the connector related to the object's server """ url = urlparse(remote_id) identifier = url.netloc if not identifier: @@ -122,3 +126,11 @@ def load_connector(connector_info): "bookwyrm.connectors.%s" % connector_info.connector_file ) return connector.Connector(connector_info.identifier) + + +@receiver(signals.post_save, sender="bookwyrm.FederatedServer") +# pylint: disable=unused-argument +def create_connector(sender, instance, created, *args, **kwargs): + """ create a connector to an external bookwyrm server """ + if instance.application_type == "bookwyrm": + get_or_create_connector("https://{:s}".format(instance.server_name)) From 634509a7f308cbaebf20ed3a349ac5062f0b0d2c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 17:19:29 -0700 Subject: [PATCH 2/4] Associate users with their invites --- .../migrations/0060_siteinvite_invitees.py | 21 +++++++++++++++++++ bookwyrm/models/site.py | 1 + bookwyrm/views/authentication.py | 1 + 3 files changed, 23 insertions(+) create mode 100644 bookwyrm/migrations/0060_siteinvite_invitees.py diff --git a/bookwyrm/migrations/0060_siteinvite_invitees.py b/bookwyrm/migrations/0060_siteinvite_invitees.py new file mode 100644 index 000000000..acd009779 --- /dev/null +++ b/bookwyrm/migrations/0060_siteinvite_invitees.py @@ -0,0 +1,21 @@ +# Generated by Django 3.1.6 on 2021-04-02 00:14 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0059_user_preferred_timezone"), + ] + + operations = [ + migrations.AddField( + model_name="siteinvite", + name="invitees", + field=models.ManyToManyField( + related_name="invitees", to=settings.AUTH_USER_MODEL + ), + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index c3c1d8a45..1eb318694 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -58,6 +58,7 @@ class SiteInvite(models.Model): use_limit = models.IntegerField(blank=True, null=True) times_used = models.IntegerField(default=0) user = models.ForeignKey(User, on_delete=models.CASCADE) + invitees = models.ManyToManyField(User, related_name="invitees") def valid(self): """ make sure it hasn't expired or been used """ diff --git a/bookwyrm/views/authentication.py b/bookwyrm/views/authentication.py index eef5c79f0..22689a28c 100644 --- a/bookwyrm/views/authentication.py +++ b/bookwyrm/views/authentication.py @@ -108,6 +108,7 @@ class Register(View): ) if invite: invite.times_used += 1 + invite.invitees.add(user) invite.save() login(request, user) From 62bd744b69ae7294d00c8e76c64ab25bcb7f2758 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 17:38:53 -0700 Subject: [PATCH 3/4] Sort and filter mutually respect each other --- bookwyrm/templates/snippets/filters_panel/filters_panel.html | 5 ++++- bookwyrm/templates/snippets/table-sort-header.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/snippets/filters_panel/filters_panel.html b/bookwyrm/templates/snippets/filters_panel/filters_panel.html index 185f5bc48..8c1788600 100644 --- a/bookwyrm/templates/snippets/filters_panel/filters_panel.html +++ b/bookwyrm/templates/snippets/filters_panel/filters_panel.html @@ -11,7 +11,10 @@ -