From 5dc9ee3b8a781608aae72a40e68cc1dcb957aca0 Mon Sep 17 00:00:00 2001 From: scayac Date: Thu, 16 Oct 2025 21:07:50 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20exports=20=20suppl=C3=A9mentaires=20pou?= =?UTF-8?q?r=20les=20courses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/templates/course_detail.html | 94 ++++++++++++++++---- main/urls.py | 2 + main/views.py | 143 +++++++++++++++++++++++++++++- 3 files changed, 220 insertions(+), 19 deletions(-) diff --git a/main/templates/course_detail.html b/main/templates/course_detail.html index 05afda2..9a4403d 100644 --- a/main/templates/course_detail.html +++ b/main/templates/course_detail.html @@ -57,20 +57,42 @@ {% if course.type == 'multi' %} {% endif %} -
- {% csrf_token %} - - -
-
- {% csrf_token %} - - -
+ {% if export_options %} + + + + + {% endif %}
@@ -241,12 +263,48 @@ function getVisibleRows() { return JSON.stringify(rows); } -$('#exportCsvForm').on('submit', function(e) { - $('#csvRowsInput').val(getVisibleRows()); +// Handle custom export option buttons in the modal +$('.export-option-btn').on('click', function() { + var url = $(this).data('url'); + if (!url) return; + // Create a temporary form and submit POST with rows + var form = $('
'); + form.attr('action', url); + // Insert CSRF token from cookie + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie !== '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = cookies[i].trim(); + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + var csrf = getCookie('csrftoken'); + if (csrf) { + form.append($('').val(csrf)); + } + var input = $('').val(getVisibleRows()); + form.append(input); + // Append to body and submit + $('body').append(form); + form.submit(); }); -$('#exportPdfForm').on('submit', function(e) { - $('#pdfRowsInput').val(getVisibleRows()); +// Help button handler: show help text in a small modal +$(document).on('click', '.help-btn', function(e){ + e.stopPropagation(); // prevent triggering parent button + var helpText = $(this).data('help') || ''; + var modalHtml = '\n