Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2020-10-31 13:08:29 -07:00
commit 2b75fd1f14
8 changed files with 67 additions and 16 deletions

View file

@ -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()

View file

@ -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'

View file

@ -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)

View file

@ -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),
),
]

View file

@ -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,
)

View file

@ -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'),

View file

@ -108,7 +108,7 @@ input.toggle-control:checked ~ .toggle-content {
position: absolute;
}
.quote blockquote:before {
content: "\e904";
content: "\e905";
top: 0;
left: 0;
}

View file

@ -3,14 +3,16 @@
<div class="columns">
<div class="column block">
{% include 'snippets/about.html' with site_settings=site_settings %}
<blockquote>
{% include 'snippets/about.html' with site_settings=site_settings %}
</blockquote>
</div>
<div class="column block">
<h2 class="title">Code of Conduct</h2>
<p>
{{ site_settings.code_of_conduct }}
</p>
<blockquote>
{{ site_settings.code_of_conduct }}
</blockquote>
</div>
</div>
{% endblock %}