Refactor HTML formatting to use mark_safe for safe rendering in various tables and models

This commit is contained in:
Ross
2026-01-28 14:28:36 +00:00
parent a61c8529ae
commit a512c2ba09
9 changed files with 54 additions and 45 deletions
+7 -6
View File
@@ -16,6 +16,7 @@ from django.urls import reverse_lazy
from django.urls.base import reverse
from django.utils import timezone
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.views.decorators.csrf import csrf_exempt
from django.core.exceptions import PermissionDenied, FieldError
@@ -850,7 +851,7 @@ def generic_exam_set_open_access(request):
# For now require the user to have edit access (ExamViews.check_user_edit_access equivalent)
# We'll do a lightweight check: if user is superuser OR user in exam.get_author_objects()
if not (request.user.is_superuser or request.user in exam.get_author_objects()):
return HttpResponse(format_html('<div class="alert alert-danger">Permission denied</div>'))
return HttpResponse(mark_safe('<div class="alert alert-danger">Permission denied</div>'))
set_val = True if request.POST.get("set_open_access") == "true" else False
@@ -1147,7 +1148,7 @@ class ExamViews(View, LoginRequiredMixin):
if request.method == "POST":
if not self.check_user_edit_access(request.user, exam_id=pk):
return HttpResponse(
format_html(
mark_safe(
'<div class="alert alert-danger" role="alert">Error toggling results published.</div>'
)
)
@@ -1163,7 +1164,7 @@ class ExamViews(View, LoginRequiredMixin):
})
else:
HttpResponse(
format_html(
mark_safe(
'<div class="alert alert-danger" role="alert">Error toggling results published.</div>'
)
)
@@ -1173,7 +1174,7 @@ class ExamViews(View, LoginRequiredMixin):
if request.method == "POST":
if not self.check_user_edit_access(request.user, exam_id=pk):
return HttpResponse(
format_html(
mark_safe(
'<div class="alert alert-danger" role="alert">Error toggling exam active.</div>'
)
)
@@ -1189,7 +1190,7 @@ class ExamViews(View, LoginRequiredMixin):
})
else:
HttpResponse(
format_html(
mark_safe(
'<div class="alert alert-danger" role="alert">Error toggling exam active.</div>'
)
)
@@ -4722,7 +4723,7 @@ def user_group_add_by_email_user(request, group_id):
res += f"<br/><div class='alert alert-warning'>Invalid emails [{','.join(invalid_emails)}]</div>"
return HttpResponse(format_html(res), content_type="text/html")
return HttpResponse(res, content_type="text/html")