Add advanced filtering options to question overview page
This commit is contained in:
@@ -43,6 +43,12 @@
|
|||||||
</p>
|
</p>
|
||||||
<div class="collapse" id="advanced-filters">
|
<div class="collapse" id="advanced-filters">
|
||||||
<div class="card card-body">
|
<div class="card card-body">
|
||||||
|
{% if qfilter %}
|
||||||
|
<div class="mb-3">
|
||||||
|
<h6 class="small">Full filter form</h6>
|
||||||
|
{{ qfilter.form.as_p }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="row g-2">
|
<div class="row g-2">
|
||||||
<div class="col-md-4 col-sm-6">
|
<div class="col-md-4 col-sm-6">
|
||||||
<label class="form-label small">Finding</label>
|
<label class="form-label small">Finding</label>
|
||||||
|
|||||||
+13
-59
@@ -531,71 +531,24 @@ def question_overview(request):
|
|||||||
|
|
||||||
status = request.GET.get("status") or QuestionReview.StatusChoices.ACCEPTED
|
status = request.GET.get("status") or QuestionReview.StatusChoices.ACCEPTED
|
||||||
group_by = request.GET.get("group_by") or "category"
|
group_by = request.GET.get("group_by") or "category"
|
||||||
# allow multi-selects for category and atlas filters
|
|
||||||
category_filters = request.GET.getlist("category")
|
|
||||||
open_access = request.GET.get("open_access")
|
|
||||||
|
|
||||||
|
# Use django-filter to build the base filtered queryset. QuestionFilter
|
||||||
|
# already applies permission filters when given the request.
|
||||||
|
from .filters import QuestionFilter
|
||||||
|
|
||||||
|
qfilter = QuestionFilter(data=request.GET or None, queryset=Question.objects.all().order_by("pk"), request=request)
|
||||||
|
qs = qfilter.qs
|
||||||
|
|
||||||
|
# We'll still support a top-level status filter (review status) via a GET param
|
||||||
|
# and advanced atlas filters are provided by the QuestionFilter form.
|
||||||
|
# Preserve selected values for building links (use getlist for multi-selects)
|
||||||
|
category_filters = request.GET.getlist("category")
|
||||||
finding_filters = request.GET.getlist("finding")
|
finding_filters = request.GET.getlist("finding")
|
||||||
structure_filters = request.GET.getlist("structure")
|
structure_filters = request.GET.getlist("structure")
|
||||||
condition_filters = request.GET.getlist("condition")
|
condition_filters = request.GET.getlist("condition")
|
||||||
subspecialty_filters = request.GET.getlist("subspecialty")
|
subspecialty_filters = request.GET.getlist("subspecialty")
|
||||||
presentation_filters = request.GET.getlist("presentation")
|
presentation_filters = request.GET.getlist("presentation")
|
||||||
|
open_access = request.GET.get("open_access")
|
||||||
qs = Question.objects.all().order_by("pk")
|
|
||||||
|
|
||||||
# Permission filter: non-checkers see open_access or their own questions
|
|
||||||
try:
|
|
||||||
if not request.user.groups.filter(name="sbas_checker").exists():
|
|
||||||
from django.db.models import Q
|
|
||||||
|
|
||||||
qs = qs.filter(Q(open_access=True) | Q(author__id=request.user.id))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Optional category filter (multi)
|
|
||||||
if category_filters:
|
|
||||||
try:
|
|
||||||
ids = [int(x) for x in category_filters if x]
|
|
||||||
if ids:
|
|
||||||
qs = qs.filter(category__id__in=ids)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Optional open_access filter
|
|
||||||
if open_access in ("0", "1"):
|
|
||||||
qs = qs.filter(open_access=(open_access == "1"))
|
|
||||||
|
|
||||||
# Optional atlas M2M filters (multi-select)
|
|
||||||
try:
|
|
||||||
finding_ids = [int(x) for x in finding_filters if x]
|
|
||||||
if finding_ids:
|
|
||||||
qs = qs.filter(finding__id__in=finding_ids)
|
|
||||||
except Exception:
|
|
||||||
finding_ids = []
|
|
||||||
try:
|
|
||||||
structure_ids = [int(x) for x in structure_filters if x]
|
|
||||||
if structure_ids:
|
|
||||||
qs = qs.filter(structure__id__in=structure_ids)
|
|
||||||
except Exception:
|
|
||||||
structure_ids = []
|
|
||||||
try:
|
|
||||||
condition_ids = [int(x) for x in condition_filters if x]
|
|
||||||
if condition_ids:
|
|
||||||
qs = qs.filter(condition__id__in=condition_ids)
|
|
||||||
except Exception:
|
|
||||||
condition_ids = []
|
|
||||||
try:
|
|
||||||
subspecialty_ids = [int(x) for x in subspecialty_filters if x]
|
|
||||||
if subspecialty_ids:
|
|
||||||
qs = qs.filter(subspecialty__id__in=subspecialty_ids)
|
|
||||||
except Exception:
|
|
||||||
subspecialty_ids = []
|
|
||||||
try:
|
|
||||||
presentation_ids = [int(x) for x in presentation_filters if x]
|
|
||||||
if presentation_ids:
|
|
||||||
qs = qs.filter(presentation__id__in=presentation_ids)
|
|
||||||
except Exception:
|
|
||||||
presentation_ids = []
|
|
||||||
|
|
||||||
# Optimize status filtering with a DB subquery to get latest review status per question
|
# Optimize status filtering with a DB subquery to get latest review status per question
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
@@ -697,6 +650,7 @@ def question_overview(request):
|
|||||||
"selected_conditions": selected_conditions,
|
"selected_conditions": selected_conditions,
|
||||||
"selected_subspecialties": selected_subspecialties,
|
"selected_subspecialties": selected_subspecialties,
|
||||||
"selected_presentations": selected_presentations,
|
"selected_presentations": selected_presentations,
|
||||||
|
"qfilter": qfilter,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, "sbas/question_overview.html", context)
|
return render(request, "sbas/question_overview.html", context)
|
||||||
|
|||||||
Reference in New Issue
Block a user