import django_tables2 as tables from django_tables2.utils import A from generic.tables import SeriesImageColumn from .models import ( Case, CaseCollection, Condition, PathologicalProcess, Presentation, QuestionSchema, Series, Structure, Finding, Subspecialty, ) from django.utils.html import format_html from easy_thumbnails.files import get_thumbnailer from easy_thumbnails.exceptions import InvalidImageFormatError class CaseTable(tables.Table): def get_view_cell(record): if record.open_access: return format_html(f""" View""") else: return f'View' edit = tables.LinkColumn( "atlas:case_update", text="Edit", args=[A("pk")], orderable=False ) view = tables.LinkColumn( "atlas:case_detail", text=get_view_cell, args=[A("pk")], orderable=False ) clone = tables.LinkColumn( "atlas:case_clone", text="Clone", args=[A("pk")], orderable=False ) delete = tables.LinkColumn( "atlas:case_delete", text="Delete", args=[A("pk")], orderable=False ) #differential = tables.ManyToManyColumn(verbose_name="Differential") selection = tables.CheckBoxColumn(accessor="pk", orderable=False) class Meta: model = Case template_name = "django_tables2/bootstrap4.html" fields = ( "title", "description", #"history", #"condition", "created_date", "author", ) sequence = ("view", )#, "series") def __init__(self, data=None, *args, **kwargs): super().__init__( data.prefetch_related( "author",#"condition", "condition__synonym" ), *args, **kwargs, ) class PopupLinkColumn(tables.Column): def render(self, value): return format_html("test: {}", value) obj = value.first() if obj is None: return format_html("No image") return obj.get_thumbnail()[0] def create_link(test): print(test) return "Hello" class SeriesTable(tables.Table): edit = tables.LinkColumn( "atlas:series_update", text="Edit", args=[A("pk")], orderable=False ) view = tables.LinkColumn( "atlas:series_detail", text="View", args=[A("pk")], orderable=False ) popup = tables.Column(empty_values=(), orderable=False) images = SeriesImageColumn("Images", orderable=False) delete = tables.LinkColumn( "atlas:series_delete", text="Delete", args=[A("pk")], orderable=False ) selection = tables.CheckBoxColumn(accessor="pk", orderable=False) case = tables.ManyToManyColumn(verbose_name="Cases") findings = tables.ManyToManyColumn(verbose_name="Findings") structures = tables.ManyToManyColumn(verbose_name="Structures") class Meta: model = Series template_name = "django_tables2/bootstrap4.html" fields = ( "modality", "description", "examination", "plane", "contrast", "author", "created_date", "modified_date", ) sequence = ("view", "popup", "images", "case") def __init__(self, data=None, *args, **kwargs): super().__init__( data.prefetch_related( "modality", "case", "examination", "plane", "contrast", "author", "findings", "images" ), *args, **kwargs, ) def render_popup(self, value, record): return format_html( """Popup""", record.pk, ) class ConditionTable(tables.Table): name = tables.Column( linkify=("atlas:condition_detail", {"pk": tables.A("pk")}), verbose_name="Condition", ) edit = tables.LinkColumn( "atlas:condition_update", text="Edit", args=[A("pk")], orderable=False ) delete = tables.LinkColumn( "atlas:condition_delete", text="Delete", args=[A("pk")], orderable=False ) selection = tables.CheckBoxColumn(accessor="pk", orderable=False) # synonym = tables.ManyToManyColumn(verbose_name="Synonyms") synonym = tables.Column(empty_values=()) parent = tables.ManyToManyColumn(verbose_name="Parents") class Meta: model = Condition template_name = "django_tables2/bootstrap4.html" fields = ("primary", "subspecialty", "rcr_curriculum_map", "rcr_curriculum") sequence = ("name",) def __init__(self, data=None, *args, **kwargs): super().__init__( data.prefetch_related( "subspecialty", "rcr_curriculum_map", "parent" ), *args, **kwargs, ) def render_synonym(self, value, record): return format_html(record.get_synonym_link()) return f"{record.get_synonym_link()}" class FindingTable(tables.Table): name = tables.Column( linkify=("atlas:finding_detail", {"pk": tables.A("pk")}), verbose_name="Finding" ) edit = tables.LinkColumn( "atlas:finding_update", text="Edit", args=[A("pk")], orderable=False ) delete = tables.LinkColumn( "atlas:finding_delete", text="Delete", args=[A("pk")], orderable=False ) selection = tables.CheckBoxColumn(accessor="pk", orderable=False) # synonym = tables.ManyToManyColumn(verbose_name="Synonyms") synonym = tables.Column(empty_values=()) parent = tables.ManyToManyColumn(verbose_name="Parents") class Meta: model = Finding template_name = "django_tables2/bootstrap4.html" fields = ("name", "primary") sequence = ("name",) def render_synonym(self, value, record): return format_html(record.get_synonym_link()) class StructureTable(tables.Table): name = tables.Column( linkify=("atlas:structure_detail", {"pk": tables.A("pk")}), verbose_name="Structure", ) edit = tables.LinkColumn( "atlas:structure_update", text="Edit", args=[A("pk")], orderable=False ) delete = tables.LinkColumn( "atlas:structure_delete", text="Delete", args=[A("pk")], orderable=False ) selection = tables.CheckBoxColumn(accessor="pk", orderable=False) # synonym = tables.ManyToManyColumn(verbose_name="Synonyms") synonym = tables.Column(empty_values=()) parent = tables.ManyToManyColumn(verbose_name="Parents") class Meta: model = Structure template_name = "django_tables2/bootstrap4.html" fields = ("name", "primary") sequence = ("name",) def render_synonym(self, value, record): return format_html(record.get_synonym_link()) class PresentationTable(tables.Table): name = tables.Column( linkify=("atlas:presentation_detail", {"pk": tables.A("pk")}), verbose_name="Presentation", ) # edit = tables.LinkColumn( # "atlas:presentation_update", text="Edit", args=[A("pk")], orderable=False # ) # delete = tables.LinkColumn( # "atlas:presentation_delete", text="Delete", args=[A("pk")], orderable=False # ) selection = tables.CheckBoxColumn(accessor="pk", orderable=False) subspecialty = tables.ManyToManyColumn(verbose_name="Subspecialty") class Meta: model = Presentation template_name = "django_tables2/bootstrap4.html" fields = ("name",) sequence = ("name",) class PathologicalProcessTable(tables.Table): name = tables.Column( linkify=("atlas:pathological_process_detail", {"pk": tables.A("pk")}), verbose_name="PathologicalProcess", ) # edit = tables.LinkColumn( # "atlas:pathological_process_update", text="Edit", args=[A("pk")], orderable=False # ) # delete = tables.LinkColumn( # "atlas:pathological_process_delete", text="Delete", args=[A("pk")], orderable=False # ) selection = tables.CheckBoxColumn(accessor="pk", orderable=False) class Meta: model = PathologicalProcess template_name = "django_tables2/bootstrap4.html" fields = ("name",) sequence = ("name",) class SubspecialtyTable(tables.Table): name = tables.Column( linkify=("atlas:subspecialty_detail", {"pk": tables.A("pk")}), verbose_name="Subspecialty", ) # edit = tables.LinkColumn( # "atlas:subspecialty_update", text="Edit", args=[A("pk")], orderable=False # ) # delete = tables.LinkColumn( # "atlas:subspecialty_delete", text="Delete", args=[A("pk")], orderable=False # ) selection = tables.CheckBoxColumn(accessor="pk", orderable=False) class Meta: model = Subspecialty template_name = "django_tables2/bootstrap4.html" fields = () sequence = ("name",) def render_synonym(self, value, record): return format_html(record.get_synonym_link()) return f"{record.get_synonym_link()}" class CaseCollectionTable(tables.Table): edit = tables.LinkColumn( "atlas:exam_update", text="Edit", args=[A("pk")], orderable=False ) view = tables.LinkColumn( "atlas:collection_detail", text="View", args=[A("pk")], orderable=False ) #clone = tables.LinkColumn( # "atlas:case_clone", text="Clone", args=[A("pk")], orderable=False #) delete = tables.LinkColumn( "atlas:exam_deleted", text="Delete", args=[A("pk")], orderable=False ) #differential = tables.ManyToManyColumn(verbose_name="Differential") selection = tables.CheckBoxColumn(accessor="pk", orderable=False) class Meta: model = CaseCollection template_name = "django_tables2/bootstrap4.html" fields = ( "name", "collection_type", "publish_results", "active", "author", ) sequence = ("view", )#, "series") def __init__(self, data=None, *args, **kwargs): super().__init__( data.prefetch_related( "author", #"conditionI"", "condition__synonym" ), *args, **kwargs, ) class QuestionSchemaTable(tables.Table): name = tables.Column( linkify=("atlas:question_schema_detail", {"pk": tables.A("pk")}), verbose_name="QuestionSchema", ) edit = tables.LinkColumn( "atlas:question_schema_update", text="Edit", args=[A("pk")], orderable=False ) delete = tables.LinkColumn( "atlas:question_schema_delete", text="Delete", args=[A("pk")], orderable=False ) class Meta: model = QuestionSchema template_name = "django_tables2/bootstrap4.html" fields = ("name", "description", "schema") def render_schema(self, value, record): return format_html("
Schema{}
", value)