Files
penracourses/generic/tables.py
T
Ross 550d74c7ee .
2022-01-06 14:00:14 +00:00

68 lines
2.3 KiB
Python

import django_tables2 as tables
from django_tables2.utils import A
from django.utils.html import format_html
from easy_thumbnails.files import get_thumbnailer
from easy_thumbnails.exceptions import InvalidImageFormatError
from generic.models import CidUser
class ImageColumn(tables.Column):
def render(self, value):
try:
thumbnailer = get_thumbnailer(value)
return format_html('<img src="/media/{}" />', thumbnailer["exam-list"])
except InvalidImageFormatError:
return format_html('<span title="{}">Invalid image url<span>', value)
class CidUserTable(tables.Table):
# edit = tables.LinkColumn(
# "anatomy:anatomy_question_update", text="Edit", args=[A("pk")], orderable=False
# )
cid = tables.LinkColumn(
"cid_scores", args=[A("cid"), A("passcode")], orderable=True
)
# image = ImageColumn("image", orderable=False)
# clone = tables.LinkColumn('anatomy:anatomy_question_clone',
# text='Clone',
# args=[A('pk')],
# orderable=False)
physics_exams = tables.ManyToManyColumn(verbose_name="Physics Exams")
rapid_exams = tables.ManyToManyColumn(verbose_name="Rapid Exams")
sba_exams = tables.ManyToManyColumn(verbose_name="SBA Exams")
longs_exams = tables.ManyToManyColumn(verbose_name="Long Exams")
anatomy_exams = tables.ManyToManyColumn(verbose_name="Anatomy Exams")
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
emails = tables.Column(empty_values=(), orderable=False)
edit = tables.LinkColumn(
"generic:update_cid", text="Edit", args=[A("pk")], orderable=True
)
class Meta:
model = CidUser
template_name = "django_tables2/bootstrap4.html"
fields = (
# "cid",
"passcode",
"active",
"group",
"internal_candidate",
# "email",
)
sequence = ("cid", "passcode", "active", "internal_candidate", "emails")
def render_emails(self, value, record):
print(self)
return format_html("""{}\n[{}]""", record.email, record.supervisor_email)
# def render_cid(self, value, record):
# return format_html("""<a href="#" onclick="return window.create_popup_window('/longs/series/{}', 'Series')" >Popup</a>""", record.pk)