]> git.parisson.com Git - teleforma.git/commitdiff
add StudentReadingsXLSBook
authorGuillaume Pellerin <guillaume.pellerin@parisson.com>
Mon, 18 May 2026 21:54:42 +0000 (23:54 +0200)
committerGuillaume Pellerin <guillaume.pellerin@parisson.com>
Mon, 18 May 2026 21:54:42 +0000 (23:54 +0200)
teleforma/admin.py
teleforma/middleware.py
teleforma/views/crfpa.py

index dc65bc83496f05e47e1e1e79eb1c51eef0b2b6ef..204e471a41474c4f370fcd6039b370e2e20c3883 100644 (file)
@@ -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']
index 6d3188e7f4d469993fd865cad65be0ef13acd8c1..9f4401fe803c1154202f04220c648fca4191bef6 100644 (file)
@@ -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
     """
index 9cf737f87d41ffaa09621ec74472c725d25a826e..689a5d3692862549b9607e337911a43adfe609ba 100644 (file)
@@ -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
+