add auto excel test
Showing
3 changed files
with
31 additions
and
2 deletions
... | @@ -6,6 +6,7 @@ urlpatterns = [ | ... | @@ -6,6 +6,7 @@ urlpatterns = [ |
6 | path(r'v1', views.CompareView.as_view()), | 6 | path(r'v1', views.CompareView.as_view()), |
7 | path(r'settlement/v1', views.SECompareView.as_view()), | 7 | path(r'settlement/v1', views.SECompareView.as_view()), |
8 | path(r'settlement/auto/v1', views.AutoSettlementView.as_view()), | 8 | path(r'settlement/auto/v1', views.AutoSettlementView.as_view()), |
9 | path(r'settlement/auto/wb/v1', views.AutoSettlementExcelView.as_view()), | ||
9 | path(r'settlement/cms/v1', views.SECMSView.as_view()), | 10 | path(r'settlement/cms/v1', views.SECMSView.as_view()), |
10 | path(r'offline/v1', views.CompareOfflineView.as_view()), | 11 | path(r'offline/v1', views.CompareOfflineView.as_view()), |
11 | path(r'result', views.CompareResultView.as_view()), | 12 | path(r'result', views.CompareResultView.as_view()), | ... | ... |
1 | import os | 1 | import os |
2 | import io | ||
2 | import time | 3 | import time |
3 | import json | 4 | import json |
4 | import random | 5 | import random |
5 | import datetime | 6 | import datetime |
6 | import fitz | 7 | import fitz |
7 | import shutil | 8 | import shutil |
9 | from openpyxl import Workbook | ||
8 | from django.utils import timezone | 10 | from django.utils import timezone |
9 | # from django.http import HttpResponse | 11 | # from django.http import HttpResponse |
10 | from django.db.models import Q | 12 | from django.db.models import Q |
... | @@ -1287,7 +1289,7 @@ class AutoSettlementView(GenericView): | ... | @@ -1287,7 +1289,7 @@ class AutoSettlementView(GenericView): |
1287 | # permission_classes = [IsAuthenticated] | 1289 | # permission_classes = [IsAuthenticated] |
1288 | # authentication_classes = [OAuth2AuthenticationWithUser] | 1290 | # authentication_classes = [OAuth2AuthenticationWithUser] |
1289 | 1291 | ||
1290 | # 获取比对结果 | 1292 | # 获取auto settlement列表 |
1291 | @use_args(auto_list_args, location='querystring') | 1293 | @use_args(auto_list_args, location='querystring') |
1292 | def get(self, request, args): | 1294 | def get(self, request, args): |
1293 | page = args.get('page', consts.PAGE_DEFAULT) | 1295 | page = args.get('page', consts.PAGE_DEFAULT) |
... | @@ -1356,3 +1358,22 @@ class AutoSettlementView(GenericView): | ... | @@ -1356,3 +1358,22 @@ class AutoSettlementView(GenericView): |
1356 | } | 1358 | } |
1357 | self.running_log.info('[get auto list] [args={0}] [res={1}]'.format(args, res)) | 1359 | self.running_log.info('[get auto list] [args={0}] [res={1}]'.format(args, res)) |
1358 | return response.ok(data=res) | 1360 | return response.ok(data=res) |
1361 | |||
1362 | |||
1363 | class AutoSettlementExcelView(GenericView): | ||
1364 | permission_classes = [] | ||
1365 | authentication_classes = [] | ||
1366 | # permission_classes = [IsAuthenticated] | ||
1367 | # authentication_classes = [OAuth2AuthenticationWithUser] | ||
1368 | |||
1369 | # 获取auto settlement excel | ||
1370 | @use_args(auto_list_args, location='querystring') | ||
1371 | def get(self, request, args): | ||
1372 | wb = Workbook() | ||
1373 | ws = wb.active | ||
1374 | ws.append(['序号', '告警id', '设备编号']) | ||
1375 | io_content = io.BytesIO() # 创建在内存中处理对象 | ||
1376 | wb.save(io_content) | ||
1377 | wb.close() | ||
1378 | file_name = 'AutoSettlement' | ||
1379 | return response.excel_response(file_name, io_content) | ... | ... |
1 | import enum | 1 | import enum |
2 | from django.http import JsonResponse | 2 | from django.http import JsonResponse, HttpResponse |
3 | from .named_enum import NamedEnum | 3 | from .named_enum import NamedEnum |
4 | 4 | ||
5 | 5 | ||
... | @@ -37,3 +37,10 @@ def ok(**kwargs): | ... | @@ -37,3 +37,10 @@ def ok(**kwargs): |
37 | 37 | ||
38 | def need_update(**kwargs): | 38 | def need_update(**kwargs): |
39 | return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs) | 39 | return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs) |
40 | |||
41 | |||
42 | def excel_response(file_name, io_content): | ||
43 | http_response = HttpResponse(content_type="application/vnd.ms-excel") | ||
44 | http_response['Content-Disposition'] = 'attachment;filename={0}.xlsx'.format(file_name) | ||
45 | http_response.write(io_content.getvalue()) | ||
46 | return http_response | ... | ... |
-
Please register or sign in to post a comment