【发布时间】:2022-07-21 16:31:47
【问题描述】:
_filename = f'summary_download_{_type}_{_from}_to_{_to}_{_encode}{_account}.zip'
attachment = 'attachment; filename*=utf-8\'\'' + urllib.parse.quote(_filename)
if _type == 'query':
header = ['date', 'user_name', 'sdgid', 'number_of_query', 'number_of_device']
if _type == 'threat':
header = ['date', 'user_name', 'sdgid', 'threat', 'number_of_query']
if _type == 'category':
header = ['date', 'user_name', 'sdgid', 'category', 'number_of_query']
if _type == 'specified_domain':
header = ['date', 'user_name', 'sdgid', 'specified_domain_list', 'number_of_query']
auditlog_data_frame = pd.DataFrame(data, columns=header)
auditlog_data_csv = auditlog_data_frame.to_csv(index=False, encoding='utf8')
auditlog_data_csv.split(';')
with TemporaryDirectory() as tmpdirname:
temp_zip_file_name = os.path.join(tmpdirname, os.path.basename(_filename))
zip_file = pyzipper.AESZipFile(
temp_zip_file_name,
'w',
compression=pyzipper.ZIP_DEFLATED,
encryption=pyzipper.WZ_AES
)
zip_file.setpassword(settings.ZIP_FILE_PASSWORD)
zip_file.writestr('summarydownload.csv', auditlog_data_csv)
zip_file.close()
response = HttpResponse(
open(temp_zip_file_name, 'rb'),
content_type='application/zip'
)
response['Content-Disposition'] = attachment
return response
【问题讨论】:
-
请edit您的帖子包含您对问题的任何其他信息。避免在 cmets 中添加它,因为它们更难阅读并且更容易删除。帖子的编辑按钮就在帖子标签的下方。
标签: python