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"
return super(UserLoginView, self).dispatch(*args, **kwargs)
-class UserBook(object):
+class UserXLSBook(object):
first_row = 2
@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'