From 3d70a36d86f6f114c9e3ee8204bf26e449024db5 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 20 May 2021 08:56:17 -0700 Subject: [PATCH] Editable announcement --- bookwyrm/templates/book/book_identifiers.html | 1 - bookwyrm/templates/settings/announcement.html | 49 +++++++- .../templates/settings/announcement_form.html | 116 +++++++++--------- .../templates/settings/announcements.html | 4 +- .../templates/settings/federated_server.html | 2 +- bookwyrm/views/announcements.py | 4 +- 6 files changed, 104 insertions(+), 72 deletions(-) diff --git a/bookwyrm/templates/book/book_identifiers.html b/bookwyrm/templates/book/book_identifiers.html index d71ea409..6021d243 100644 --- a/bookwyrm/templates/book/book_identifiers.html +++ b/bookwyrm/templates/book/book_identifiers.html @@ -1,5 +1,4 @@ {% spaceless %} - {% load i18n %}
diff --git a/bookwyrm/templates/settings/announcement.html b/bookwyrm/templates/settings/announcement.html index 57b4d167..9c367fa6 100644 --- a/bookwyrm/templates/settings/announcement.html +++ b/bookwyrm/templates/settings/announcement.html @@ -1,22 +1,59 @@ {% extends 'settings/admin_layout.html' %} -{% load i18n %} +{% load i18n %}{% load humanize %} {% block title %}{% trans "Announcement" %} - {{ announcement.preview }}{% endblock %} -{% block header %}{% trans "Announcement" %}{% endblock %} +{% block header %} +{% trans "Announcement" %} +{% trans "Back to list" %} +{% endblock %} {% block edit-button %} {% 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" %} {% endblock %} {% block panel %} -
- {% include 'settings/announcement_form.html' with controls_text="create-announcement" %} -
+
+ {% include 'settings/announcement_form.html' with controls_text="edit-announcement" %} +
+
+
+
{% trans "Visible:" %}
+
+ {% if announcement in active_announcements %} + {% trans "True" %} + {% else %} + {% trans "False" %} + {% endif %} +
+
+ + {% if announcement.start_date %} +
+
{% trans "Start date:" %}
+
{{ announcement.start_date|naturalday }}
+
+ {% endif %} + + {% if announcement.end_date %} +
+
{% trans "End date:" %}
+
{{ announcement.end_date|naturalday }}
+
+ {% endif %} + +
+
{% trans "Active:" %}
+
{{ announcement.active }}
+
+
+ + + {% include 'snippets/announcement.html' with announcement=announcement pressed=True %}
diff --git a/bookwyrm/templates/settings/announcement_form.html b/bookwyrm/templates/settings/announcement_form.html index 5c05b995..4e2e8f32 100644 --- a/bookwyrm/templates/settings/announcement_form.html +++ b/bookwyrm/templates/settings/announcement_form.html @@ -6,67 +6,63 @@ {% endblock %} {% block form %} -
- - {% csrf_token %} - -

- - {{ form.preview }} - {% for error in form.preview.errors %} -

{{ error | escape }}

- {% endfor %} -

-

- - {{ form.content }} - {% for error in form.content.errors %} -

{{ error | escape }}

- {% endfor %} -

-

- - - {% for error in form.event_date.errors %} -

{{ error | escape }}

- {% endfor %} -

- -
-
-

- - - {% for error in form.start_date.errors %} -

{{ error | escape }}

- {% endfor %} -

-
-
-

- - - {% for error in form.end_date.errors %} -

{{ error | escape }}

- {% endfor %} -

-
-
-

- - {{ form.active }} - {% for error in form.active.errors %} -

{{ error | escape }}

- {% endfor %} -

-
+{% csrf_token %} + +

+ + {{ form.preview }} + {% for error in form.preview.errors %} +

{{ error | escape }}

+ {% endfor %} +

+

+ + {{ form.content }} + {% for error in form.content.errors %} +

{{ error | escape }}

+ {% endfor %} +

+

+ + + {% for error in form.event_date.errors %} +

{{ error | escape }}

+ {% endfor %} +

+ +
+
+

+ + + {% for error in form.start_date.errors %} +

{{ error | escape }}

+ {% endfor %} +

+
+

+ + + {% for error in form.end_date.errors %} +

{{ error | escape }}

+ {% endfor %} +

+
+
+

+ + {{ form.active }} + {% for error in form.active.errors %} +

{{ error | escape }}

+ {% endfor %} +

+
+
-
-
- -
+
+
+
- +
{% endblock %} - diff --git a/bookwyrm/templates/settings/announcements.html b/bookwyrm/templates/settings/announcements.html index f5117f2f..d1396179 100644 --- a/bookwyrm/templates/settings/announcements.html +++ b/bookwyrm/templates/settings/announcements.html @@ -11,9 +11,9 @@ {% endblock %} {% block panel %} -
+
{% include 'settings/announcement_form.html' with controls_text="create-announcement" %} -
+ diff --git a/bookwyrm/templates/settings/federated_server.html b/bookwyrm/templates/settings/federated_server.html index 9e00f92b..b10f8501 100644 --- a/bookwyrm/templates/settings/federated_server.html +++ b/bookwyrm/templates/settings/federated_server.html @@ -10,7 +10,7 @@ {% if server.status == "blocked" %}{% trans "Blocked" %} {% endif %} -{% trans "Back to server list" %} +{% trans "Back to list" %} {% endblock %} {% block panel %} diff --git a/bookwyrm/views/announcements.py b/bookwyrm/views/announcements.py index 79e50da9..8ea5952c 100644 --- a/bookwyrm/views/announcements.py +++ b/bookwyrm/views/announcements.py @@ -61,9 +61,9 @@ class Announcement(View): announcement = get_object_or_404(models.Announcement, id=announcement_id) form = forms.AnnouncementForm(request.POST, instance=announcement) if form.is_valid(): - form.save() + announcement = form.save() data = { - "announcements": models.Announcement.objects.all(), + "announcement": announcement, "form": form, } return TemplateResponse(request, "settings/announcement.html", data)