diff --git a/anatomy/tables.py b/anatomy/tables.py index 7f1c9808..c3994922 100644 --- a/anatomy/tables.py +++ b/anatomy/tables.py @@ -7,24 +7,27 @@ from django.utils.html import format_html from easy_thumbnails.files import get_thumbnailer +from easy_thumbnails.exceptions import InvalidImageFormatError + + class ImageColumn(tables.Column): def render(self, value): - thumbnailer = get_thumbnailer(value) - return format_html('', thumbnailer["exam-list"]) - + 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) - view = tables.LinkColumn('anatomy:question_detail', - text='View', - args=[A('pk')], - orderable=False) + edit = tables.LinkColumn( + "anatomy:anatomy_question_update", text="Edit", args=[A("pk")], orderable=False + ) + view = tables.LinkColumn( + "anatomy:question_detail", text="View", args=[A("pk")], orderable=False + ) image = ImageColumn("image", orderable=False) - #clone = tables.LinkColumn('anatomy:anatomy_question_clone', + # clone = tables.LinkColumn('anatomy:anatomy_question_clone', # text='Clone', # args=[A('pk')], # orderable=False) @@ -33,6 +36,15 @@ class AnatomyQuestionTable(tables.Table): class Meta: model = AnatomyQuestion template_name = "django_tables2/bootstrap4.html" - fields = ("question_type", "description", "examination", "modality", "region", - "body_part", "created_date", "open_access", "author") + fields = ( + "question_type", + "description", + "examination", + "modality", + "region", + "body_part", + "created_date", + "open_access", + "author", + ) sequence = ("view", "image", "exams") \ No newline at end of file