Implement hiding and showing functionality for user exams and collections

This commit is contained in:
Ross
2026-06-15 11:23:00 +01:00
parent 35ab7443d2
commit c50ace771e
11 changed files with 400 additions and 50 deletions
+39
View File
@@ -7114,4 +7114,43 @@ def user_content_review(request, user_id):
# Render HTMX partial (or full page if not HTMX)
template = "generic/partials/user_content_review.html"
return render(request, template, context)
@login_required
@require_POST
def toggle_hide_item(request):
"""Toggle the hidden status of an exam or collection for the current user.
Scope: Authenticated end users.
Functionality: Adds or removes a UserHiddenItem record for the given
content_type_id and object_id, then triggers a page reload via HX-Refresh.
"""
from django.contrib.contenttypes.models import ContentType
from generic.models import UserHiddenItem
content_type_id = request.POST.get("content_type_id")
object_id = request.POST.get("object_id")
if not content_type_id or not object_id:
return HttpResponse("Missing parameters", status=400)
try:
content_type = ContentType.objects.get(pk=int(content_type_id))
object_id = int(object_id)
except (ContentType.DoesNotExist, ValueError):
return HttpResponse("Invalid parameters", status=400)
hidden_item, created = UserHiddenItem.objects.get_or_create(
user=request.user,
content_type=content_type,
object_id=object_id,
)
if not created:
hidden_item.delete()
response = HttpResponse("")
response["HX-Refresh"] = "true"
return response