Add case search functionality with HTMX support and results partial

This commit is contained in:
Ross
2025-11-05 21:37:57 +00:00
parent 89a767034c
commit 03a24615ab
4 changed files with 57 additions and 0 deletions
+25
View File
@@ -183,6 +183,31 @@ from helpers.cimar import CimarAPI
logger = logging.getLogger(__name__)
@login_required
def case_search_partial(request):
"""Return an HTMX partial listing cases matching the query parameter `q`.
This view returns a small list-group fragment that can be swapped into
the index page. It respects the user's available cases via
get_cases_available_to_user.
"""
q = request.GET.get('q', '') or request.GET.get('case-search-input', '')
q = q.strip()
# Start with cases available to the user
qs = get_cases_available_to_user(request.user)
if q:
from django.db.models import Q
qs = qs.filter(Q(title__icontains=q) | Q(description__icontains=q)).distinct()
qs = qs.order_by('-created_date')[:20]
html = render_to_string('atlas/partials/_case_search_results.html', {'cases': qs}, request=request)
return HttpResponse(html)
class AuthorOrCheckerRequiredMixin(object):
def get_object(self, *args, **kwargs):
obj = super().get_object(*args, **kwargs)