]> git.parisson.com Git - teleforma.git/commitdiff
script xls export
authorYoan Le Clanche <yoanl@pilotsystems.net>
Tue, 16 Dec 2025 09:07:47 +0000 (10:07 +0100)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Tue, 16 Dec 2025 09:07:47 +0000 (10:07 +0100)
teleforma/exam/admin.py

index b52fccd5fa94cfe3f9a3140d7edc1da26f99bc52..385d7a48ff95ff010f84016b047409206f184b13 100644 (file)
@@ -2,9 +2,11 @@
 import os
 
 from django.contrib import admin
+from django.http import HttpResponse
 from django.template.defaultfilters import filesizeformat
 from django.contrib.auth.models import User
 from django.db.models import Q
+from xlwt import Workbook
 
 from ..exam.models import Quota, Script, ScriptPage, ScriptType
 
@@ -49,7 +51,7 @@ class ScriptAdmin(admin.ModelAdmin):
                     'date_submitted', 'date_marked', 'date_rejected',
                    'author__student__platform_only']
     list_display = ['title', 'author_name', 'corrector', 'file_size', 'status']
-    actions = ['force_resubmit',]
+    actions = ['force_resubmit', 'export_xls']
 
     class Media:
         js = ("exam/js/admin.js",)
@@ -86,6 +88,37 @@ class ScriptAdmin(admin.ModelAdmin):
 
     force_resubmit.short_description = "Re-submit scripts"
 
+    def export_xls(self, request, queryset):
+        book = Workbook()
+        sheet = book.add_sheet('Scripts')
+
+        # En-têtes
+        cols = [
+            {'name': 'Identifiant', 'width': 5000},
+            {'name': 'Matière', 'width': 8000},
+            {'name': 'Séance', 'width': 3000},
+            {'name': 'Note', 'width': 3000},
+        ]
+        row = sheet.row(0)
+        for i, col in enumerate(cols):
+            row.write(i, col['name'])
+            sheet.col(i).width = col['width']
+
+        # Données
+        for i, script in enumerate(queryset):
+            row = sheet.row(i + 1)
+            row.write(0, script.author.username if script.author else '')
+            row.write(1, script.course.title if script.course else '')
+            row.write(2, script.session or '')
+            row.write(3, script.score if script.score is not None else '')
+
+        response = HttpResponse(content_type="application/vnd.ms-excel")
+        response['Content-Disposition'] = 'attachment; filename=scripts.xls'
+        book.save(response)
+        return response
+
+    export_xls.short_description = "Export vers XLS"
+
 
 admin.site.register(Script, ScriptAdmin)
 admin.site.register(ScriptPage)