Add filtering options for findings, structures, conditions, subspecialties, and presentations in question overview
This commit is contained in:
@@ -36,6 +36,58 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="w-100"></div>
|
||||
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<label class="form-label small">Finding</label>
|
||||
<select name="finding" class="form-select form-select-sm">
|
||||
<option value="">(Any)</option>
|
||||
{% for f in findings %}
|
||||
<option value="{{ f.id }}" {% if selected_finding|default:'' == f.id|stringformat:"s" %}selected{% endif %}>{{ f.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<label class="form-label small">Structure</label>
|
||||
<select name="structure" class="form-select form-select-sm">
|
||||
<option value="">(Any)</option>
|
||||
{% for s in structures %}
|
||||
<option value="{{ s.id }}" {% if selected_structure|default:'' == s.id|stringformat:"s" %}selected{% endif %}>{{ s.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<label class="form-label small">Condition</label>
|
||||
<select name="condition" class="form-select form-select-sm">
|
||||
<option value="">(Any)</option>
|
||||
{% for c in conditions %}
|
||||
<option value="{{ c.id }}" {% if selected_condition|default:'' == c.id|stringformat:"s" %}selected{% endif %}>{{ c.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<label class="form-label small">Subspecialty</label>
|
||||
<select name="subspecialty" class="form-select form-select-sm">
|
||||
<option value="">(Any)</option>
|
||||
{% for ss in subspecialties %}
|
||||
<option value="{{ ss.id }}" {% if selected_subspecialty|default:'' == ss.id|stringformat:"s" %}selected{% endif %}>{{ ss.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<label class="form-label small">Presentation</label>
|
||||
<select name="presentation" class="form-select form-select-sm">
|
||||
<option value="">(Any)</option>
|
||||
{% for p in presentations %}
|
||||
<option value="{{ p.id }}" {% if selected_presentation|default:'' == p.id|stringformat:"s" %}selected{% endif %}>{{ p.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-auto align-self-end">
|
||||
<button class="btn btn-sm btn-primary">Filter</button>
|
||||
</div>
|
||||
|
||||
@@ -534,6 +534,13 @@ def question_overview(request):
|
||||
category_filter = request.GET.get("category")
|
||||
open_access = request.GET.get("open_access")
|
||||
|
||||
# Atlas model filters (single-select for now)
|
||||
finding_filter = request.GET.get("finding")
|
||||
structure_filter = request.GET.get("structure")
|
||||
condition_filter = request.GET.get("condition")
|
||||
subspecialty_filter = request.GET.get("subspecialty")
|
||||
presentation_filter = request.GET.get("presentation")
|
||||
|
||||
qs = Question.objects.all().order_by("pk")
|
||||
|
||||
# Permission filter: non-checkers see open_access or their own questions
|
||||
@@ -556,12 +563,42 @@ def question_overview(request):
|
||||
if open_access in ("0", "1"):
|
||||
qs = qs.filter(open_access=(open_access == "1"))
|
||||
|
||||
# Optional atlas M2M filters
|
||||
try:
|
||||
if finding_filter:
|
||||
qs = qs.filter(finding__id=int(finding_filter))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if structure_filter:
|
||||
qs = qs.filter(structure__id=int(structure_filter))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if condition_filter:
|
||||
qs = qs.filter(condition__id=int(condition_filter))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if subspecialty_filter:
|
||||
qs = qs.filter(subspecialty__id=int(subspecialty_filter))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if presentation_filter:
|
||||
qs = qs.filter(presentation__id=int(presentation_filter))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Build counts by category (default)
|
||||
counts = {}
|
||||
total = 0
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
# Import atlas models for populating filter choices
|
||||
from atlas.models import Finding, Structure, Condition as AtlasCondition, Subspecialty, Presentation as AtlasPresentation
|
||||
|
||||
for question in qs:
|
||||
# Respect authors_only flag
|
||||
try:
|
||||
@@ -608,6 +645,13 @@ def question_overview(request):
|
||||
|
||||
categories = Category.objects.all().order_by("category")
|
||||
|
||||
# Populate atlas filter lists
|
||||
findings = Finding.objects.all().order_by("name")
|
||||
structures = Structure.objects.all().order_by("name")
|
||||
conditions = AtlasCondition.objects.all().order_by("name")
|
||||
subspecialties = Subspecialty.objects.all().order_by("name")
|
||||
presentations = AtlasPresentation.objects.all().order_by("name")
|
||||
|
||||
context = {
|
||||
"status_options": status_options,
|
||||
"selected_status": status,
|
||||
@@ -617,6 +661,16 @@ def question_overview(request):
|
||||
"categories": categories,
|
||||
"selected_category": category_filter,
|
||||
"selected_open_access": open_access,
|
||||
"findings": findings,
|
||||
"structures": structures,
|
||||
"conditions": conditions,
|
||||
"subspecialties": subspecialties,
|
||||
"presentations": presentations,
|
||||
"selected_finding": finding_filter,
|
||||
"selected_structure": structure_filter,
|
||||
"selected_condition": condition_filter,
|
||||
"selected_subspecialty": subspecialty_filter,
|
||||
"selected_presentation": presentation_filter,
|
||||
}
|
||||
|
||||
return render(request, "sbas/question_overview.html", context)
|
||||
|
||||
Reference in New Issue
Block a user