improve case tables
This commit is contained in:
+101
-5
@@ -35,11 +35,44 @@ class CaseTable(tables.Table):
|
||||
"series__examination", # ForeignKey in the related model
|
||||
"series__plane", # ForeignKey in the related model
|
||||
"series__images", # Reverse relationship
|
||||
"previous_case", # Prefetch the previous case relationship
|
||||
#"next_case", # Prefetch the next case relationship
|
||||
),
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def render_title(self, value, record):
|
||||
return value
|
||||
|
||||
def render_description(self, value):
|
||||
max_length = 50 # Set the maximum length for truncation
|
||||
if len(value) > max_length:
|
||||
truncated_value = f"{value[:max_length]}..." # Truncate and add ellipsis
|
||||
else:
|
||||
truncated_value = value
|
||||
# Add a tooltip with the full text
|
||||
return format_html(
|
||||
'<span title="{}">{}</span>',
|
||||
value, # Full text for the tooltip
|
||||
truncated_value, # Truncated text for display
|
||||
)
|
||||
|
||||
def render_series(self, value):
|
||||
max_length = 50 # Set the maximum length for truncation
|
||||
series_list = [str(series) for series in value.all()]
|
||||
full_text = ", ".join(series_list) # Full text for the tooltip
|
||||
if len(full_text) > max_length:
|
||||
truncated_text = f"{full_text[:max_length]}..." # Truncate and add ellipsis
|
||||
else:
|
||||
truncated_text = full_text
|
||||
# Add a tooltip with the full text
|
||||
return format_html(
|
||||
'<span title="{}">{}</span>',
|
||||
full_text, # Full text for the tooltip
|
||||
truncated_text, # Truncated text for display
|
||||
)
|
||||
|
||||
def get_view_cell(record):
|
||||
if record.open_access:
|
||||
return format_html(f"""<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-opencollective" viewBox="0 0 16 16">
|
||||
@@ -49,6 +82,71 @@ class CaseTable(tables.Table):
|
||||
else:
|
||||
return f'View'
|
||||
|
||||
def render_author(self, value):
|
||||
max_length = 15 # Set the maximum length for truncating individual author names
|
||||
authors = []
|
||||
for author in value.all():
|
||||
full_name = str(author) # Convert the author object to a string (e.g., full name)
|
||||
if len(full_name) > max_length:
|
||||
truncated_name = f"{full_name[:max_length]}..." # Truncate and add ellipsis
|
||||
else:
|
||||
truncated_name = full_name
|
||||
# Add a tooltip with the full name
|
||||
authors.append(
|
||||
format_html(
|
||||
'<span title="{}">{}</span>',
|
||||
full_name, # Full name for the tooltip
|
||||
truncated_name, # Truncated name for display
|
||||
)
|
||||
)
|
||||
# Join all authors with commas
|
||||
return format_html(", ".join(authors))
|
||||
|
||||
def render_associated_cases(self, record):
|
||||
links = []
|
||||
if record.previous_case:
|
||||
links.append(
|
||||
format_html(
|
||||
'<a href="{}" title="View previous case">Previous Case</a>',
|
||||
record.previous_case.get_absolute_url(),
|
||||
)
|
||||
)
|
||||
try:
|
||||
if record.next_case:
|
||||
links.append(
|
||||
format_html(
|
||||
'<a href="{}" title="View next case">Next Case</a>',
|
||||
record.next_case.get_absolute_url(),
|
||||
)
|
||||
)
|
||||
except Case.DoesNotExist:
|
||||
pass
|
||||
if links:
|
||||
return format_html(", ".join(links))
|
||||
return "No associated cases"
|
||||
|
||||
def render_collections(self, record):
|
||||
collections = record.casecollection_set.all()
|
||||
if collections:
|
||||
links = [
|
||||
format_html(
|
||||
'<a href="{}" title="View collection">{}</a>',
|
||||
collection.get_absolute_url(),
|
||||
collection.name,
|
||||
)
|
||||
for collection in collections
|
||||
]
|
||||
return format_html(", ".join(links))
|
||||
return "No collections"
|
||||
|
||||
associated_cases = tables.Column(
|
||||
verbose_name="Associated Cases", accessor="pk", orderable=False
|
||||
)
|
||||
|
||||
collections = tables.Column(
|
||||
verbose_name="Collections", accessor="pk", orderable=False
|
||||
)
|
||||
|
||||
edit = tables.LinkColumn(
|
||||
"atlas:case_update", text="Edit", args=[A("pk")], orderable=False
|
||||
)
|
||||
@@ -62,8 +160,6 @@ class CaseTable(tables.Table):
|
||||
"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:
|
||||
@@ -72,13 +168,13 @@ class CaseTable(tables.Table):
|
||||
fields = (
|
||||
"title",
|
||||
"description",
|
||||
#"history",
|
||||
#"condition",
|
||||
"created_date",
|
||||
"series",
|
||||
"author",
|
||||
"associated_cases",
|
||||
"collections",
|
||||
)
|
||||
sequence = ("view", )#, "series")
|
||||
sequence = ("view", )
|
||||
order_by = "-created_date"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user