286 lines
8.6 KiB
Python
286 lines
8.6 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, Examination
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
class SingleImageColumn(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 BlockImageColumn(tables.Column):
|
|
def render(self, value):
|
|
blocks = []
|
|
for obj in value.all():
|
|
blocks.append(obj.get_block())
|
|
return format_html(
|
|
"""<span class='multi-image-block'>
|
|
{}
|
|
</span>""".format("".join(blocks))
|
|
)
|
|
|
|
class SeriesImageColumn(tables.Column):
|
|
def render(self, value):
|
|
obj = value.first()
|
|
|
|
if obj is None:
|
|
return "None"
|
|
|
|
image_object = obj.image
|
|
try:
|
|
thumbnailer = get_thumbnailer(image_object)
|
|
return format_html(
|
|
'<img src="/media/{}" /><br/>[{}]',
|
|
thumbnailer["exam-list"],
|
|
value.count(),
|
|
)
|
|
except InvalidImageFormatError:
|
|
return format_html(
|
|
'<span title="{}">Invalid image url<span><br/>[{}]',
|
|
image_object,
|
|
value.count(),
|
|
)
|
|
|
|
class FirstImageColumn(tables.Column):
|
|
def render(self, value):
|
|
obj = value.all()
|
|
|
|
if not obj:
|
|
return format_html('<span>No image<span>')
|
|
|
|
image_object = obj[0].image
|
|
try:
|
|
thumbnailer = get_thumbnailer(image_object)
|
|
return format_html('<img src="/media/{}" />', thumbnailer["exam-list"])
|
|
except InvalidImageFormatError:
|
|
return format_html('<span title="{}">Invalid image url<span>', image_object)
|
|
|
|
|
|
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
|
|
)
|
|
|
|
# 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")
|
|
group = tables.Column(linkify=True)
|
|
|
|
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 __init__(self, data=None, *args, **kwargs):
|
|
super().__init__(
|
|
data.prefetch_related("group"),
|
|
*args,
|
|
**kwargs,
|
|
)
|
|
|
|
def render_emails(self, value, record):
|
|
print(self)
|
|
if record.supervisor is not None:
|
|
return format_html("""{}\n[{}]""", record.email, record.supervisor.email)
|
|
else:
|
|
return format_html(record.email)
|
|
|
|
|
|
class CidUserExamTable(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
|
|
)
|
|
|
|
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 __init__(self, data=None, *args, **kwargs):
|
|
super().__init__(
|
|
data.prefetch_related(
|
|
"physics_exams",
|
|
"rapid_exams",
|
|
"sba_exams",
|
|
"anatomy_exams",
|
|
"longs_exams",
|
|
"group",
|
|
),
|
|
*args,
|
|
**kwargs,
|
|
)
|
|
|
|
def render_emails(self, value, record):
|
|
if record.supervisor is not None:
|
|
return format_html("""{}\n[{}]""", record.email, record.supervisor.email)
|
|
else:
|
|
return format_html(record.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)
|
|
|
|
|
|
class UserUserTable(tables.Table):
|
|
# edit = tables.LinkColumn(
|
|
# "anatomy:anatomy_question_update", text="Edit", args=[A("pk")], orderable=False
|
|
# )
|
|
|
|
user = tables.Column(
|
|
linkify={"viewname": "account_profile", "args": [A("username")]},
|
|
orderable=True,
|
|
verbose_name="User",
|
|
empty_values=(),
|
|
)
|
|
|
|
supervisor = tables.Column(
|
|
linkify={
|
|
"viewname": "generic:supervisor_detail",
|
|
"args": [A("userprofile__supervisor__pk")],
|
|
},
|
|
orderable=True,
|
|
verbose_name="Supervisor",
|
|
accessor=A("userprofile__supervisor"),
|
|
)
|
|
|
|
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
|
|
|
|
edit = tables.Column(
|
|
empty_values=(),
|
|
linkify={"viewname": "account_update", "args": [A("username")]},
|
|
orderable=True,
|
|
verbose_name="Edit",
|
|
)
|
|
|
|
user_groups = tables.ManyToManyColumn(verbose_name="Groups", linkify_item=True)
|
|
|
|
date_joined = tables.DateTimeColumn(format="Y/m/d")
|
|
|
|
class Meta:
|
|
model = User
|
|
template_name = "django_tables2/bootstrap4.html"
|
|
fields = (
|
|
# "cid",
|
|
# "userprofile",
|
|
"userprofile__grade",
|
|
"date_joined",
|
|
# "user_groups",
|
|
# "userprofile.supervisor",
|
|
# "email",
|
|
)
|
|
sequence = (
|
|
"user",
|
|
"userprofile__grade",
|
|
"supervisor",
|
|
"user_groups",
|
|
"date_joined",
|
|
"edit",
|
|
)
|
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
super().__init__(
|
|
data.prefetch_related(
|
|
"userprofile",
|
|
"user_groups",
|
|
"userprofile__grade",
|
|
"supervisor",
|
|
),
|
|
*args,
|
|
**kwargs,
|
|
)
|
|
|
|
# This should be avoidable?
|
|
def render_edit(self, value, record):
|
|
return "Edit"
|
|
|
|
def render_user(self, value, record):
|
|
return format_html(
|
|
"{} {}<br/>{}<br/>{}",
|
|
record.first_name,
|
|
record.last_name,
|
|
record.username,
|
|
record.email,
|
|
)
|
|
|
|
class ExaminationTable(tables.Table):
|
|
examination = tables.Column(
|
|
linkify=("generic:examination_detail", {"pk": tables.A("pk")}),
|
|
verbose_name="Condition",
|
|
)
|
|
|
|
#edit = tables.LinkColumn(
|
|
# "generic:examination_update", text="Edit", args=[A("pk")], orderable=False
|
|
#)
|
|
delete = tables.LinkColumn(
|
|
"generic:examination_delete", text="Delete", args=[A("pk")], orderable=False
|
|
)
|
|
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
|
|
|
|
# synonym = tables.ManyToManyColumn(verbose_name="Synonyms")
|
|
#synonym = tables.Column(empty_values=())
|
|
#parent = tables.ManyToManyColumn(verbose_name="Parents")
|
|
|
|
class Meta:
|
|
model = Examination
|
|
template_name = "django_tables2/bootstrap4.html"
|
|
#fields = ("primary", "subspecialty")
|
|
sequence = ("examination",)
|