111 lines
3.4 KiB
Python
Executable File
111 lines
3.4 KiB
Python
Executable File
import django_tables2 as tables
|
|
from django_tables2.utils import A
|
|
|
|
from .models import Long, LongSeries
|
|
|
|
from django.utils.html import format_html
|
|
|
|
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("".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.first()
|
|
|
|
if obj is None:
|
|
return "None"
|
|
|
|
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 LongTable(tables.Table):
|
|
edit = tables.LinkColumn(
|
|
"longs:long_update", text="Edit", args=[A("pk")], orderable=False
|
|
)
|
|
view = tables.LinkColumn(
|
|
"longs:long_detail", text="View", args=[A("pk")], orderable=False
|
|
)
|
|
clone = tables.LinkColumn(
|
|
"longs:long_clone", text="Clone", args=[A("pk")], orderable=False
|
|
)
|
|
delete = tables.LinkColumn(
|
|
"longs:long_delete", text="Delete", args=[A("pk")], orderable=False
|
|
)
|
|
series = LongImageColumn("Images", orderable=False)
|
|
|
|
#series = tables.ManyToManyColumn(verbose_name="Exams")
|
|
exams = tables.ManyToManyColumn(verbose_name="Exams")
|
|
|
|
class Meta:
|
|
model = Long
|
|
template_name = "django_tables2/bootstrap4.html"
|
|
fields = ("created_date", "author")
|
|
sequence = ("view", "series", "exams")
|
|
|
|
class PopupLinkColumn(tables.Column):
|
|
def render(self, value):
|
|
return format_html("<span>test: {}<span>", value)
|
|
obj = value.first()
|
|
|
|
if obj is None:
|
|
return format_html("<span>No image<span>")
|
|
|
|
return obj.get_thumbnail()[0]
|
|
|
|
def create_link(test):
|
|
print(test)
|
|
return "Hello"
|
|
|
|
class LongSeriesTable(tables.Table):
|
|
edit = tables.LinkColumn(
|
|
"longs:long_series_update", text="Edit", args=[A("pk")], orderable=False
|
|
)
|
|
view = tables.LinkColumn(
|
|
"longs:long_series_detail", text="View", args=[A("pk")], orderable=False
|
|
)
|
|
popup = tables.Column(empty_values=(), orderable=False)
|
|
|
|
images = LongSeriesImageColumn("Images", orderable=False)
|
|
|
|
delete = tables.LinkColumn(
|
|
"longs:long_series_delete", text="Delete", args=[A("pk")], orderable=False
|
|
)
|
|
|
|
class Meta:
|
|
model = LongSeries
|
|
template_name = "django_tables2/bootstrap4.html"
|
|
fields = ("modality", "examination", "long", "description", "author")
|
|
sequence = ("view", "popup", "images")
|
|
|
|
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) |