Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2020-11-02 09:07:21 -08:00
commit 6b667aa575
7 changed files with 69 additions and 27 deletions

View file

@ -50,7 +50,7 @@ def get_or_create_connector(remote_id):
books_url='https://%s/book' % identifier,
covers_url='https://%s/images/covers' % identifier,
search_url='https://%s/search?q=' % identifier,
priority=3
priority=2
)
return load_connector(connector_info)

View file

@ -84,7 +84,8 @@ class User(OrderedCollectionPageMixin, AbstractUser):
if self.avatar:
url = self.avatar.url
else:
url = 'https://%s/static/images/default_avi.jpg' % DOMAIN
url = '/static/images/default_avi.jpg'
url = 'https://%s%s' % (DOMAIN, url)
return activitypub.Image(url=url)
@property

View file

@ -52,7 +52,7 @@ def handle_remote_webfinger(query):
try:
user = models.User.objects.get(username=query)
except models.User.DoesNotExist:
url = 'https://%s/.well-known/webfinger?resource=acct:@%s' % \
url = 'https://%s/.well-known/webfinger?resource=acct:%s' % \
(domain, query)
try:
response = requests.get(url)

View file

@ -1,32 +1,66 @@
{% extends 'layout.html' %}
{% block content %}
{% with book_results|first as local_results %}
<div class="block columns">
<div class="column">
<h2 class="title">Matching Books</h2>
{% for result_set in book_results %}
{% if result_set.results %}
<section>
{% if not result_set.connector.local %}
<h3>
Results from <a href="{{ result_set.connector.base_url }}" target="_blank">{% if result_set.connector.name %}{{ result_set.connector.name }}{% else %}{{ result_set.connector.identifier }}{% endif %}</a>
</h3>
{% endif %}
{% for result in result_set.results %}
<div>
<form action="/resolve_book" method="POST">
{% csrf_token %}
<input type="hidden" name="remote_id" value="{{ result.key }}">
<button type="submit">{{ result.title }} by {{ result.author }} ({{ result.year }})</button>
</form>
</div>
<section class="block">
{% if not local_results.results %}
<p>No books found for "{{ query }}"</p>
{% else %}
<ul>
{% for result in local_results.results %}
<li class="pd-4">
<a href="{{ result.key }}">{% include 'snippets/search_result_text.html' with result=result link=True %}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</section>
{% if book_results|slice:":1" and local_results.results %}
<div class="block">
<p>
Didn't find what you were looking for?
</p>
<input class="toggle-control" type="radio" name="more-results" id="fewer-results" checked>
<div class="toggle-content hidden">
<label class="button is-small" for="more-results">Show results from other catalogues</label>
</div>
</div>
{% endif %}
{% endfor %}
{% if not book_results %}
<p>No books found for "{{ query }}"</p>
{% endif %}
<input class="toggle-control" type="radio" name="more-results" id="more-results" {% if not local_results.results %}checked{% endif %}>
<div class="toggle-content hidden">
{% for result_set in book_results|slice:"1:" %}
{% if result_set.results %}
<section class="block">
{% if not result_set.connector.local %}
<h3 class="title is-5">
Results from <a href="{{ result_set.connector.base_url }}" target="_blank">{% if result_set.connector.name %}{{ result_set.connector.name }}{% else %}{{ result_set.connector.identifier }}{% endif %}</a>
</h3>
{% endif %}
<ul>
{% for result in result_set.results %}
<li class="pb-4">
<form action="/resolve_book" method="POST">
{% csrf_token %}
<input type="hidden" name="remote_id" value="{{ result.key }}">
<div>{% include 'snippets/search_result_text.html' with result=result link=False %}</div>
<button type="submit" class="button is-small is-link is-light">Import book</button>
</form>
</li>
{% endfor %}
</ul>
</section>
{% endif %}
{% endfor %}
{% if local_results.results %}
<label class="button is-small" for="fewer-results">Hide results from other catalogues</label>
{% endif %}
</div>
</div>
<div class="column">
<h2 class="title">Matching Users</h2>
@ -42,4 +76,5 @@
{% endfor %}
</div>
</div>
{% endwith %}
{% endblock %}

View file

@ -1,5 +1,6 @@
''' views for actions you can take in the application '''
from io import BytesIO, TextIOWrapper
from uuid import uuid4
from PIL import Image
import dateutil.parser
@ -201,8 +202,12 @@ def edit_profile(request):
output = BytesIO()
cropped.save(output, format=image.format)
ContentFile(output.getvalue())
# set the name to a hash
extension = form.files['avatar'].name.split('.')[-1]
filename = '%s.%s' % (uuid4(), extension)
request.user.avatar.save(
form.files['avatar'].name,
filename,
ContentFile(output.getvalue())
)

View file

@ -19,14 +19,14 @@ def webfinger(request):
if not resource and not resource.startswith('acct:'):
return HttpResponseNotFound()
username = resource.replace('acct:@', '')
username = resource.replace('acct:', '')
try:
user = models.User.objects.get(username=username)
except models.User.DoesNotExist:
return HttpResponseNotFound('No account found')
return JsonResponse({
'subject': 'acct:@%s' % (user.username),
'subject': 'acct:%s' % (user.username),
'links': [
{
'rel': 'self',

View file

@ -76,4 +76,5 @@ Connector.objects.create(
books_url='https://openlibrary.org',
covers_url='https://covers.openlibrary.org',
search_url='https://openlibrary.org/search?q=',
priority=3,
)