more Long improvements
This commit is contained in:
+58
-16
@@ -4,6 +4,7 @@ from django_tables2.utils import A
|
||||
from .models import Long, LongSeries, UserAnswer
|
||||
|
||||
from django.utils.html import format_html
|
||||
from django.db.models import Prefetch
|
||||
|
||||
from easy_thumbnails.files import get_thumbnailer
|
||||
|
||||
@@ -12,10 +13,12 @@ from easy_thumbnails.exceptions import InvalidImageFormatError
|
||||
|
||||
class LongImageColumn(tables.Column):
|
||||
def render(self, value):
|
||||
blocks =[]
|
||||
blocks = []
|
||||
for obj in value.all():
|
||||
blocks.append(obj.get_block())
|
||||
return format_html("<span class='multi-image-block'>{}</span>".format("".join(blocks)))
|
||||
return format_html(
|
||||
"<span class='multi-image-block'>{}</span>".format("".join(blocks))
|
||||
)
|
||||
|
||||
obj = value.first()
|
||||
|
||||
@@ -42,9 +45,17 @@ class LongSeriesImageColumn(tables.Column):
|
||||
image_object = obj[0].image
|
||||
try:
|
||||
thumbnailer = get_thumbnailer(image_object)
|
||||
return format_html('<img src="/media/{}" /><br/>[{}]', thumbnailer["exam-list"], value.count())
|
||||
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())
|
||||
return format_html(
|
||||
'<span title="{}">Invalid image url<span><br/>[{}]',
|
||||
image_object,
|
||||
value.count(),
|
||||
)
|
||||
|
||||
|
||||
class LongTable(tables.Table):
|
||||
@@ -62,7 +73,7 @@ class LongTable(tables.Table):
|
||||
)
|
||||
series = LongImageColumn("Images", orderable=False)
|
||||
|
||||
#series = tables.ManyToManyColumn(verbose_name="Exams")
|
||||
# series = tables.ManyToManyColumn(verbose_name="Exams")
|
||||
exams = tables.ManyToManyColumn(verbose_name="Exams")
|
||||
|
||||
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
|
||||
@@ -76,12 +87,19 @@ class LongTable(tables.Table):
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
super().__init__(
|
||||
data.prefetch_related(
|
||||
"series", "author", "exams", "series__images", "series__examination", "series__plane", "series__contrast"
|
||||
"series",
|
||||
"author",
|
||||
"exams",
|
||||
"series__images",
|
||||
"series__examination",
|
||||
"series__plane",
|
||||
"series__contrast",
|
||||
),
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
class PopupLinkColumn(tables.Column):
|
||||
def render(self, value):
|
||||
return format_html("<span>test: {}<span>", value)
|
||||
@@ -120,7 +138,14 @@ class LongSeriesTable(tables.Table):
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
super().__init__(
|
||||
data.prefetch_related(
|
||||
"long", "long__series", "images", "author", "examination", "plane", "contrast", "modality"
|
||||
"long",
|
||||
"long__series",
|
||||
"images",
|
||||
"author",
|
||||
"examination",
|
||||
"plane",
|
||||
"contrast",
|
||||
"modality",
|
||||
),
|
||||
*args,
|
||||
**kwargs,
|
||||
@@ -128,17 +153,21 @@ class LongSeriesTable(tables.Table):
|
||||
|
||||
def render_popup(self, value, record):
|
||||
print(self)
|
||||
return format_html("""<a href="#" onclick="return window.create_popup_window('/longs/series/{}', 'Series')" >Popup</a>""", record.pk)
|
||||
return format_html(
|
||||
"""<a href="#" onclick="return window.create_popup_window('/longs/series/{}', 'Series')" >Popup</a>""",
|
||||
record.pk,
|
||||
)
|
||||
|
||||
|
||||
class UserAnswerTable(tables.Table):
|
||||
select = tables.CheckBoxColumn(accessor=("pk"))
|
||||
delete = tables.LinkColumn(
|
||||
"longs:user_answer_delete", text="Delete", args=[A("pk")], orderable=False
|
||||
)
|
||||
view = tables.LinkColumn('longs:user_answer_view',
|
||||
text='View',
|
||||
args=[A('pk')],
|
||||
orderable=False)
|
||||
view = tables.LinkColumn(
|
||||
"longs:user_answer_view", text="View", args=[A("pk")], orderable=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = UserAnswer
|
||||
template_name = "django_tables2/bootstrap4.html"
|
||||
@@ -146,11 +175,24 @@ class UserAnswerTable(tables.Table):
|
||||
"cid",
|
||||
"question",
|
||||
"score",
|
||||
#"normal",
|
||||
#"answer",
|
||||
#"answer_compare",
|
||||
# "normal",
|
||||
# "answer",
|
||||
# "answer_compare",
|
||||
"exam",
|
||||
"created",
|
||||
"updated",
|
||||
)
|
||||
|
||||
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
super().__init__(
|
||||
data.prefetch_related(
|
||||
Prefetch(
|
||||
"question", # "question__exams"#, "author", "exams", "series__images", "series__examination", "series__plane", "series__contrast"
|
||||
#queryset=Long.objects.select_related().prefetch_related(
|
||||
# Prefetch("exams")
|
||||
#),
|
||||
)
|
||||
),
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user