diff --git a/anatomy/static/not-found-image.jpg b/anatomy/static/not-found-image.jpg new file mode 100644 index 00000000..8dd4fee6 Binary files /dev/null and b/anatomy/static/not-found-image.jpg differ diff --git a/anatomy/tables.py b/anatomy/tables.py index 122a750c..7192bd5b 100644 --- a/anatomy/tables.py +++ b/anatomy/tables.py @@ -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('', thumbnailer["exam-list"]) - except InvalidImageFormatError: - return format_html('Invalid image url', 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')], diff --git a/atlas/tables.py b/atlas/tables.py index 3e1f1575..f95ac078 100755 --- a/atlas/tables.py +++ b/atlas/tables.py @@ -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( - """ - {} - """.format("".join(blocks)) - ) - obj = value.first() - - if obj is None: - return format_html("No image") - - return obj.get_thumbnail()[0] - - # image_object = obj.image - # try: - # thumbnailer = get_thumbnailer(image_object) - # return format_html('', thumbnailer["exam-list"]) - # except InvalidImageFormatError: - # return format_html('Invalid image url', 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( - '
[{}]', - thumbnailer["exam-list"], - value.count(), - ) - except InvalidImageFormatError: - return format_html( - 'Invalid image url
[{}]', - 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") diff --git a/generic/models.py b/generic/models.py index a1c601ae..5e53503c 100644 --- a/generic/models.py +++ b/generic/models.py @@ -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('Invalid image url', img), len( + return format_html('', img), len( images ) return format_html('', thumbnail), len(images) diff --git a/generic/tables.py b/generic/tables.py index 08adf03f..1dc08bb9 100644 --- a/generic/tables.py +++ b/generic/tables.py @@ -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('Invalid image url', value) +class BlockImageColumn(tables.Column): + def render(self, value): + blocks = [] + for obj in value.all(): + blocks.append(obj.get_block()) + return format_html( + """ + {} + """.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( + '
[{}]', + thumbnailer["exam-list"], + value.count(), + ) + except InvalidImageFormatError: + return format_html( + 'Invalid image url
[{}]', + image_object, + value.count(), + ) + +class FirstImageColumn(tables.Column): + def render(self, value): + obj = value.all() + + if not obj: + return format_html('No image') + + image_object = obj[0].image + try: + thumbnailer = get_thumbnailer(image_object) + return format_html('', thumbnailer["exam-list"]) + except InvalidImageFormatError: + return format_html('Invalid image url', image_object) + class CidUserTable(tables.Table): # edit = tables.LinkColumn( diff --git a/longs/tables.py b/longs/tables.py index 1aaca779..acd7a72d 100755 --- a/longs/tables.py +++ b/longs/tables.py @@ -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( - "{}".format("".join(blocks)) - ) - - obj = value.first() - - if obj is None: - return format_html("No image") - - return obj.get_thumbnail()[0] - - # image_object = obj.image - # try: - # thumbnailer = get_thumbnailer(image_object) - # return format_html('', thumbnailer["exam-list"]) - # except InvalidImageFormatError: - # return format_html('Invalid image url', 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( - '
[{}]', - thumbnailer["exam-list"], - value.count(), - ) - except InvalidImageFormatError: - return format_html( - 'Invalid image url
[{}]', - 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 diff --git a/physics/tables.py b/physics/tables.py index c0f7bb29..969cb0dc 100644 --- a/physics/tables.py +++ b/physics/tables.py @@ -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('', thumbnailer["exam-list"]) -# except InvalidImageFormatError: -# return format_html('Invalid image url', value) - class QuestionTable(tables.Table): # edit = tables.LinkColumn( diff --git a/rad/static/css/anatomy.css b/rad/static/css/anatomy.css index 65b956a1..39daa622 100644 --- a/rad/static/css/anatomy.css +++ b/rad/static/css/anatomy.css @@ -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; diff --git a/rapids/tables.py b/rapids/tables.py index f8e191b1..35d789f5 100755 --- a/rapids/tables.py +++ b/rapids/tables.py @@ -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('No image') - - image_object = obj[0].image - try: - thumbnailer = get_thumbnailer(image_object) - return format_html('', thumbnailer["exam-list"]) - except InvalidImageFormatError: - return format_html('Invalid image url', 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") diff --git a/sbas/tables.py b/sbas/tables.py index da138262..bb7b374b 100644 --- a/sbas/tables.py +++ b/sbas/tables.py @@ -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('', thumbnailer["exam-list"]) -# except InvalidImageFormatError: -# return format_html('Invalid image url', value) - class QuestionTable(tables.Table): #edit = tables.LinkColumn(