diff --git a/anatomy/models.py b/anatomy/models.py index 664dce65..6797309f 100644 --- a/anatomy/models.py +++ b/anatomy/models.py @@ -191,9 +191,9 @@ class AnatomyQuestion(QuestionBase): if not unmarked_answers: return "No answers to mark" return format_html( - "{} answer unmarked: {}".format( - len(unmarked_answers), ", ".join(unmarked_answers) - ) + "{} answer unmarked: {}", + len(unmarked_answers), + ", ".join(unmarked_answers), ) def get_unmarked_user_answers(self, exam_pk: int|None = None): diff --git a/atlas/tables.py b/atlas/tables.py index 874810be..e5f15aef 100755 --- a/atlas/tables.py +++ b/atlas/tables.py @@ -19,6 +19,8 @@ from .models import ( from django.utils.html import format_html +from django.utils.safestring import mark_safe + from easy_thumbnails.files import get_thumbnailer from easy_thumbnails.exceptions import InvalidImageFormatError @@ -83,12 +85,14 @@ class CaseTable(SelectionTable): def get_view_cell(record): if record.open_access: - return format_html(f""" - - - View""") + return mark_safe( + '' + '' + '' + ' View' + ) else: - return f'View' + return 'View' def render_author(self, value): max_length = 15 # Set the maximum length for truncating individual author names @@ -108,7 +112,7 @@ class CaseTable(SelectionTable): ) ) # Join all authors with commas - return format_html(", ".join(authors)) + return mark_safe(", ".join(authors)) def render_associated_cases(self, record): links = [] @@ -130,7 +134,7 @@ class CaseTable(SelectionTable): except Case.DoesNotExist: pass if links: - return format_html(", ".join(links)) + return mark_safe(", ".join(links)) return "No associated cases" def render_collections(self, record): @@ -151,7 +155,7 @@ class CaseTable(SelectionTable): ) for collection in collections ] - return format_html(", ".join(links)) + return mark_safe(", ".join(links)) return "No collections" associated_cases = tables.Column( @@ -166,7 +170,7 @@ class CaseTable(SelectionTable): "atlas:case_update", text="Edit", args=[A("pk")], orderable=False ) view = tables.LinkColumn( - "atlas:case_detail", text=get_view_cell, args=[A("pk")], orderable=False + "atlas:case_detail", text=get_view_cell, args=[A("pk")], accessor="pk", orderable=False ) clone = tables.LinkColumn( "atlas:case_clone", text="Clone", args=[A("pk")], orderable=False @@ -199,7 +203,7 @@ class PopupLinkColumn(tables.Column): obj = value.first() if obj is None: - return format_html("No image") + return mark_safe("No image") return obj.get_thumbnail()[0] @@ -209,7 +213,7 @@ class SeriesTable(SelectionTable): "atlas:series_update", text="Edit", args=[A("pk")], orderable=False ) view = tables.LinkColumn( - "atlas:series_detail", text="View", args=[A("pk")], orderable=False + "atlas:series_detail", text="View", args=[A("pk")], accessor="pk", orderable=False ) popup = tables.Column(empty_values=(), orderable=False) @@ -290,7 +294,7 @@ class ConditionTable(SelectionTable): ) def render_synonym(self, value, record): - return format_html(record.get_synonym_link()) + return mark_safe(record.get_synonym_link()) return f"{record.get_synonym_link()}" @@ -317,7 +321,7 @@ class FindingTable(SelectionTable): def render_synonym(self, value, record): - return format_html(record.get_synonym_link()) + return mark_safe(record.get_synonym_link()) class StructureTable(SelectionTable): @@ -344,7 +348,7 @@ class StructureTable(SelectionTable): def render_synonym(self, value, record): - return format_html(record.get_synonym_link()) + return mark_safe(record.get_synonym_link()) class PresentationTable(SelectionTable): @@ -412,7 +416,7 @@ class SubspecialtyTable(SelectionTable): def render_synonym(self, value, record): - return format_html(record.get_synonym_link()) + return mark_safe(record.get_synonym_link()) return f"{record.get_synonym_link()}" @@ -432,7 +436,7 @@ class CaseCollectionTable(SelectionTable): "atlas:exam_update", text="Edit", args=[A("pk")], orderable=False ) view = tables.LinkColumn( - "atlas:collection_detail", text="View", args=[A("pk")], orderable=False + "atlas:collection_detail", text="View", args=[A("pk")], accessor="pk", orderable=False ) created = tables.DateTimeColumn(verbose_name="Created", accessor="created", orderable=True) diff --git a/generic/tables.py b/generic/tables.py index 67b1132f..e36a3288 100644 --- a/generic/tables.py +++ b/generic/tables.py @@ -3,6 +3,7 @@ import django_tables2 as tables from django_tables2.utils import A from django.utils.html import format_html +from django.utils.safestring import mark_safe from easy_thumbnails.files import get_thumbnailer @@ -85,7 +86,7 @@ class SelectionTable(tables.Table): # Also include a small data attribute so client scripts can locate the # controls by selection name if they prefer. - return format_html(html) + return mark_safe(html) class SingleImageColumn(tables.Column): def render(self, value): @@ -100,7 +101,7 @@ class BlockImageColumn(tables.Column): blocks = [] for obj in value.all(): blocks.append(obj.get_block()) - return format_html( + return mark_safe( """ {} """.format("".join(blocks)) @@ -112,9 +113,7 @@ class SeriesImageColumn(tables.Column): images = value.all() if not images: - return format_html( - 'None
', - ) + return mark_safe('None
') obj = findMiddle(images) @@ -141,7 +140,7 @@ class FirstImageColumn(tables.Column): obj = value.all() if not obj: - return format_html('No image') + return mark_safe('No image') image_object = obj[0].image try: @@ -196,7 +195,7 @@ class CidUserTable(SelectionTable): if record.supervisor is not None: return format_html("""{}\n[{}]""", record.email, record.supervisor.email) else: - return format_html(record.email) + return record.email class CidUserExamTable(SelectionTable): @@ -249,7 +248,7 @@ class CidUserExamTable(SelectionTable): if record.supervisor is not None: return format_html("""{}\n[{}]""", record.email, record.supervisor.email) else: - return format_html(record.email) + return record.email # def render_cid(self, value, record): diff --git a/generic/views.py b/generic/views.py index f4c92a23..6ceeb7a4 100644 --- a/generic/views.py +++ b/generic/views.py @@ -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('
Permission denied
')) + return HttpResponse(mark_safe('
Permission denied
')) 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( '' ) ) @@ -1163,7 +1164,7 @@ class ExamViews(View, LoginRequiredMixin): }) else: HttpResponse( - format_html( + mark_safe( '' ) ) @@ -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( '' ) ) @@ -1189,7 +1190,7 @@ class ExamViews(View, LoginRequiredMixin): }) else: HttpResponse( - format_html( + mark_safe( '' ) ) @@ -4722,7 +4723,7 @@ def user_group_add_by_email_user(request, group_id): res += f"
Invalid emails [{','.join(invalid_emails)}]
" - return HttpResponse(format_html(res), content_type="text/html") + return HttpResponse(res, content_type="text/html") diff --git a/longs/tables.py b/longs/tables.py index 6ebc55a1..c4f4651b 100755 --- a/longs/tables.py +++ b/longs/tables.py @@ -6,6 +6,7 @@ from generic.tables import BlockImageColumn, SeriesImageColumn from .models import Long, LongSeries, UserAnswer from django.utils.html import format_html +from django.utils.safestring import mark_safe from django.db.models import Prefetch from easy_thumbnails.files import get_thumbnailer @@ -61,7 +62,7 @@ class PopupLinkColumn(tables.Column): obj = value.first() if obj is None: - return format_html("No image") + return mark_safe("No image") return obj.get_thumbnail()[0] diff --git a/rad/views.py b/rad/views.py index 36295864..2ac1bd86 100644 --- a/rad/views.py +++ b/rad/views.py @@ -23,6 +23,7 @@ from django.core.exceptions import ValidationError from django.core.validators import validate_email from django.utils.html import format_html +from django.utils.safestring import mark_safe # from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required, user_passes_test @@ -1107,7 +1108,7 @@ def accounts_bulk_create(request): except Exception as error: error_text = error_text + f"

Error creating users.
{error}

" - context["error"] = format_html(error_text) + context["error"] = mark_safe(error_text) context["created_users"] = created_users if existing_users: diff --git a/rapids/models.py b/rapids/models.py index 18beb338..a7f97860 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -316,9 +316,9 @@ class Rapid(QuestionBase): if not unmarked_answers: return "No answers to mark" return format_html( - "{} answer unmarked: {}".format( - len(unmarked_answers), ", ".join(unmarked_answers) - ) + "{} answer unmarked: {}", + len(unmarked_answers), + ", ".join(unmarked_answers), ) def get_unmarked_user_answers(self, exam_pk: int | None = None, marker=None): diff --git a/sbas/tables.py b/sbas/tables.py index 6d4218fc..5af1dcc8 100644 --- a/sbas/tables.py +++ b/sbas/tables.py @@ -11,11 +11,14 @@ from generic.tables import SelectionTable class QuestionTable(SelectionTable): def get_view_cell(record): + if record.open_access: - return format_html(""" - - - View""") + return mark_safe( + """ + + + View""" + ) else: return 'View' #edit = tables.LinkColumn( diff --git a/shorts/models.py b/shorts/models.py index bf1a7e7c..88aa6d4b 100644 --- a/shorts/models.py +++ b/shorts/models.py @@ -185,9 +185,9 @@ class Question(QuestionBase): if not unmarked_answers: return "No answers to mark" return format_html( - "{} answer unmarked: {}".format( - len(unmarked_answers), ", ".join(unmarked_answers) - ) + "{} answer unmarked: {}", + len(unmarked_answers), + ", ".join(unmarked_answers), ) def get_unmarked_user_answers(self, exam_pk: int | None = None, marker=None):