Refactor HTML formatting to use mark_safe for safe rendering in various tables and models
This commit is contained in:
+7
-8
@@ -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(
|
||||
"""<span class='multi-image-block'>
|
||||
{}
|
||||
</span>""".format("".join(blocks))
|
||||
@@ -112,9 +113,7 @@ class SeriesImageColumn(tables.Column):
|
||||
images = value.all()
|
||||
|
||||
if not images:
|
||||
return format_html(
|
||||
'<span>None<span><br/>',
|
||||
)
|
||||
return mark_safe('<span>None</span><br/>')
|
||||
|
||||
obj = findMiddle(images)
|
||||
|
||||
@@ -141,7 +140,7 @@ class FirstImageColumn(tables.Column):
|
||||
obj = value.all()
|
||||
|
||||
if not obj:
|
||||
return format_html('<span>No image<span>')
|
||||
return mark_safe('<span>No image</span>')
|
||||
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user