Refactor user_scores.html to replace Case Collections section with Atlas Collections, implementing HTMX for dynamic loading of user-specific collections.
This commit is contained in:
+19
-2
@@ -1713,14 +1713,30 @@ def index(request):
|
||||
|
||||
@login_required
|
||||
def user_collections(request):
|
||||
"""Return collection buckets for a user (available/in-progress/finished).
|
||||
|
||||
By default this uses ``request.user``. Superusers may optionally provide
|
||||
``?user_id=<id>`` to inspect another user's collection state. HTMX requests
|
||||
return the ``atlas/partials/_user_collections.html`` fragment; normal
|
||||
requests render ``atlas/user_collections.html``.
|
||||
"""
|
||||
|
||||
target_user = request.user
|
||||
requested_user_id = request.GET.get("user_id")
|
||||
if requested_user_id and request.user.is_superuser:
|
||||
try:
|
||||
target_user = User.objects.get(pk=int(requested_user_id))
|
||||
except (User.DoesNotExist, ValueError, TypeError):
|
||||
target_user = request.user
|
||||
|
||||
# Collections the user is explicitly allowed to take (via CaseCollection.valid_user_users)
|
||||
available_collections = request.user.user_casecollection_exams.all()
|
||||
available_collections = target_user.user_casecollection_exams.all()
|
||||
# Collections the user has already taken (recorded in generic.CidUserExam)
|
||||
in_progress_ids = []
|
||||
finished_ids = []
|
||||
try:
|
||||
ct = ContentType.objects.get_for_model(CaseCollection)
|
||||
taken_exams = CidUserExam.objects.filter(user_user=request.user, content_type=ct)
|
||||
taken_exams = CidUserExam.objects.filter(user_user=target_user, content_type=ct)
|
||||
in_progress_ids = list(
|
||||
taken_exams.filter(completed=False).values_list("object_id", flat=True).distinct()
|
||||
)
|
||||
@@ -1745,6 +1761,7 @@ def user_collections(request):
|
||||
finished_qs = CaseCollection.objects.filter(pk__in=list(finished_ids)).order_by("name")
|
||||
|
||||
context = {
|
||||
"target_user": target_user,
|
||||
"available_collections": available_qs,
|
||||
"in_progress_collections": in_progress_qs,
|
||||
"finished_collections": finished_qs,
|
||||
|
||||
+79
-79
File diff suppressed because one or more lines are too long
+14
-19
@@ -86,27 +86,22 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if case_collections %}
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Case Collections</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted">The following Case Collections have been found.</p>
|
||||
<ul class="list-group">
|
||||
{% for collection in case_collections %}
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<a href="{{ collection.get_take_url }}?cid={{ cid }}&passcode={{ passcode }}">{{ collection.name }}</a>
|
||||
<div>
|
||||
{% if collection.active %}<span class="badge bg-success">Active</span>{% endif %}
|
||||
{% if collection.publish_results %}<span class="badge bg-info text-dark ms-2">Results Published</span>{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Atlas Collections</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted mb-2">Available, in-progress, and completed Atlas collections for this user.</p>
|
||||
<div
|
||||
id="atlas-collections-scores"
|
||||
hx-get="{% url 'atlas:user_collections' %}?user_id={{ cid_user.id }}"
|
||||
hx-trigger="load"
|
||||
hx-target="this"
|
||||
hx-swap="innerHTML">
|
||||
<div class="text-muted small">Loading collections...</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-4">
|
||||
|
||||
Reference in New Issue
Block a user