mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
694 B
22 lines
694 B
import csv
|
|
import codecs
|
|
from django.http import HttpResponse
|
|
|
|
|
|
def get_excel_response(filename):
|
|
excel_response = HttpResponse(content_type='text/csv')
|
|
excel_response[
|
|
'Content-Disposition'] = 'attachment; filename="%s"' % filename
|
|
excel_response.write(codecs.BOM_UTF8)
|
|
return excel_response
|
|
|
|
|
|
def write_content_to_excel(response, header=None, login_logs=None, fields=None):
|
|
writer = csv.writer(response, dialect='excel', quoting=csv.QUOTE_MINIMAL)
|
|
if header:
|
|
writer.writerow(header)
|
|
if login_logs:
|
|
for log in login_logs:
|
|
data = [getattr(log, field.name) for field in fields]
|
|
writer.writerow(data)
|
|
return response |