Add user-related collections feature with HTMX support and timestamps for collections
This commit is contained in:
@@ -1151,6 +1151,39 @@ def user_collections(request):
|
||||
# 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 user_related_collections(request):
|
||||
"""Return up to 10 most recently modified collections where the user
|
||||
is an author or a marker. If called via HTMX return a fragment suitable
|
||||
for swapping into the index page.
|
||||
"""
|
||||
user = request.user
|
||||
qs = (
|
||||
CaseCollection.objects.filter(Q(author=user) | Q(markers=user))
|
||||
.distinct()
|
||||
.order_by("-updated")[:10]
|
||||
)
|
||||
|
||||
related = []
|
||||
for c in qs:
|
||||
related.append(
|
||||
{
|
||||
"collection": c,
|
||||
"is_author": c.author.filter(id=user.id).exists(),
|
||||
"is_marker": c.markers.filter(id=user.id).exists(),
|
||||
}
|
||||
)
|
||||
|
||||
context = {"related_collections": related}
|
||||
|
||||
is_htmx = getattr(request, "htmx", False) or request.headers.get("HX-Request", "").lower() == "true"
|
||||
if is_htmx:
|
||||
html = render_to_string("atlas/partials/_user_related_collections.html", context, request=request)
|
||||
return HttpResponse(html)
|
||||
|
||||
return render(request, "atlas/user_collections.html", context)
|
||||
|
||||
@login_required
|
||||
def collection_options(request):
|
||||
if not request.htmx:
|
||||
|
||||
Reference in New Issue
Block a user