Implement selection-enabled table base class and update QuestionTable to inherit from it
This commit is contained in:
@@ -12,6 +12,28 @@ from generic.models import CidUser, Examination, Supervisor, findMiddle
|
|||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
# Generic selection-enabled table base class.
|
||||||
|
# Inherit from this class to automatically get a selection checkbox
|
||||||
|
# column (input name="selection") and table attrs that client-side
|
||||||
|
# scripts can use to find selectable tables.
|
||||||
|
class SelectionTable(tables.Table):
|
||||||
|
# Provide a default selection checkbox column. Subclasses that wish to
|
||||||
|
# customise can override this attribute.
|
||||||
|
selection = tables.CheckBoxColumn(
|
||||||
|
accessor="pk",
|
||||||
|
orderable=False,
|
||||||
|
attrs={
|
||||||
|
'th': {'class': 'selection-col'},
|
||||||
|
'td': {'class': 'selection-col'},
|
||||||
|
'input': {'name': 'selection'},
|
||||||
|
},
|
||||||
|
verbose_name=''
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
# Defaults: add js-row-selectable class so client-side code can
|
||||||
|
# locate tables that support row selection.
|
||||||
|
attrs = {"class": "table js-row-selectable", "data-selection-name": "selection"}
|
||||||
|
|
||||||
class SingleImageColumn(tables.Column):
|
class SingleImageColumn(tables.Column):
|
||||||
def render(self, value):
|
def render(self, value):
|
||||||
|
|||||||
+6
-4
@@ -6,16 +6,18 @@ from .models import Question, UserAnswer
|
|||||||
|
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
|
|
||||||
|
from generic.tables import SelectionTable
|
||||||
|
|
||||||
class QuestionTable(tables.Table):
|
|
||||||
|
class QuestionTable(SelectionTable):
|
||||||
def get_view_cell(record):
|
def get_view_cell(record):
|
||||||
if record.open_access:
|
if record.open_access:
|
||||||
return format_html(f"""<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-opencollective" viewBox="0 0 16 16">
|
return format_html("""<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-opencollective" viewBox="0 0 16 16">
|
||||||
<path fill-opacity=".4" d="M12.995 8.195c0 .937-.312 1.912-.78 2.693l1.99 1.99c.976-1.327 1.6-2.966 1.6-4.683 0-1.795-.624-3.434-1.561-4.76l-2.068 2.028c.468.781.78 1.679.78 2.732h.04Z"/>
|
<path fill-opacity=".4" d="M12.995 8.195c0 .937-.312 1.912-.78 2.693l1.99 1.99c.976-1.327 1.6-2.966 1.6-4.683 0-1.795-.624-3.434-1.561-4.76l-2.068 2.028c.468.781.78 1.679.78 2.732h.04Z"/>
|
||||||
<path d="M8 13.151a4.995 4.995 0 1 1 0-9.99c1.015 0 1.951.273 2.732.82l1.95-2.03a7.805 7.805 0 1 0 .04 12.449l-1.951-2.03a5.072 5.072 0 0 1-2.732.781z"/>
|
<path d="M8 13.151a4.995 4.995 0 1 1 0-9.99c1.015 0 1.951.273 2.732.82l1.95-2.03a7.805 7.805 0 1 0 .04 12.449l-1.951-2.03a5.072 5.072 0 0 1-2.732.781z"/>
|
||||||
</svg> View""")
|
</svg> View""")
|
||||||
else:
|
else:
|
||||||
return f'View'
|
return 'View'
|
||||||
#edit = tables.LinkColumn(
|
#edit = tables.LinkColumn(
|
||||||
# "sbas:sbas_question_update", text="Edit", args=[A("pk")], orderable=False
|
# "sbas:sbas_question_update", text="Edit", args=[A("pk")], orderable=False
|
||||||
#)
|
#)
|
||||||
@@ -27,7 +29,7 @@ class QuestionTable(tables.Table):
|
|||||||
#)
|
#)
|
||||||
#exams = tables.ManyToManyColumn(verbose_name="Exams")
|
#exams = tables.ManyToManyColumn(verbose_name="Exams")
|
||||||
|
|
||||||
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
|
#selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
|
||||||
|
|
||||||
stem = tables.Column()
|
stem = tables.Column()
|
||||||
answers = tables.TemplateColumn("<ol type='A'><li>{{ record.a_answer|safe}}</li><li>{{ record.b_answer|safe}}</li><li>{{ record.c_answer|safe}}</li><li>{{ record.d_answer|safe}}</li><li>{{ record.e_answer|safe}}</li></ol>")
|
answers = tables.TemplateColumn("<ol type='A'><li>{{ record.a_answer|safe}}</li><li>{{ record.b_answer|safe}}</li><li>{{ record.c_answer|safe}}</li><li>{{ record.d_answer|safe}}</li><li>{{ record.e_answer|safe}}</li></ol>")
|
||||||
|
|||||||
Reference in New Issue
Block a user