mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-08 07:12:21 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
406c94354f
7 changed files with 51 additions and 4 deletions
|
@ -3,6 +3,9 @@ import importlib
|
||||||
import re
|
import re
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from django.db.models import signals
|
||||||
|
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
@ -44,6 +47,7 @@ def search(query, min_confidence=0.1):
|
||||||
except (HTTPError, ConnectorException):
|
except (HTTPError, ConnectorException):
|
||||||
continue
|
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]
|
result_set = [r for r in result_set if dedup_slug(r) not in result_index]
|
||||||
# `|=` concats two sets. WE ARE GETTING FANCY HERE
|
# `|=` concats two sets. WE ARE GETTING FANCY HERE
|
||||||
result_index |= set(dedup_slug(r) for r in result_set)
|
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):
|
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)
|
url = urlparse(remote_id)
|
||||||
identifier = url.netloc
|
identifier = url.netloc
|
||||||
if not identifier:
|
if not identifier:
|
||||||
|
@ -122,3 +126,11 @@ def load_connector(connector_info):
|
||||||
"bookwyrm.connectors.%s" % connector_info.connector_file
|
"bookwyrm.connectors.%s" % connector_info.connector_file
|
||||||
)
|
)
|
||||||
return connector.Connector(connector_info.identifier)
|
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))
|
||||||
|
|
21
bookwyrm/migrations/0060_siteinvite_invitees.py
Normal file
21
bookwyrm/migrations/0060_siteinvite_invitees.py
Normal file
|
@ -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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -58,6 +58,7 @@ class SiteInvite(models.Model):
|
||||||
use_limit = models.IntegerField(blank=True, null=True)
|
use_limit = models.IntegerField(blank=True, null=True)
|
||||||
times_used = models.IntegerField(default=0)
|
times_used = models.IntegerField(default=0)
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
invitees = models.ManyToManyField(User, related_name="invitees")
|
||||||
|
|
||||||
def valid(self):
|
def valid(self):
|
||||||
""" make sure it hasn't expired or been used """
|
""" make sure it hasn't expired or been used """
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="field is-grouped">
|
<td class="field is-grouped">
|
||||||
|
{# no invite OR invite not yet used #}
|
||||||
|
{% if not req.invite.times_used %}
|
||||||
<form name="send-invite" method="post">
|
<form name="send-invite" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="invite-request" value="{{ req.id }}">
|
<input type="hidden" name="invite-request" value="{{ req.id }}">
|
||||||
|
@ -68,9 +70,16 @@
|
||||||
<button type="submit" class="button is-link is-light is-small">{% trans "Re-send invite" %}</button>
|
<button type="submit" class="button is-link is-light is-small">{% trans "Re-send invite" %}</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# invite created but not used #}
|
||||||
{% if req.invite and not req.invite.times_used %}
|
{% if req.invite and not req.invite.times_used %}
|
||||||
{# <button class="button is-danger is-light is-small">{% trans "Revoke invite" %}</button> #}
|
{# <button class="button is-danger is-light is-small">{% trans "Revoke invite" %}</button> #}
|
||||||
|
{% elif req.invite %}
|
||||||
|
{# accepted #}
|
||||||
|
{% if req.invite.invitees.exists %}
|
||||||
|
<a href="{{ req.invite.invitees.first.local_path }}">@{{ req.invite.invitees.first.localname }}</a>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}">
|
<form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -78,7 +87,7 @@
|
||||||
{% if not req.ignored %}
|
{% if not req.ignored %}
|
||||||
<button type="submit" class="button is-danger is-light is-small">{% trans "Ignore" %}</button>
|
<button type="submit" class="button is-danger is-light is-small">{% trans "Ignore" %}</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button type="submit" class="button is-danger is-light is-small">{% trans "Un-gnore" %}</button>
|
<button type="submit" class="button is-danger is-light is-small">{% trans "Un-ignore" %}</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -11,7 +11,10 @@
|
||||||
</span>
|
</span>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<form class="hidden mt-3" id="filters" method-"get" action="{{ request.path }}" tabindex="0">
|
<form class="hidden mt-3" id="filters" method="get" action="{{ request.path }}" tabindex="0">
|
||||||
|
{% if sort %}
|
||||||
|
<input type="hidden" name="sort" value="{{ sort }}">
|
||||||
|
{% endif %}
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
{% block filter_fields %}
|
{% block filter_fields %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<a href="{{ url }}?sort={% if sort == field %}-{% endif %}{{ field }}">
|
<a href="{{ url }}?sort={% if sort == field %}-{% endif %}{{ field }}{% for k, v in request.GET.items %}{% if k != "sort" %}&{{ k }}={{ v }}{% endif %}{% endfor %}">
|
||||||
{{ text }}
|
{{ text }}
|
||||||
{% if sort == field %}
|
{% if sort == field %}
|
||||||
<span class="icon icon-arrow-up">
|
<span class="icon icon-arrow-up">
|
||||||
|
|
|
@ -108,6 +108,7 @@ class Register(View):
|
||||||
)
|
)
|
||||||
if invite:
|
if invite:
|
||||||
invite.times_used += 1
|
invite.times_used += 1
|
||||||
|
invite.invitees.add(user)
|
||||||
invite.save()
|
invite.save()
|
||||||
|
|
||||||
login(request, user)
|
login(request, user)
|
||||||
|
|
Loading…
Reference in a new issue