Editable announcement

This commit is contained in:
Mouse Reeve 2021-05-20 08:56:17 -07:00
parent d64e0c4aa8
commit 3d70a36d86
6 changed files with 104 additions and 72 deletions

View file

@ -1,5 +1,4 @@
{% spaceless %} {% spaceless %}
{% load i18n %} {% load i18n %}
<dl> <dl>

View file

@ -1,22 +1,59 @@
{% extends 'settings/admin_layout.html' %} {% extends 'settings/admin_layout.html' %}
{% load i18n %} {% load i18n %}{% load humanize %}
{% block title %}{% trans "Announcement" %} - {{ announcement.preview }}{% endblock %} {% block title %}{% trans "Announcement" %} - {{ announcement.preview }}{% endblock %}
{% block header %}{% trans "Announcement" %}{% endblock %} {% block header %}
{% trans "Announcement" %}
<a href="{% url 'settings-announcements' %}" class="has-text-weight-normal help">{% trans "Back to list" %}</a>
{% endblock %}
{% block edit-button %} {% block edit-button %}
{% trans "Edit Announcement" as button_text %} {% trans "Edit Announcement" as button_text %}
{% include 'snippets/toggle/open_button.html' with controls_text="create-announcement" icon_with_text="plus" text=button_text focus="create-announcement-header" %} {% include 'snippets/toggle/open_button.html' with controls_text="edit-announcement" icon_with_text="plus" text=button_text focus="edit-announcement-header" %}
</a> </a>
{% endblock %} {% endblock %}
{% block panel %} {% block panel %}
<div class="block"> <form name="edit-announcement" method="post" action="{% url 'settings-announcements' announcement.id %}" class="block">
{% include 'settings/announcement_form.html' with controls_text="create-announcement" %} {% include 'settings/announcement_form.html' with controls_text="edit-announcement" %}
</div> </form>
<div class="block content"> <div class="block content">
<dl>
<div class="is-flex notification pt-1 pb-1 mb-0 {% if announcement in active_announcements %}is-success{% else %}is-danger{% endif %}">
<dt class="mr-1 has-text-weight-bold">{% trans "Visible:" %}</dt>
<dd>
{% if announcement in active_announcements %}
{% trans "True" %}
{% else %}
{% trans "False" %}
{% endif %}
</dd>
</div>
{% if announcement.start_date %}
<div class="is-flex notificationi pt-1 pb-1 mb-0 has-background-white">
<dt class="mr-1 has-text-weight-bold">{% trans "Start date:" %}</dt>
<dd>{{ announcement.start_date|naturalday }}</dd>
</div>
{% endif %}
{% if announcement.end_date %}
<div class="is-flex notification pt-1 pb-1 mb-0 has-background-white">
<dt class="mr-1 has-text-weight-bold">{% trans "End date:" %}</dt>
<dd>{{ announcement.end_date|naturalday }}</dd>
</div>
{% endif %}
<div class="is-flex notification pt-1 pb-1 has-background-white">
<dt class="mr-1 has-text-weight-bold">{% trans "Active:" %}</dt>
<dd>{{ announcement.active }}</dd>
</div>
</dl>
<hr aria-hidden="true">
{% include 'snippets/announcement.html' with announcement=announcement pressed=True %} {% include 'snippets/announcement.html' with announcement=announcement pressed=True %}
</div> </div>

View file

@ -6,8 +6,6 @@
{% endblock %} {% endblock %}
{% block form %} {% block form %}
<form name="create-announcement" method="post" action="{% url 'settings-announcements' %}">
<form name="create-announcement" method="post" action="/settings/announcements">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ request.user.id }}"> <input type="hidden" name="user" value="{{ request.user.id }}">
<p> <p>
@ -67,6 +65,4 @@
<button type="submit" class="button is-primary">{% trans "Save" %}</button> <button type="submit" class="button is-primary">{% trans "Save" %}</button>
</div> </div>
</div> </div>
</form>
{% endblock %} {% endblock %}

View file

@ -11,9 +11,9 @@
{% endblock %} {% endblock %}
{% block panel %} {% block panel %}
<div class="block"> <form name="create-announcement" method="post" action="{% url 'settings-announcements' %}" class="block">
{% include 'settings/announcement_form.html' with controls_text="create-announcement" %} {% include 'settings/announcement_form.html' with controls_text="create-announcement" %}
</div> </form>
<table class="table is-striped"> <table class="table is-striped">
<tr> <tr>

View file

@ -10,7 +10,7 @@
{% if server.status == "blocked" %}<span class="icon icon-x has-text-danger is-size-5" title="{% trans 'Blocked' %}"><span class="is-sr-only">{% trans "Blocked" %}</span></span> {% if server.status == "blocked" %}<span class="icon icon-x has-text-danger is-size-5" title="{% trans 'Blocked' %}"><span class="is-sr-only">{% trans "Blocked" %}</span></span>
{% endif %} {% endif %}
<a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to server list" %}</a> <a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to list" %}</a>
{% endblock %} {% endblock %}
{% block panel %} {% block panel %}

View file

@ -61,9 +61,9 @@ class Announcement(View):
announcement = get_object_or_404(models.Announcement, id=announcement_id) announcement = get_object_or_404(models.Announcement, id=announcement_id)
form = forms.AnnouncementForm(request.POST, instance=announcement) form = forms.AnnouncementForm(request.POST, instance=announcement)
if form.is_valid(): if form.is_valid():
form.save() announcement = form.save()
data = { data = {
"announcements": models.Announcement.objects.all(), "announcement": announcement,
"form": form, "form": form,
} }
return TemplateResponse(request, "settings/announcement.html", data) return TemplateResponse(request, "settings/announcement.html", data)