Skip to content

Commit

Permalink
feat: Add present count in meeting change form
Browse files Browse the repository at this point in the history
  • Loading branch information
lfavole committed Feb 10, 2025
1 parent 60b5041 commit 8df148a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions cate/common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class CommonMeetingAdmin(admin.ModelAdmin):
"""

change_list_template = "admin/change_list_meeting.html"
change_form_template = "admin/change_form_meeting.html"

fields = ("date", "kind", "name")
list_display = ("__str__", "date")
Expand Down
24 changes: 24 additions & 0 deletions cate/common/templates/admin/change_form_meeting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "admin/change_form.html" %}

{% block after_related_objects %}
{{ block.super }}
<p id="present-count"></p>
<script>
window.addEventListener("DOMContentLoaded", function() {
var present_count = document.getElementById("present-count");
var children_checkboxes = document.querySelectorAll("#attendances-group .field-is_present input");
function updatePresentCount() {
var count = 0;
for (var checkbox of children_checkboxes) {
if (checkbox.checked)
count++;
}
present_count.textContent = count + " enfant" + (count > 1 ? "s" : "") + " présent" + (count > 1 ? "s" : "") + " sur " + children_checkboxes.length + ". Taux de présence : " + (count / children_checkboxes.length * 100).toFixed(2) + "%";
}
for (var checkbox of children_checkboxes) {
checkbox.addEventListener("change", updatePresentCount);
}
updatePresentCount();
});
</script>
{% endblock after_related_objects %}

0 comments on commit 8df148a

Please sign in to comment.