Functional add server form

This commit is contained in:
Mouse Reeve 2021-04-07 13:06:29 -07:00
parent d383e8a61e
commit ddab9af564
7 changed files with 70 additions and 35 deletions

View file

@ -1,13 +0,0 @@
{% extends 'components/inline_form.html' %}
{% load i18n %}
{% block header %}
{% trans "Add server" %}
{% endblock %}
{% block form %}
<form>
{% include 'settings/server_form.html' %}
</form>
{% endblock %}

View file

@ -0,0 +1,16 @@
{% extends 'settings/admin_layout.html' %}
{% load i18n %}
{% block title %}{% trans "Add server" %}{% endblock %}
{% block header %}
{% if form.server_name.value %}{{ form.server_name.value }}{% else %}{% trans "Add server" %}{% endif %}
<a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to server list" %}</a>
{% endblock %}
{% block panel %}
<form method="POST" action="{% url 'settings-edit-federated-server' %}">
{% include 'settings/server_form.html' %}
</form>
{% endblock %}

View file

@ -5,16 +5,14 @@
{% block header %}{% trans "Federated Servers" %}{% endblock %}
{% block edit-button %}
{% trans "Add server" as button_text %}
{% include 'snippets/toggle/open_button.html' with controls_text="add-server" icon="plus" text=button_text focus="add-server-header" %}
{% endblock%}
<a href="{% url 'settings-edit-federated-server' %}">
<span class="icon icon-plus" title="{% trans 'Add server' %}">
<span class="is-sr-only">{% trans "Add server" %}</span>
</span>
</a>
{% endblock %}
{% block panel %}
<div class="block">
{% include 'settings/add_server_form.html' with controls_text="add-server" %}
</div>
<table class="table is-striped">
<tr>
{% url 'settings-federation' as url %}

View file

@ -1,32 +1,40 @@
{% load i18n %}
{% csrf_token %}
<div class="columns">
<div class="column is-half">
<p>
<div>
<label class="label" for="id_server_name">{% trans "Instance:" %}</label>
<input type="text" name="server_name" maxlength="255" class="input" required="" id="id_server_name" value="{{ form.server_name.value|default:'' }}" placeholder="domain.com">
</p>
<p>
<input type="text" name="server_name" maxlength="255" class="input" required id="id_server_name" value="{{ form.server_name.value|default:'' }}" placeholder="domain.com">
{% for error in form.server_name.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
<div>
<label class="label" for="id_status">{% trans "Status:" %}</label>
<div class="select">
<select name="status" class="" id="id_status">
<option value="federated" {% if form.status.value == "federated" or not form.status.value %}selected=""{% endif %}>Federated</option>
<option value="blocked" {% if form.status.value == "blocked" %}selected{% endif %}>Blocked</option>
<option value="federated" {% if form.status.value == "federated" or not form.status.value %}selected=""{% endif %}>{% trans "Federated" %}</option>
<option value="blocked" {% if form.status.value == "blocked" %}selected{% endif %}>{% trans "Blocked" %}</option>
</select>
</div>
</p>
</div>
</div>
<div class="column is-half">
<p>
<div>
<label class="label" for="id_application_type">{% trans "Software:" %}</label>
<input type="text" name="application_type" maxlength="255" class="input" id="id_application_type" value="{{ form.application_type.value|default:'' }}">
</p>
<p>
{% for error in form.application_type.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
<div>
<label class="label" for="id_application_version">{% trans "Version:" %}</label>
<input type="text" name="application_version" maxlength="255" class="input" id="id_application_version" value="{{ form.application_version.value|default:'' }}">
</p>
{% for error in form.application_version.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
</div>
</div>
<p>

View file

@ -68,6 +68,11 @@ urlpatterns = [
views.FederatedServer.as_view(),
name="settings-federated-server",
),
re_path(
r"^settings/federation/edit/?$",
views.EditFederatedServer.as_view(),
name="settings-edit-federated-server",
),
re_path(
r"^settings/invites/?$", views.ManageInvites.as_view(), name="settings-invites"
),

View file

@ -5,7 +5,7 @@ from .block import Block, unblock
from .books import Book, EditBook, ConfirmEditBook, Editions
from .books import upload_cover, add_description, switch_edition, resolve_book
from .directory import Directory
from .federation import Federation, FederatedServer
from .federation import Federation, FederatedServer, EditFederatedServer
from .feed import DirectMessage, Feed, Replies, Status
from .follow import follow, unfollow
from .follow import accept_follow_request, delete_follow_request

View file

@ -34,10 +34,31 @@ class Federation(View):
servers = servers.order_by(sort)
paginated = Paginator(servers, PAGE_LENGTH)
data = {"servers": paginated.page(page), "sort": sort, "form": forms.ServerForm}
data = {
"servers": paginated.page(page), "sort": sort, "form": forms.ServerForm()
}
return TemplateResponse(request, "settings/federation.html", data)
class EditFederatedServer(View):
""" manually add a server """
def get(self, request):
""" add server form """
data = {"form": forms.ServerForm()}
return TemplateResponse(request, "settings/edit_server.html", data)
def post(self, request):
""" add a server from the admin panel """
form = forms.ServerForm(request.POST)
if not form.is_valid():
data = {"form": form}
return TemplateResponse(request, "settings/edit_server.html", data)
server = form.save()
return redirect("settings-federated-server", server.id)
@method_decorator(login_required, name="dispatch")
@method_decorator(
permission_required("bookwyrm.control_federation", raise_exception=True),