Merge branch 'main' into user-migration
This commit is contained in:
commit
0276c15948
10 changed files with 158 additions and 2 deletions
|
@ -32,7 +32,7 @@ from .admin.reports import (
|
|||
moderator_delete_user,
|
||||
)
|
||||
from .admin.site import Site, Registration, RegistrationLimited
|
||||
from .admin.themes import Themes, delete_theme
|
||||
from .admin.themes import Themes, delete_theme, test_theme
|
||||
from .admin.user_admin import UserAdmin, UserAdminList, ActivateUserAdmin
|
||||
|
||||
# user preferences
|
||||
|
@ -169,3 +169,4 @@ from .annual_summary import (
|
|||
summary_revoke_key,
|
||||
)
|
||||
from .server_error import server_error
|
||||
from .permission_denied import permission_denied
|
||||
|
|
|
@ -6,6 +6,8 @@ from django.utils.decorators import method_decorator
|
|||
from django.views import View
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from sass_processor.processor import sass_processor
|
||||
|
||||
from bookwyrm import forms, models
|
||||
|
||||
|
||||
|
@ -40,6 +42,7 @@ class Themes(View):
|
|||
def get_view_data():
|
||||
"""data for view"""
|
||||
return {
|
||||
"broken_theme": models.Theme.objects.filter(loads=False).exists(),
|
||||
"themes": models.Theme.objects.all(),
|
||||
"theme_form": forms.ThemeForm(),
|
||||
}
|
||||
|
@ -52,3 +55,20 @@ def delete_theme(request, theme_id):
|
|||
"""Remove a theme"""
|
||||
get_object_or_404(models.Theme, id=theme_id).delete()
|
||||
return redirect("settings-themes")
|
||||
|
||||
|
||||
@require_POST
|
||||
@permission_required("bookwyrm.system_administration", raise_exception=True)
|
||||
# pylint: disable=unused-argument
|
||||
def test_theme(request, theme_id):
|
||||
"""Remove a theme"""
|
||||
theme = get_object_or_404(models.Theme, id=theme_id)
|
||||
|
||||
try:
|
||||
sass_processor(theme.path)
|
||||
theme.loads = True
|
||||
except Exception: # pylint: disable=broad-except
|
||||
theme.loads = False
|
||||
|
||||
theme.save()
|
||||
return redirect("settings-themes")
|
||||
|
|
15
bookwyrm/views/permission_denied.py
Normal file
15
bookwyrm/views/permission_denied.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
"""custom 403 handler to enable context processors"""
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.template.response import TemplateResponse
|
||||
|
||||
from .helpers import is_api_request
|
||||
|
||||
|
||||
def permission_denied(request, exception): # pylint: disable=unused-argument
|
||||
"""permission denied page"""
|
||||
|
||||
if request.method == "POST" or is_api_request(request):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
return TemplateResponse(request, "403.html")
|
Loading…
Add table
Add a link
Reference in a new issue