tidy up table image dlocks
This commit is contained in:
+4
-49
@@ -1,6 +1,8 @@
|
||||
import django_tables2 as tables
|
||||
from django_tables2.utils import A
|
||||
|
||||
from generic.tables import BlockImageColumn, SeriesImageColumn
|
||||
|
||||
from .models import Long, LongSeries, UserAnswer
|
||||
|
||||
from django.utils.html import format_html
|
||||
@@ -11,53 +13,6 @@ from easy_thumbnails.files import get_thumbnailer
|
||||
from easy_thumbnails.exceptions import InvalidImageFormatError
|
||||
|
||||
|
||||
class LongImageColumn(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))
|
||||
)
|
||||
|
||||
obj = value.first()
|
||||
|
||||
if obj is None:
|
||||
return format_html("<span>No image<span>")
|
||||
|
||||
return obj.get_thumbnail()[0]
|
||||
|
||||
# image_object = obj.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 LongSeriesImageColumn(tables.Column):
|
||||
def render(self, value):
|
||||
obj = value.all()
|
||||
|
||||
if not obj:
|
||||
return "None"
|
||||
|
||||
image_object = obj[0].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 LongTable(tables.Table):
|
||||
edit = tables.LinkColumn(
|
||||
"longs:long_update", text="Edit", args=[A("pk")], orderable=False
|
||||
@@ -71,7 +26,7 @@ class LongTable(tables.Table):
|
||||
delete = tables.LinkColumn(
|
||||
"longs:long_delete", text="Delete", args=[A("pk")], orderable=False
|
||||
)
|
||||
series = LongImageColumn("Images", orderable=False)
|
||||
series = BlockImageColumn("Images", orderable=False)
|
||||
|
||||
# series = tables.ManyToManyColumn(verbose_name="Exams")
|
||||
exams = tables.ManyToManyColumn(verbose_name="Exams")
|
||||
@@ -120,7 +75,7 @@ class LongSeriesTable(tables.Table):
|
||||
)
|
||||
popup = tables.Column(empty_values=(), orderable=False)
|
||||
|
||||
images = LongSeriesImageColumn("Images", orderable=False)
|
||||
images = SeriesImageColumn("Images", orderable=False)
|
||||
|
||||
delete = tables.LinkColumn(
|
||||
"longs:long_series_delete", text="Delete", args=[A("pk")], orderable=False
|
||||
|
||||
Reference in New Issue
Block a user