From 4986c2faa97fb84e2eafe251c36505061c198962 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 13 Oct 2025 14:18:34 +0100 Subject: [PATCH] Add sync functionality for prerequisite users and enhance result display --- atlas/templates/atlas/collection_detail.html | 17 +++++---- .../atlas/partials/sync_prereq_result.html | 12 ++++++ atlas/views.py | 37 +++++++++++++++++-- 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 atlas/templates/atlas/partials/sync_prereq_result.html diff --git a/atlas/templates/atlas/collection_detail.html b/atlas/templates/atlas/collection_detail.html index 0efb370d..e625fa09 100644 --- a/atlas/templates/atlas/collection_detail.html +++ b/atlas/templates/atlas/collection_detail.html @@ -52,6 +52,15 @@ {% endfor %} + +

+ +

{% endif %} @@ -128,14 +137,6 @@
-

- -

{% endif %} {% include 'exam_overview_js.html' %} {% endblock %} diff --git a/atlas/templates/atlas/partials/sync_prereq_result.html b/atlas/templates/atlas/partials/sync_prereq_result.html new file mode 100644 index 00000000..bd98916e --- /dev/null +++ b/atlas/templates/atlas/partials/sync_prereq_result.html @@ -0,0 +1,12 @@ +
+ Two-way sync complete +

Total added: {{ total_added_cid }} CID(s), {{ total_added_user }} user(s), {{ total_added_cid_groups }} CID group(s), {{ total_added_user_groups }} user group(s).

+
+ Per-collection changes ({{ per_collection_added|length }}) +
    + {% for pk, added_cid, added_user, added_cid_groups, added_user_groups in per_collection_added %} +
  • Collection {{ pk }}: +{{ added_cid }} CID(s), +{{ added_user }} user(s), +{{ added_cid_groups }} CID group(s), +{{ added_user_groups }} user group(s)
  • + {% endfor %} +
+
+
diff --git a/atlas/views.py b/atlas/views.py index 552aba99..cc3af2ca 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -3589,17 +3589,25 @@ def collection_sync_prerequisite_users(request, pk: int): # Compute the union of all cid users and user users across the set union_cid_users = set() union_user_users = set() + union_cid_groups = set() + union_user_groups = set() for col in collections: union_cid_users.update(list(col.valid_cid_users.all())) union_user_users.update(list(col.valid_user_users.all())) + union_cid_groups.update(list(col.cid_user_groups.all())) + union_user_groups.update(list(col.user_user_groups.all())) # Apply the union to each collection and count additions total_added_cid = 0 total_added_user = 0 + total_added_cid_groups = 0 + total_added_user_groups = 0 per_collection_added = [] for col in collections: added_cid = 0 added_user = 0 + added_cid_groups = 0 + added_user_groups = 0 for cid_user in union_cid_users: if not col.valid_cid_users.filter(pk=cid_user.pk).exists(): col.valid_cid_users.add(cid_user) @@ -3608,16 +3616,39 @@ def collection_sync_prerequisite_users(request, pk: int): if not col.valid_user_users.filter(pk=user.pk).exists(): col.valid_user_users.add(user) added_user += 1 + # Sync groups as well + for gid in union_cid_groups: + if not col.cid_user_groups.filter(pk=gid.pk).exists(): + col.cid_user_groups.add(gid) + added_cid_groups += 1 + for ug in union_user_groups: + if not col.user_user_groups.filter(pk=ug.pk).exists(): + col.user_user_groups.add(ug) + added_user_groups += 1 + added_user += added_user_groups + added_cid += added_cid_groups if added_cid or added_user: col.save() total_added_cid += added_cid total_added_user += added_user - per_collection_added.append((col.pk, added_cid, added_user)) + total_added_cid_groups += added_cid_groups + total_added_user_groups += added_user_groups + per_collection_added.append((col.pk, added_cid, added_user, added_cid_groups, added_user_groups)) - return HttpResponse( - f"Two-way sync complete — total added: {total_added_cid} cid(s), {total_added_user} user(s)." + html = render_to_string( + "atlas/partials/sync_prereq_result.html", + { + "total_added_cid": total_added_cid, + "total_added_user": total_added_user, + "total_added_cid_groups": total_added_cid_groups, + "total_added_user_groups": total_added_user_groups, + "per_collection_added": per_collection_added, + }, + request=request, ) + return HttpResponse(html) + def collection_reset_answers_user_list(request, exam_id: int): if request.htmx: