]> git.parisson.com Git - teleforma.git/commitdiff
fix student XLS export in admin
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 11 May 2015 22:28:35 +0000 (00:28 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 11 May 2015 22:28:35 +0000 (00:28 +0200)
teleforma/admin.py
teleforma/views/crfpa.py

index 1ad03d4608b998067fdf925bdd1b30aa42fe6b5f..f531f2ebc44b1efdd2d8db8e77bfcaebe4bbabc5 100644 (file)
@@ -83,9 +83,13 @@ class StudentAdmin(admin.ModelAdmin):
         return response
 
     def export_xls(self, request, queryset):
-        view = UsersExportView()
-        view.users = queryset
-        return view.get(request)
+        users = [student.user for student in queryset]
+        book = UserXLSBook(users)
+        book.write()
+        response = HttpResponse(mimetype="application/vnd.ms-excel")
+        response['Content-Disposition'] = 'attachment; filename=users.xls'
+        book.book.save(response)
+        return response
 
     export_xls.short_description = "Export to XLS"
 
index 2353762d73fbb964295ec248d4e443d12f0cd7a7..6c5b396bef3c6bb1d0ab5d0bcf9537be6ff698dd 100644 (file)
@@ -203,7 +203,7 @@ class UserLoginView(View):
         return super(UserLoginView, self).dispatch(*args, **kwargs)
 
 
-class UserBook(object):
+class UserXLSBook(object):
 
     first_row = 2
 
@@ -283,7 +283,7 @@ class UsersExportView(UsersView):
     @method_decorator(permission_required('is_staff'))
     def get(self, *args, **kwargs):
         super(UsersExportView, self).get(*args, **kwargs)
-        book = UserBook(self.users)
+        book = UserXLSBook(self.users)
         book.write()
         response = HttpResponse(mimetype="application/vnd.ms-excel")
         response['Content-Disposition'] = 'attachment; filename=users.xls'