This commit is contained in:
Ross
2021-12-11 23:55:43 +00:00
parent f0af4c6a4d
commit 16c5324051
2 changed files with 15 additions and 5 deletions
+13 -5
View File
@@ -17,10 +17,9 @@
{% render_table table %}
<details>
<summary>Add new CID users</summary>
<button id="add-new-cids">Add New</button>
<input type="number" id="add-number" value="number to add">
<summary><h3>Add/Edit CID users</h3></summary>
<button id="add-selected-cids">Add to selected</button>
<p>Select exams below to add user to.</p>
<div class="exam-selectors">
<span>
Physics Exams<br/>
@@ -67,6 +66,10 @@
</select>
</span>
<button id="add-new-cids">Add New</button>
<input type="number" id="add-number" value="number to add">
</div>
</details>
@@ -82,7 +85,12 @@
url: "{% url 'generic:create_cid_users' %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
number: $("#add-number").get(0).value
number: $("#add-number").get(0).value,
physics_exams: $("#physics-exams").val(),
rapid_exams: $("#rapid-exams").val(),
sbas_exams: $("#sbas-exams").val(),
longs_exams: $("#longs-exams").val(),
anatomy_exams: $("#anatomy-exams").val(),
},
type: "POST",
dataType: "json",
+2
View File
@@ -954,12 +954,14 @@ class CidUserView(LoginRequiredMixin, SingleTableMixin, FilterView):
def create_cid_users(request):
if request.is_ajax() and request.method == "POST":
number = int(request.POST.get("number"))
physics_exams = request.POST.get("physics_exams")
new_cid = max(CidUser.objects.all().order_by("-cid")[0].cid + 1, 50000)
for n in range(number):
passcode = "".join(random.choices(string.ascii_uppercase, k=4))
c = CidUser(cid=new_cid, passcode=passcode)
c.physics_exams.set(physics_exams)
c.save()
new_cid = new_cid + 1