Delete themes

This commit is contained in:
Mouse Reeve 2022-02-28 09:54:07 -08:00
parent 106ef2e3a4
commit c82042f506
4 changed files with 23 additions and 3 deletions

View file

@ -123,8 +123,12 @@
<td>{{ theme.name }}</td> <td>{{ theme.name }}</td>
<td><code>{{ theme.path }}</code></td> <td><code>{{ theme.path }}</code></td>
<td> <td>
<form> <form method="POST" action="{% url 'settings-themes-delete' theme.id %}">
<button type="submit" class="button is-danger is-light">{% trans "Remove theme" %}</button> {% csrf_token %}
<button type="submit" class="button is-danger is-light is-small">
<span class="icon icon-x" aria-hideen="true"></span>
<span>{% trans "Remove theme" %}</span>
</button>
</form> </form>
</td> </td>
</tr> </tr>

View file

@ -87,6 +87,11 @@ urlpatterns = [
), ),
re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"), 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/?$", views.Themes.as_view(), name="settings-themes"),
re_path(
r"^settings/themes/(?P<theme_id>\d+)/delete/?$",
views.delete_theme,
name="settings-themes-delete",
),
re_path( re_path(
r"^settings/announcements/?$", r"^settings/announcements/?$",
views.Announcements.as_view(), views.Announcements.as_view(),

View file

@ -21,7 +21,7 @@ from .admin.reports import (
moderator_delete_user, moderator_delete_user,
) )
from .admin.site import Site from .admin.site import Site
from .admin.themes import Themes from .admin.themes import Themes, delete_theme
from .admin.user_admin import UserAdmin, UserAdminList from .admin.user_admin import UserAdmin, UserAdminList
# user preferences # user preferences

View file

@ -2,9 +2,11 @@
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.staticfiles.utils import get_files from django.contrib.staticfiles.utils import get_files
from django.contrib.staticfiles.storage import StaticFilesStorage from django.contrib.staticfiles.storage import StaticFilesStorage
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View from django.views import View
from django.views.decorators.http import require_POST
from bookwyrm import forms, models 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"], "choices": [c for c in choices if c not in current and c[-5:] == ".scss"],
"theme_form": forms.ThemeForm(), "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")