Implement HTMX support for user collections display and refactor rendering logic
This commit is contained in:
+19
-9
@@ -1131,15 +1131,25 @@ def user_collections(request):
|
||||
# Finished (completed)
|
||||
finished_qs = CaseCollection.objects.filter(pk__in=list(finished_ids)).order_by("name")
|
||||
|
||||
return render(
|
||||
request,
|
||||
"atlas/user_collections.html",
|
||||
{
|
||||
"available_collections": available_qs,
|
||||
"in_progress_collections": in_progress_qs,
|
||||
"finished_collections": finished_qs,
|
||||
},
|
||||
)
|
||||
context = {
|
||||
"available_collections": available_qs,
|
||||
"in_progress_collections": in_progress_qs,
|
||||
"finished_collections": finished_qs,
|
||||
}
|
||||
|
||||
# If called via HTMX return a small fragment suitable for swapping
|
||||
# into the index page. Otherwise render the full page.
|
||||
is_htmx = getattr(request, "htmx", False) or request.headers.get("HX-Request", "").lower() == "true"
|
||||
if is_htmx:
|
||||
html = render_to_string("atlas/partials/_user_collections.html", context, request=request)
|
||||
return HttpResponse(html)
|
||||
|
||||
return render(request, "atlas/user_collections.html", context)
|
||||
|
||||
|
||||
# Note: keep the above full-page render for normal requests. If this
|
||||
# endpoint is called by HTMX we prefer returning a small fragment so it
|
||||
# can be swapped into the index page without duplicating layout.
|
||||
|
||||
@login_required
|
||||
def collection_options(request):
|
||||
|
||||
Reference in New Issue
Block a user