Enhance AnatomyQuestion string representation; improve formatting and handle missing attributes for better readability

This commit is contained in:
Ross
2025-11-11 14:04:46 +00:00
parent c69eecc1ec
commit 87dde70fd3
2 changed files with 53 additions and 51 deletions
+10 -8
View File
@@ -132,14 +132,16 @@ class AnatomyQuestion(QuestionBase):
return "anatomy" return "anatomy"
def __str__(self): def __str__(self):
# Get first answer # Nicely formatted representation
return "{}/{}: {} [{}, {}]".format( pk = self.pk or ""
self.pk, qtype = str(self.question_type) if self.question_type else "N/A"
self.question_type, primary = self.get_primary_answer() or "None"
self.get_primary_answer(), modality = str(self.modality) if self.modality else "Unknown"
self.modality, structure = str(self.structure) if self.structure else "Unknown"
self.structure, title = self.get_title() if hasattr(self, "get_title") else (self.description or "")
) if title and len(title) > 60:
title = title[:57] + "..."
return f"{title} (Type: {qtype}) — Answer: {primary} — Modality: {modality}; Structure: {structure}"
def get_link(self): def get_link(self):
return format_html("<a href='{}'>{}</a>", self.get_absolute_url(), self) return format_html("<a href='{}'>{}</a>", self.get_absolute_url(), self)
@@ -77,4 +77,4 @@
<style> <style>
.show-all-button.active, .show-unmarked-button.active { box-shadow: inset 0 -2px 0 rgba(0,0,0,0.08); } .show-all-button.active, .show-unmarked-button.active { box-shadow: inset 0 -2px 0 rgba(0,0,0,0.08); }
</style> </style>
{% endblock %} {% endblock %}