diff --git a/bookwyrm/templates/settings/themes.html b/bookwyrm/templates/settings/themes.html index e3035b2f..d3dac804 100644 --- a/bookwyrm/templates/settings/themes.html +++ b/bookwyrm/templates/settings/themes.html @@ -123,8 +123,12 @@ {{ theme.name }} {{ theme.path }} -
- + + {% csrf_token %} +
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index bef6786d..415af912 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -87,6 +87,11 @@ urlpatterns = [ ), re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"), re_path(r"^settings/themes/?$", views.Themes.as_view(), name="settings-themes"), + re_path( + r"^settings/themes/(?P\d+)/delete/?$", + views.delete_theme, + name="settings-themes-delete", + ), re_path( r"^settings/announcements/?$", views.Announcements.as_view(), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 675221cb..957a0f6e 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -21,7 +21,7 @@ from .admin.reports import ( moderator_delete_user, ) from .admin.site import Site -from .admin.themes import Themes +from .admin.themes import Themes, delete_theme from .admin.user_admin import UserAdmin, UserAdminList # user preferences diff --git a/bookwyrm/views/admin/themes.py b/bookwyrm/views/admin/themes.py index c1eacf44..12b449af 100644 --- a/bookwyrm/views/admin/themes.py +++ b/bookwyrm/views/admin/themes.py @@ -2,9 +2,11 @@ from django.contrib.auth.decorators import login_required, permission_required from django.contrib.staticfiles.utils import get_files from django.contrib.staticfiles.storage import StaticFilesStorage +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 +from django.views.decorators.http import require_POST from bookwyrm import forms, models @@ -46,3 +48,12 @@ def get_view_data(): "choices": [c for c in choices if c not in current and c[-5:] == ".scss"], "theme_form": forms.ThemeForm(), } + + +@require_POST +@permission_required("bookwyrm.edit_instance_settings", raise_exception=True) +# pylint: disable=unused-argument +def delete_theme(request, theme_id): + """Remove a theme""" + get_object_or_404(models.Theme, id=theme_id).delete() + return redirect("settings-themes")