From 02265b1e49ce99d46ff5ef34630343a3b5d3e10a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 31 Oct 2020 12:45:39 -0700 Subject: [PATCH 1/4] Show federated servers and connectors in admin --- bookwyrm/admin.py | 2 + .../migrations/0062_auto_20201031_1936.py | 38 +++++++++++++++++++ bookwyrm/models/connector.py | 18 ++++++--- bookwyrm/templates/about.html | 10 +++-- 4 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 bookwyrm/migrations/0062_auto_20201031_1936.py diff --git a/bookwyrm/admin.py b/bookwyrm/admin.py index 2ea0a1d1e..45af81d99 100644 --- a/bookwyrm/admin.py +++ b/bookwyrm/admin.py @@ -4,3 +4,5 @@ from bookwyrm import models admin.site.register(models.SiteSettings) admin.site.register(models.User) +admin.site.register(models.FederatedServer) +admin.site.register(models.Connector) diff --git a/bookwyrm/migrations/0062_auto_20201031_1936.py b/bookwyrm/migrations/0062_auto_20201031_1936.py new file mode 100644 index 000000000..2fbfe6c07 --- /dev/null +++ b/bookwyrm/migrations/0062_auto_20201031_1936.py @@ -0,0 +1,38 @@ +# Generated by Django 3.0.7 on 2020-10-31 19:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0061_auto_20201030_2157'), + ] + + operations = [ + migrations.AlterField( + model_name='connector', + name='api_key', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='connector', + name='max_query_count', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name='connector', + name='name', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='connector', + name='politeness_delay', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name='connector', + name='search_url', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/bookwyrm/models/connector.py b/bookwyrm/models/connector.py index 2a9d496b0..6f64cdf3e 100644 --- a/bookwyrm/models/connector.py +++ b/bookwyrm/models/connector.py @@ -10,25 +10,25 @@ class Connector(BookWyrmModel): ''' book data source connectors ''' identifier = models.CharField(max_length=255, unique=True) priority = models.IntegerField(default=2) - name = models.CharField(max_length=255, null=True) + name = models.CharField(max_length=255, null=True, blank=True) local = models.BooleanField(default=False) connector_file = models.CharField( max_length=255, choices=ConnectorFiles.choices ) - api_key = models.CharField(max_length=255, null=True) + api_key = models.CharField(max_length=255, null=True, blank=True) base_url = models.CharField(max_length=255) books_url = models.CharField(max_length=255) covers_url = models.CharField(max_length=255) - search_url = models.CharField(max_length=255, null=True) + search_url = models.CharField(max_length=255, null=True, blank=True) - politeness_delay = models.IntegerField(null=True) #seconds - max_query_count = models.IntegerField(null=True) + politeness_delay = models.IntegerField(null=True, blank=True) #seconds + max_query_count = models.IntegerField(null=True, blank=True) # how many queries executed in a unit of time, like a day query_count = models.IntegerField(default=0) # when to reset the query count back to 0 (ie, after 1 day) - query_count_expiry = models.DateTimeField(auto_now_add=True) + query_count_expiry = models.DateTimeField(auto_now_add=True, blank=True) class Meta: ''' check that there's code to actually use this connector ''' @@ -38,3 +38,9 @@ class Connector(BookWyrmModel): name='connector_file_valid' ) ] + + def __str__(self): + return "{} ({})".format( + self.identifier, + self.id, + ) diff --git a/bookwyrm/templates/about.html b/bookwyrm/templates/about.html index dbf6f8521..4aae183a8 100644 --- a/bookwyrm/templates/about.html +++ b/bookwyrm/templates/about.html @@ -3,14 +3,16 @@
- {% include 'snippets/about.html' with site_settings=site_settings %} +
+ {% include 'snippets/about.html' with site_settings=site_settings %} +

Code of Conduct

-

- {{ site_settings.code_of_conduct }} -

+
+ {{ site_settings.code_of_conduct }} +
{% endblock %} From 9ef03664f2255ebd270ffd44bc597121b86725fc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 31 Oct 2020 12:59:15 -0700 Subject: [PATCH 2/4] lookup books when resolving activity json --- bookwyrm/activitypub/base_activity.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index fc5b11288..79987b50a 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -2,6 +2,8 @@ from dataclasses import dataclass, fields, MISSING from json import JSONEncoder +from bookwyrm import books_manager, models + from django.db.models.fields.related_descriptors \ import ForwardManyToOneDescriptor @@ -102,6 +104,9 @@ class ActivityObject: def resolve_foreign_key(model, remote_id): ''' look up the remote_id on an activity json field ''' + if model in [models.Edition, models.Work]: + return books_manager.get_or_create_book(remote_id) + result = model.objects if hasattr(model.objects, 'select_subclasses'): result = result.select_subclasses() From 2463e643212dd725f07d6f702d8548aec22b29b2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 31 Oct 2020 13:00:28 -0700 Subject: [PATCH 3/4] wrong quote in blockquote --- bookwyrm/static/css/format.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index b1bf20cde..3f16d94d4 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -108,7 +108,7 @@ input.toggle-control:checked ~ .toggle-content { position: absolute; } .quote blockquote:before { - content: "\e904"; + content: "\e905"; top: 0; left: 0; } From a7d8376b6af7e9fbb50b7bc7cae808e4a0505673 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 31 Oct 2020 13:06:22 -0700 Subject: [PATCH 4/4] Small activitypub serialization issues --- bookwyrm/activitypub/person.py | 2 +- bookwyrm/models/user.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/bookwyrm/activitypub/person.py b/bookwyrm/activitypub/person.py index dee6c1f19..118774a27 100644 --- a/bookwyrm/activitypub/person.py +++ b/bookwyrm/activitypub/person.py @@ -16,7 +16,7 @@ class Person(ActivityObject): publicKey: PublicKey endpoints: Dict icon: Image = field(default=lambda: {}) - bookwyrmUser: str = False + bookwyrmUser: bool = False manuallyApprovesFollowers: str = False discoverable: str = True type: str = 'Person' diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index d1e1f69ea..38442ed75 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -82,12 +82,9 @@ class User(OrderedCollectionPageMixin, AbstractUser): ''' send default icon if one isn't set ''' if self.avatar: url = self.avatar.url - # TODO not the right way to get the media type - media_type = 'image/%s' % url.split('.')[-1] else: url = 'https://%s/static/images/default_avi.jpg' % DOMAIN - media_type = 'image/jpeg' - return activitypub.Image(media_type, url, 'Image') + return activitypub.Image(url=url) @property def ap_public_key(self): @@ -106,6 +103,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): activity_formatter=lambda x: x.split('@')[0] ), ActivityMapping('name', 'name'), + ActivityMapping('bookwyrmUser', 'bookwyrm_user'), ActivityMapping('inbox', 'inbox'), ActivityMapping('outbox', 'outbox'), ActivityMapping('followers', 'ap_followers'),