allow bulk adding cid candidates by group
This commit is contained in:
@@ -73,8 +73,24 @@
|
|||||||
<a href="{{exam.get_absolute_url}}" class="px-2">{{exam}}</a>
|
<a href="{{exam.get_absolute_url}}" class="px-2">{{exam}}</a>
|
||||||
{% if group_type == "cid" %}
|
{% if group_type == "cid" %}
|
||||||
<a href="{{exam.get_cid_edit_url}}" class="edit-link" px-2>Edit candidates</a>
|
<a href="{{exam.get_cid_edit_url}}" class="edit-link" px-2>Edit candidates</a>
|
||||||
{% comment %} <button>Add group candidates</button>
|
<form>
|
||||||
<button>Remove group candidates</button> {% endcomment %}
|
<input type="hidden" name="exam_id" value="{{exam.pk}}">
|
||||||
|
<input type="hidden" name="exam_type" value="{{exam.app_name}}">
|
||||||
|
<button
|
||||||
|
class="btn btn-sm px-2"
|
||||||
|
hx-post="{% url 'generic:cid_group_add_candidates_to_exams' group.pk %}"
|
||||||
|
title="Add all group candidates to this exam"
|
||||||
|
name="action"
|
||||||
|
value="add"
|
||||||
|
>Add group candidates</button>
|
||||||
|
<button
|
||||||
|
hx-post="{% url 'generic:cid_group_add_candidates_to_exams' group.pk %}"
|
||||||
|
title="Remove all group candidates to this exam"
|
||||||
|
class="btn btn-sm px-2"
|
||||||
|
name="action"
|
||||||
|
value="remove"
|
||||||
|
>Remove group candidates</button>
|
||||||
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{exam.get_user_edit_url}}" class="edit-link px-2">Edit candidates</a>
|
<a href="{{exam.get_user_edit_url}}" class="edit-link px-2">Edit candidates</a>
|
||||||
<form>
|
<form>
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ urlpatterns = [
|
|||||||
views.CidUserGroupDelete.as_view(),
|
views.CidUserGroupDelete.as_view(),
|
||||||
name="cid_group_delete",
|
name="cid_group_delete",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"cid/group/<int:group_id>/add",
|
||||||
|
views.cid_group_add_candidates_to_exams,
|
||||||
|
name="cid_group_add_candidates_to_exams",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"cids/group/create", views.CidUserGroupCreate.as_view(), name="cid_group_create"
|
"cids/group/create", views.CidUserGroupCreate.as_view(), name="cid_group_create"
|
||||||
),
|
),
|
||||||
|
|||||||
+22
-1
@@ -2890,7 +2890,7 @@ def user_group_add_by_email_user(request, group_id):
|
|||||||
# Ignore invalid emails
|
# Ignore invalid emails
|
||||||
pass
|
pass
|
||||||
|
|
||||||
res = f"<div class='alert alert-primary'>Users added to {group.name} [{','.join(added)}]</div>"
|
res = f"<div class='alert alert-primary'>Users added to {group.name} [{','.join(added)} ({len(added)})]</div>"
|
||||||
|
|
||||||
if invalid_emails:
|
if invalid_emails:
|
||||||
res += f"<br/><div class='alert alert-warning'>Invalid emails [{','.join(invalid_emails)}]</div>"
|
res += f"<br/><div class='alert alert-warning'>Invalid emails [{','.join(invalid_emails)}]</div>"
|
||||||
@@ -2928,6 +2928,27 @@ def cid_group_view_all(request):
|
|||||||
{"groups": groups, "view_all": True},
|
{"groups": groups, "view_all": True},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@user_is_cid_user_manager
|
||||||
|
def cid_group_add_candidates_to_exams(request, group_id):
|
||||||
|
if request.htmx:
|
||||||
|
group = get_object_or_404(CidUserGroup, pk=group_id)
|
||||||
|
|
||||||
|
exam_id = request.POST.get("exam_id")
|
||||||
|
exam_type = request.POST.get("exam_type")
|
||||||
|
|
||||||
|
ExamModel = get_exam_model_from_app_name(exam_type)
|
||||||
|
|
||||||
|
exam = get_object_or_404(ExamModel, pk=exam_id)
|
||||||
|
|
||||||
|
if request.POST.get("action") == "remove":
|
||||||
|
exam.valid_cid_users.remove(*group.ciduser_set.all())
|
||||||
|
return HttpResponse(f"Candidates removed")
|
||||||
|
else:
|
||||||
|
exam.valid_cid_users.add(*group.ciduser_set.all())
|
||||||
|
return HttpResponse(f"Candidates added")
|
||||||
|
# exam.save()
|
||||||
|
|
||||||
|
raise PermissionDenied() # or Http404
|
||||||
|
|
||||||
@user_is_cid_user_manager
|
@user_is_cid_user_manager
|
||||||
def user_group_add_candidates_to_exams(request, group_id):
|
def user_group_add_candidates_to_exams(request, group_id):
|
||||||
|
|||||||
Reference in New Issue
Block a user