From: Guillaume Pellerin Date: Mon, 11 May 2015 22:28:35 +0000 (+0200) Subject: fix student XLS export in admin X-Git-Tag: 1.1~255 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=80a698a2935dd83e252da879f8546aeb86fa22b4;p=teleforma.git fix student XLS export in admin --- diff --git a/teleforma/admin.py b/teleforma/admin.py index 1ad03d46..f531f2eb 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -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" diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index 2353762d..6c5b396b 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -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'