From: Guillaume Pellerin Date: Mon, 18 May 2026 21:54:42 +0000 (+0200) Subject: add StudentReadingsXLSBook X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=186af5f6be514b7b504f72bdf97803dcc3bc245f;p=teleforma.git add StudentReadingsXLSBook --- diff --git a/teleforma/admin.py b/teleforma/admin.py index dc65bc83..204e471a 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -30,7 +30,7 @@ from .models.crfpa import (IEJ, Corrector, Discount, Home, NewsItem, OptionalFee, Parameters, Payback, Payment, Profile, Student, Training) from .models.messages import GroupedMessage, StudentGroup -from .views.crfpa import CorrectorXLSBook, UserXLSBook +from .views.crfpa import CorrectorXLSBook, UserXLSBook, StudentReadingsXLSBook from .views.core import get_periods from django.contrib.admin.helpers import ActionForm @@ -181,7 +181,7 @@ class StudentAdmin(StudentAdminMixin, admin.ModelAdmin): list_display = ['student_name', 'restricted', 'get_trainings', 'platform_only', 'total_payments', 'total_fees', 'balance', 'balance_intermediary'] readonly_fields = ['user', 'balance', 'balance_intermediary'] - actions = ['export_xls', 'write_message', 'add_to_group'] + actions = ['export_xls_training', 'export_xls_readings', 'write_message', 'add_to_group'] action_form = StudentGroupForm class Media: @@ -211,7 +211,7 @@ class StudentAdmin(StudentAdminMixin, admin.ModelAdmin): serializers.serialize("json", queryset, stream=response) return response - def export_xls(self, request, queryset): + def export_xls_training(self, request, queryset): book = UserXLSBook(students=queryset) book.write() response = HttpResponse(content_type="application/vnd.ms-excel") @@ -219,7 +219,16 @@ class StudentAdmin(StudentAdminMixin, admin.ModelAdmin): book.book.save(response) return response - export_xls.short_description = "Export vers XLS" + def export_xls_readings(self, request, queryset): + book = StudentReadingsXLSBook(students=queryset) + book.write() + response = HttpResponse(content_type="application/vnd.ms-excel") + response['Content-Disposition'] = 'attachment; filename=%s.xls' % queryset[0].user.username + book.book.save(response) + return response + + export_xls_training.short_description = "Export Formation (XLS)" + export_xls_readings.short_description = "Export Lectures (XLS)" def add_to_group(self, request, queryset): group_name = request.POST['group_name'] diff --git a/teleforma/middleware.py b/teleforma/middleware.py index 6d3188e7..9f4401fe 100644 --- a/teleforma/middleware.py +++ b/teleforma/middleware.py @@ -18,7 +18,6 @@ class XsSharing: """ This middleware allows cross-domain XHR using the html5 postMessage API. - Access-Control-Allow-Origin: http://foo.example Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE """ diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index 9cf737f8..689a5d36 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -1274,3 +1274,27 @@ class QuizQuestionView(CourseAccessMixin, QuizTake): validation.save() return render(self.request, 'quiz/result.html', results) + + + +class StudentXLSBook: + + def __init__(self, students): + self.book = Workbook() + if students: + self.student = students[0] + + self.sheet_docs = self.book.add_sheet('Documents') + self.sheet_media = self.book.add_sheet('Medias') + + def write(self): + row = 1 + for media_read in self.student.user.read.all(): + self.sheet_media.write(row, 0, str(media_read.media)) + row += 1 + + row = 1 + for doc_read in self.student.user.private_documents.all(): + self.sheet_docs.write(row, 0, str(media_read.media)) + row += 1 +