diff --git a/bookwyrm/templates/book/format_filter.html b/bookwyrm/templates/book/format_filter.html index c722b24f..4280ebac 100644 --- a/bookwyrm/templates/book/format_filter.html +++ b/bookwyrm/templates/book/format_filter.html @@ -8,7 +8,7 @@ {% for format in formats %}{% if format %} {% endif %}{% endfor %} diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 6adab96a..112640fb 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -1,4 +1,4 @@ -{% load layout %}{% load i18n %}{% load humanize %} +{% load layout %}{% load i18n %} @@ -185,25 +185,7 @@
{% for announcement in active_announcements %} -
-
-
- {% if announcement.event_date %} - {{ announcement.event_date|naturalday|title }}: - {% endif %} - {{ announcement.preview }} -
-
- {% trans "Open" as button_text %} - {% include 'snippets/toggle/open_button.html' with text=button_text controls_text="announcement" class="is-small" controls_uid=announcement.id icon_with_text="arrow-down" %} - {% trans "Close" as button_text %} - {% include 'snippets/toggle/close_button.html' with text=button_text controls_text="announcement" class="is-small" controls_uid=announcement.id icon_with_text="arrow-up" %} -
-
- -
+ {% include 'snippets/announcement.html' with announcement=announcement %} {% endfor %}
diff --git a/bookwyrm/templates/settings/announcement.html b/bookwyrm/templates/settings/announcement.html new file mode 100644 index 00000000..57b4d167 --- /dev/null +++ b/bookwyrm/templates/settings/announcement.html @@ -0,0 +1,23 @@ +{% extends 'settings/admin_layout.html' %} +{% load i18n %} +{% block title %}{% trans "Announcement" %} - {{ announcement.preview }}{% endblock %} + +{% block header %}{% trans "Announcement" %}{% 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" %} + +{% endblock %} + +{% block panel %} + +
+ {% include 'settings/announcement_form.html' with controls_text="create-announcement" %} +
+ +
+ {% include 'snippets/announcement.html' with announcement=announcement pressed=True %} +
+ +{% endblock %} diff --git a/bookwyrm/templates/settings/announcements.html b/bookwyrm/templates/settings/announcements.html index eba228c0..f5117f2f 100644 --- a/bookwyrm/templates/settings/announcements.html +++ b/bookwyrm/templates/settings/announcements.html @@ -45,5 +45,5 @@ {% endfor %} -{% include 'snippets/pagination.html' with page=servers path=request.path %} +{% include 'snippets/pagination.html' with page=announcements path=request.path %} {% endblock %} diff --git a/bookwyrm/templates/snippets/announcement.html b/bookwyrm/templates/snippets/announcement.html new file mode 100644 index 00000000..1d82c07c --- /dev/null +++ b/bookwyrm/templates/snippets/announcement.html @@ -0,0 +1,22 @@ +{% load humanize %}{% load i18n %}{% load utilities %} +{% with announcement.id|uuid as uuid %} + +{% endwith %} diff --git a/bookwyrm/templates/snippets/book_titleby.html b/bookwyrm/templates/snippets/book_titleby.html index 76f5f7d6..353f9d12 100644 --- a/bookwyrm/templates/snippets/book_titleby.html +++ b/bookwyrm/templates/snippets/book_titleby.html @@ -1,8 +1,8 @@ {% load i18n %} {% load utilities %} {% if book.authors %} -{% blocktrans with path=book.local_path title=book|title %}{{ title }} by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %} +{% blocktrans with path=book.local_path title=book|book_title %}{{ title }} by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %} {% else %} -{{ book|title }} +{{ book|book_title }} {% endif %} diff --git a/bookwyrm/templates/snippets/status/status_header.html b/bookwyrm/templates/snippets/status/status_header.html index 9ff7f9ff..9abdf8ca 100644 --- a/bookwyrm/templates/snippets/status/status_header.html +++ b/bookwyrm/templates/snippets/status/status_header.html @@ -48,7 +48,7 @@ {% if status.book %} {% if status.status_type == 'GeneratedNote' or status.status_type == 'Rating' %} - {{ status.book|title }}{% if status.status_type == 'Rating' %}: {% include 'snippets/stars.html' with rating=status.rating %} + {{ status.book|book_title }}{% if status.status_type == 'Rating' %}: {% include 'snippets/stars.html' with rating=status.rating %} {{ status.book|title }}{% if status.status_type == 'Rating' %}: + {{ status.book|book_title }}{% if status.status_type == 'Rating' %}: - {{ status.mention_books.first.title }} + {{ status.mention_books.first|book_title }} {% endif %} {% include 'snippets/stars.html' with rating=status.rating %} @@ -87,7 +87,7 @@ {% include 'snippets/book_titleby.html' with book=status.book %} {% endif %} {% elif status.mention_books %} - {{ status.mention_books.first|title }} + {{ status.mention_books.first|book_title }} {% endif %} diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index f828397e..68befa54 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -18,7 +18,7 @@ def get_user_identifier(user): return user.localname if user.localname else user.username -@register.filter(name="title") +@register.filter(name="book_title") def get_title(book): """display the subtitle if the title is short""" if not book: diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 92f2c498..ff835631 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -63,7 +63,7 @@ urlpatterns = [ ), re_path( r"^settings/announcements/(?P\d+)/??$", - views.Announcements.as_view(), + views.Announcement.as_view(), name="settings-announcements", ), re_path( diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 99fedf36..cd0162b8 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -1,5 +1,5 @@ """ make sure all our nice views are available """ -from .announcements import Announcements +from .announcements import Announcements, Announcement from .authentication import Login, Register, Logout from .author import Author, EditAuthor from .block import Block, unblock diff --git a/bookwyrm/views/announcements.py b/bookwyrm/views/announcements.py index 318cf856..79e50da9 100644 --- a/bookwyrm/views/announcements.py +++ b/bookwyrm/views/announcements.py @@ -1,5 +1,6 @@ """ make announcements """ from django.contrib.auth.decorators import login_required, permission_required +from django.shortcuts import get_object_or_404 from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View @@ -29,8 +30,40 @@ class Announcements(View): form = forms.AnnouncementForm(request.POST) if form.is_valid(): form.save() + # reset the create form + form = forms.AnnouncementForm() data = { "announcements": models.Announcement.objects.all(), - "form": forms.AnnouncementForm(), + "form": form, } return TemplateResponse(request, "settings/announcements.html", data) + + +@method_decorator(login_required, name="dispatch") +@method_decorator( + permission_required("bookwyrm.edit_instance_settings", raise_exception=True), + name="dispatch", +) +class Announcement(View): + """delete or edit an announcement""" + + def get(self, request, announcement_id): + """view announcement""" + announcement = get_object_or_404(models.Announcement, id=announcement_id) + data = { + "announcement": announcement, + "form": forms.AnnouncementForm(instance=announcement), + } + return TemplateResponse(request, "settings/announcement.html", data) + + def post(self, request, announcement_id): + """edit the site settings""" + announcement = get_object_or_404(models.Announcement, id=announcement_id) + form = forms.AnnouncementForm(request.POST, instance=announcement) + if form.is_valid(): + form.save() + data = { + "announcements": models.Announcement.objects.all(), + "form": form, + } + return TemplateResponse(request, "settings/announcement.html", data)