Remove title from QuestionTable sequence and enhance render_stem method to include title in output

This commit is contained in:
Ross
2025-10-20 13:08:06 +01:00
parent 4a3a089941
commit 272c3381e1
+11 -2
View File
@@ -39,7 +39,7 @@ class QuestionTable(tables.Table):
"category", "category",
"author", "author",
) )
sequence = ("view","title", "stem", "answers")#, "exams") sequence = ("view", "stem", "answers")#, "exams")
attrs = {"class": "table row-selector"} attrs = {"class": "table row-selector"}
def __init__(self, data=None, *args, **kwargs): def __init__(self, data=None, *args, **kwargs):
@@ -51,7 +51,16 @@ class QuestionTable(tables.Table):
**kwargs, **kwargs,
) )
def render_stem(self, value): def render_stem(self, value, record=None, **kwargs):
"""Render the stem, optionally with a title from the record.
Some versions of django-tables2 may call the render method without
passing a `record`; guard for that and fall back to rendering the
value only.
"""
title = getattr(record, "title", None) if record is not None else None
if title:
return format_html("<h5>{}</h5>{}", title, mark_safe(value))
return mark_safe(value) return mark_safe(value)