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
|
@login_required
|
||||||
def user_collections(request):
|
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)
|
# 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)
|
# Collections the user has already taken (recorded in generic.CidUserExam)
|
||||||
in_progress_ids = []
|
in_progress_ids = []
|
||||||
finished_ids = []
|
finished_ids = []
|
||||||
try:
|
try:
|
||||||
ct = ContentType.objects.get_for_model(CaseCollection)
|
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(
|
in_progress_ids = list(
|
||||||
taken_exams.filter(completed=False).values_list("object_id", flat=True).distinct()
|
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")
|
finished_qs = CaseCollection.objects.filter(pk__in=list(finished_ids)).order_by("name")
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
|
"target_user": target_user,
|
||||||
"available_collections": available_qs,
|
"available_collections": available_qs,
|
||||||
"in_progress_collections": in_progress_qs,
|
"in_progress_collections": in_progress_qs,
|
||||||
"finished_collections": finished_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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if case_collections %}
|
<div class="card mb-3">
|
||||||
<div class="card mb-3">
|
<div class="card-header">
|
||||||
<div class="card-header">
|
<h5 class="mb-0">Atlas Collections</h5>
|
||||||
<h5 class="mb-0">Case Collections</h5>
|
</div>
|
||||||
</div>
|
<div class="card-body">
|
||||||
<div class="card-body">
|
<p class="text-muted mb-2">Available, in-progress, and completed Atlas collections for this user.</p>
|
||||||
<p class="text-muted">The following Case Collections have been found.</p>
|
<div
|
||||||
<ul class="list-group">
|
id="atlas-collections-scores"
|
||||||
{% for collection in case_collections %}
|
hx-get="{% url 'atlas:user_collections' %}?user_id={{ cid_user.id }}"
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
hx-trigger="load"
|
||||||
<a href="{{ collection.get_take_url }}?cid={{ cid }}&passcode={{ passcode }}">{{ collection.name }}</a>
|
hx-target="this"
|
||||||
<div>
|
hx-swap="innerHTML">
|
||||||
{% if collection.active %}<span class="badge bg-success">Active</span>{% endif %}
|
<div class="text-muted small">Loading collections...</div>
|
||||||
{% if collection.publish_results %}<span class="badge bg-info text-dark ms-2">Results Published</span>{% endif %}
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-4">
|
<div class="col-lg-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user