tidy up table image dlocks

This commit is contained in:
Ross
2023-06-12 12:34:38 +01:00
parent e0f0c7619a
commit d1ba8c87dc
10 changed files with 66 additions and 154 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

+3 -11
View File
@@ -1,6 +1,8 @@
import django_tables2 as tables
from django_tables2.utils import A
from generic.tables import SingleImageColumn
from .models import AnatomyQuestion, UserAnswer
from django.utils.html import format_html
@@ -11,16 +13,6 @@ from easy_thumbnails.exceptions import InvalidImageFormatError
#from generic.tables import UserAnswerTable
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 AnatomyQuestionTable(tables.Table):
edit = tables.LinkColumn(
"anatomy:anatomy_question_update", text="Edit", args=[A("pk")], orderable=False
@@ -28,7 +20,7 @@ class AnatomyQuestionTable(tables.Table):
view = tables.LinkColumn(
"anatomy:question_detail", text="View", args=[A("pk")], orderable=False
)
image = ImageColumn("image", orderable=False)
image = SingleImageColumn("image", orderable=False)
# clone = tables.LinkColumn('anatomy:anatomy_question_clone',
# text='Clone',
# args=[A('pk')],
+2 -48
View File
@@ -1,6 +1,8 @@
import django_tables2 as tables
from django_tables2.utils import A
from generic.tables import SeriesImageColumn
from .models import (
Case,
Condition,
@@ -19,53 +21,7 @@ from easy_thumbnails.files import get_thumbnailer
from easy_thumbnails.exceptions import InvalidImageFormatError
class AtlasImageColumn(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 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 CaseTable(tables.Table):
@@ -81,7 +37,6 @@ class CaseTable(tables.Table):
delete = tables.LinkColumn(
"atlas:case_delete", text="Delete", args=[A("pk")], orderable=False
)
#series = AtlasImageColumn("Images", orderable=False)
#differential = tables.ManyToManyColumn(verbose_name="Differential")
@@ -329,7 +284,6 @@ class CaseCollectionTable(tables.Table):
delete = tables.LinkColumn(
"atlas:collection_delete", text="Delete", args=[A("pk")], orderable=False
)
#series = AtlasImageColumn("Images", orderable=False)
#differential = tables.ManyToManyColumn(verbose_name="Differential")
+2 -1
View File
@@ -194,6 +194,7 @@ class SeriesBase(models.Model):
else:
# This is a mess...
return format_html('", "'.join(images))
def get_thumbnail(self):
images = self.images.all()
@@ -205,7 +206,7 @@ class SeriesBase(models.Model):
thumbnailer = get_thumbnailer(img)
thumbnail = thumbnailer["exam-list"]
except InvalidImageFormatError:
return format_html('<span title="{}">Invalid image url<span>', img), len(
return format_html('<img title="{}" src="/static/not-found-image.jpg" />', img), len(
images
)
return format_html('<img src="/media/{}" />', thumbnail), len(images)
+48 -1
View File
@@ -12,7 +12,7 @@ from generic.models import CidUser
from django.contrib.auth.models import User
class ImageColumn(tables.Column):
class SingleImageColumn(tables.Column):
def render(self, value):
try:
thumbnailer = get_thumbnailer(value)
@@ -20,6 +20,53 @@ class ImageColumn(tables.Column):
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(
+4 -49
View File
@@ -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
-15
View File
@@ -6,21 +6,6 @@ from .models import Question, UserAnswer
from django.utils.html import format_html
# from easy_thumbnails.files import get_thumbnailer
# from easy_thumbnails.exceptions import InvalidImageFormatError
# from generic.tables import UserAnswerTable
# 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 QuestionTable(tables.Table):
# edit = tables.LinkColumn(
+4
View File
@@ -579,6 +579,10 @@ td.user-answer-score-2.rapid-ans::after {
color: darkblue
}
.series-block img {
max-width: 100%;
}
.sortable-placeholder {
border: 4px solid purple;
+3 -14
View File
@@ -1,6 +1,8 @@
import django_tables2 as tables
from django_tables2.utils import A
from generic.tables import FirstImageColumn
from .models import Rapid, UserAnswer
from django.utils.html import format_html
@@ -10,19 +12,6 @@ from easy_thumbnails.files import get_thumbnailer
from easy_thumbnails.exceptions import InvalidImageFormatError
class ImageColumn(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 RapidTable(tables.Table):
@@ -42,7 +31,7 @@ class RapidTable(tables.Table):
text='Delete',
args=[A('pk')],
orderable=False)
images = ImageColumn("images", orderable=False)
images = FirstImageColumn("images", orderable=False)
exams = tables.ManyToManyColumn(verbose_name="Exams")
-15
View File
@@ -6,21 +6,6 @@ from .models import Question, UserAnswer
from django.utils.html import format_html
#from easy_thumbnails.files import get_thumbnailer
#from easy_thumbnails.exceptions import InvalidImageFormatError
#from generic.tables import UserAnswerTable
#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 QuestionTable(tables.Table):
#edit = tables.LinkColumn(