43ce3393 by 周伟奇

add auto excel test

1 parent 135d5714
......@@ -6,6 +6,7 @@ urlpatterns = [
path(r'v1', views.CompareView.as_view()),
path(r'settlement/v1', views.SECompareView.as_view()),
path(r'settlement/auto/v1', views.AutoSettlementView.as_view()),
path(r'settlement/auto/wb/v1', views.AutoSettlementExcelView.as_view()),
path(r'settlement/cms/v1', views.SECMSView.as_view()),
path(r'offline/v1', views.CompareOfflineView.as_view()),
path(r'result', views.CompareResultView.as_view()),
......
import os
import io
import time
import json
import random
import datetime
import fitz
import shutil
from openpyxl import Workbook
from django.utils import timezone
# from django.http import HttpResponse
from django.db.models import Q
......@@ -1287,7 +1289,7 @@ class AutoSettlementView(GenericView):
# permission_classes = [IsAuthenticated]
# authentication_classes = [OAuth2AuthenticationWithUser]
# 获取比对结果
# 获取auto settlement列表
@use_args(auto_list_args, location='querystring')
def get(self, request, args):
page = args.get('page', consts.PAGE_DEFAULT)
......@@ -1356,3 +1358,22 @@ class AutoSettlementView(GenericView):
}
self.running_log.info('[get auto list] [args={0}] [res={1}]'.format(args, res))
return response.ok(data=res)
class AutoSettlementExcelView(GenericView):
permission_classes = []
authentication_classes = []
# permission_classes = [IsAuthenticated]
# authentication_classes = [OAuth2AuthenticationWithUser]
# 获取auto settlement excel
@use_args(auto_list_args, location='querystring')
def get(self, request, args):
wb = Workbook()
ws = wb.active
ws.append(['序号', '告警id', '设备编号'])
io_content = io.BytesIO() # 创建在内存中处理对象
wb.save(io_content)
wb.close()
file_name = 'AutoSettlement'
return response.excel_response(file_name, io_content)
......
import enum
from django.http import JsonResponse
from django.http import JsonResponse, HttpResponse
from .named_enum import NamedEnum
......@@ -37,3 +37,10 @@ def ok(**kwargs):
def need_update(**kwargs):
return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs)
def excel_response(file_name, io_content):
http_response = HttpResponse(content_type="application/vnd.ms-excel")
http_response['Content-Disposition'] = 'attachment;filename={0}.xlsx'.format(file_name)
http_response.write(io_content.getvalue())
return http_response
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!