90 lines
2.7 KiB
Python
90 lines
2.7 KiB
Python
|
|
import django_tables2 as tables
|
|
from django_tables2.utils import A
|
|
|
|
from generic.tables import FirstImageColumn
|
|
|
|
from .models import Question, UserAnswer
|
|
|
|
from django.utils.html import format_html
|
|
|
|
from easy_thumbnails.files import get_thumbnailer
|
|
|
|
from easy_thumbnails.exceptions import InvalidImageFormatError
|
|
|
|
|
|
|
|
|
|
class QuestionTable(tables.Table):
|
|
edit = tables.LinkColumn('shorts:question_update',
|
|
text='Edit',
|
|
args=[A('pk')],
|
|
orderable=False)
|
|
view = tables.LinkColumn('shorts:question_detail',
|
|
text='View',
|
|
args=[A('pk')],
|
|
orderable=False)
|
|
clone = tables.LinkColumn('shorts:question_clone',
|
|
text='Clone',
|
|
args=[A('pk')],
|
|
orderable=False)
|
|
delete = tables.LinkColumn('shorts:question_delete',
|
|
text='Delete',
|
|
args=[A('pk')],
|
|
orderable=False)
|
|
images = FirstImageColumn("images", orderable=False)
|
|
|
|
exams = tables.ManyToManyColumn(verbose_name="Exams")
|
|
|
|
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
|
|
|
|
class Meta:
|
|
model = Question
|
|
template_name = "django_tables2/bootstrap4.html"
|
|
fields = ("normal", "examination",
|
|
#"site",
|
|
"created_date", "open_access", "author")
|
|
sequence = ("view", "images", "exams")
|
|
order_by = "-created_date"
|
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
super().__init__(
|
|
data.prefetch_related(
|
|
"examination", "images", "exams", "author"
|
|
),
|
|
*args,
|
|
**kwargs,
|
|
)
|
|
|
|
class QuestionUserAnswerTable(tables.Table):
|
|
select = tables.CheckBoxColumn(accessor=("pk"))
|
|
delete = tables.LinkColumn(
|
|
"shorts:user_answer_delete", text="Delete", args=[A("pk")], orderable=False
|
|
)
|
|
view = tables.LinkColumn('shorts:user_answer_view',
|
|
text='View',
|
|
args=[A('pk')],
|
|
orderable=False)
|
|
class Meta:
|
|
model = UserAnswer
|
|
template_name = "django_tables2/bootstrap4.html"
|
|
fields = (
|
|
"cid",
|
|
"user",
|
|
"question",
|
|
"answer",
|
|
#"answer_compare",
|
|
"exam",
|
|
"created",
|
|
"updated",
|
|
)
|
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
super().__init__(
|
|
data.prefetch_related(
|
|
"exam", "question"
|
|
),
|
|
*args,
|
|
**kwargs,
|
|
)
|
|
|