forked from mirrors/bookwyrm
Delete announcements
This commit is contained in:
parent
a415991e96
commit
2e193aa3c6
5 changed files with 35 additions and 8 deletions
|
@ -9,8 +9,18 @@
|
|||
|
||||
{% block edit-button %}
|
||||
{% trans "Edit Announcement" as button_text %}
|
||||
{% include 'snippets/toggle/open_button.html' with controls_text="edit-announcement" icon_with_text="plus" text=button_text focus="edit-announcement-header" %}
|
||||
</a>
|
||||
<div class="field has-addons">
|
||||
<div class="control">
|
||||
{% include 'snippets/toggle/open_button.html' with controls_text="edit-announcement" icon_with_text="pencil" text=button_text focus="edit-announcement-header" %}
|
||||
</div>
|
||||
<form class="control" action="{% url 'settings-announcements-delete' announcement.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="button is-danger">
|
||||
<span class="icon icon-x" aria-hidden="true"></span>
|
||||
<span>{% trans "Delete" %}</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block panel %}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
{% load humanize %}{% load i18n %}{% load utilities %}
|
||||
{% with announcement.id|uuid as uuid %}
|
||||
<aside class="notification mb-1 p-3 is-hidden transition-y"{% if not admin_mode %} data-hide="hide-announcement-{{ announcement.id }}"{% endif %}>
|
||||
<aside
|
||||
class="notification mb-1 p-3{% if not admin_mode %} is-hidden{% endif %} transition-y"
|
||||
{% if not admin_mode %}data-hide="hide-announcement-{{ announcement.id }}"{% endif %}
|
||||
>
|
||||
<div class="columns mb-0">
|
||||
<div class="column pb-0">
|
||||
{% if announcement.event_date %}
|
||||
|
|
|
@ -62,10 +62,15 @@ urlpatterns = [
|
|||
name="settings-announcements",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/announcements/(?P<announcement_id>\d+)/??$",
|
||||
r"^settings/announcements/(?P<announcement_id>\d+)/?$",
|
||||
views.Announcement.as_view(),
|
||||
name="settings-announcements",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/announcements/(?P<announcement_id>\d+)/delete/?$",
|
||||
views.delete_announcement,
|
||||
name="settings-announcements-delete",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/email-preview/?$",
|
||||
views.site.email_preview,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
""" make sure all our nice views are available """
|
||||
from .announcements import Announcements, Announcement
|
||||
from .announcements import Announcements, Announcement, delete_announcement
|
||||
from .authentication import Login, Register, Logout
|
||||
from .author import Author, EditAuthor
|
||||
from .block import Block, unblock
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
""" make announcements """
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
@ -64,7 +64,7 @@ class Announcements(View):
|
|||
name="dispatch",
|
||||
)
|
||||
class Announcement(View):
|
||||
"""delete or edit an announcement"""
|
||||
"""edit an announcement"""
|
||||
|
||||
def get(self, request, announcement_id):
|
||||
"""view announcement"""
|
||||
|
@ -76,7 +76,7 @@ class Announcement(View):
|
|||
return TemplateResponse(request, "settings/announcement.html", data)
|
||||
|
||||
def post(self, request, announcement_id):
|
||||
"""edit the site settings"""
|
||||
"""edit announcement"""
|
||||
announcement = get_object_or_404(models.Announcement, id=announcement_id)
|
||||
form = forms.AnnouncementForm(request.POST, instance=announcement)
|
||||
if form.is_valid():
|
||||
|
@ -86,3 +86,12 @@ class Announcement(View):
|
|||
"form": form,
|
||||
}
|
||||
return TemplateResponse(request, "settings/announcement.html", data)
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
|
||||
def delete_announcement(_, announcement_id):
|
||||
"""delete announcement"""
|
||||
announcement = get_object_or_404(models.Announcement, id=announcement_id)
|
||||
announcement.delete()
|
||||
return redirect("settings-announcements")
|
||||
|
|
Loading…
Reference in a new issue