Adds create block form

This commit is contained in:
Mouse Reeve 2021-09-08 15:08:22 -07:00
parent 21de8e66be
commit c705178c3b
6 changed files with 57 additions and 12 deletions

View file

@ -299,6 +299,12 @@ class ReportForm(CustomForm):
fields = ["user", "reporter", "statuses", "note"]
class EmailBlocklistForm(CustomForm):
class Meta:
model = models.EmailBlocklist
fields = ["domain"]
class ServerForm(CustomForm):
class Meta:
model = models.FederatedServer

View file

@ -24,7 +24,9 @@ from .federated_server import FederatedServer
from .import_job import ImportJob, ImportItem
from .site import SiteSettings, SiteInvite, PasswordReset, InviteRequest
from .site import SiteSettings, SiteInvite
from .site import PasswordReset, InviteRequest
from .site import EmailBlocklist
from .announcement import Announcement
cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass)

View file

@ -13,21 +13,21 @@
{% csrf_token %}
<input type="hidden" name="user" value="{{ request.user.id }}">
<p>
<label class="label" for="id_preview">Preview:</label>
<label class="label" for="id_preview">{% trans "Preview:" %}</label>
{{ form.preview }}
{% for error in form.preview.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<p>
<label class="label" for="id_content">Content:</label>
<label class="label" for="id_content">{% trans "Content:" %}</label>
{{ form.content }}
{% for error in form.content.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<p>
<label class="label" for="id_event_date">Event date:</label>
<label class="label" for="id_event_date">{% trans "Event date:" %}</label>
<input type="date" name="event_date" value="{{ form.event_date.value|date:'Y-m-d' }}" class="input" id="id_event_date">
{% for error in form.event_date.errors %}
<p class="help is-danger">{{ error | escape }}</p>
@ -37,7 +37,7 @@
<div class="columns">
<div class="column">
<p>
<label class="label" for="id_start_date">Start date:</label>
<label class="label" for="id_start_date">{% trans "Start date:" %}</label>
<input type="date" name="start_date" class="input" value="{{ form.start_date.value|date:'Y-m-d' }}" id="id_start_date">
{% for error in form.start_date.errors %}
<p class="help is-danger">{{ error | escape }}</p>
@ -46,7 +46,7 @@
</div>
<div class="column">
<p>
<label class="label" for="id_end_date">End date:</label>
<label class="label" for="id_end_date">{% trans "End date:" %}</label>
<input type="date" name="end_date" class="input" id="id_end_date" value="{{ form.end_date.value|date:'Y-m-d' }}">
{% for error in form.end_date.errors %}
<p class="help is-danger">{{ error | escape }}</p>
@ -55,7 +55,7 @@
</div>
<div class="column is-narrow">
<p>
<label class="label" for="id_active">Active:</label>
<label class="label" for="id_active">{% trans "Active:" %}</label>
{{ form.active }}
{% for error in form.active.errors %}
<p class="help is-danger">{{ error | escape }}</p>

View file

@ -0,0 +1,25 @@
{% extends 'components/inline_form.html' %}
{% load i18n %}
{% block header %}
{% trans "Add domain" %}
{% endblock %}
{% block form %}
<form name="add-domain" method="post" action="{% url 'settings-email-blocks' %}">
{% csrf_token %}
<div class="field">
<label class="label" for="id_event_date">{% trans "Domain:" %}</label>
{{ form.domain }}
{% for error in form.domain.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
<div class="field">
<div class="control">
<button type="submit" class="button is-primary">{% trans "Add" %}</button>
</div>
</div>
</form>
{% endblock %}

View file

@ -5,13 +5,18 @@
{% block header %}{% trans "Email Blocklist" %}{% endblock %}
{% block edit-button %}
<a href="{% url 'settings-import-blocklist' %}">
<span class="icon icon-plus" title="{% trans 'Add domain' %}" aria-hidden="True"></span>
<span class="is-hidden-mobile">{% trans "Add domain" %}</span>
{% trans "Add domain" as button_text %}
{% include 'snippets/toggle/open_button.html' with controls_text="add_domain" icon_with_text="plus" text=button_text focus="add_domain_header" %}
</a>
{% endblock %}
{% block panel %}
{% include 'settings/domain_form.html' with controls_text="add_domain" class="block" %}
<p class="notification block">
{% trans "When someone tries to register with an email from this domain, no account will be created. The registration process will appear to have worked." %}
</p>
<table class="table is-striped">
<tr>
{% url 'settings-federation' as url %}
@ -23,8 +28,9 @@
{% trans "Options" %}
</th>
</tr>
{% for domain in domains %}
<tr>
<td>gmail.com</td>
<td>{{ domain.domain }}</td>
<td>
{% trans "Delete" as button_text %}
<button class="button">
@ -33,6 +39,7 @@
</button>
</td>
</tr>
{% endfor %}
</table>
{% include 'snippets/pagination.html' with page=servers path=request.path %}

View file

@ -4,6 +4,8 @@ from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import forms, models
# pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch")
@method_decorator(
@ -15,5 +17,8 @@ class EmailBlocklist(View):
def get(self, request):
"""view and compose blocks"""
data = {}
data = {
"domains": models.EmailBlocklist.objects.order_by("-created_date").all(),
"form": forms.EmailBlocklistForm(),
}
return TemplateResponse(request, "settings/email_blocklist.html", data)