Bladeren bron

设备导入修改

zhangnaiwen 2 jaren geleden
bovenliggende
commit
af70004d97
3 gewijzigde bestanden met toevoegingen van 5 en 9 verwijderingen
  1. BIN
      config/device.xls
  2. BIN
      config/device.xlsx
  3. 5 9
      src/app/api/device.py

BIN
config/device.xls


BIN
config/device.xlsx


+ 5 - 9
src/app/api/device.py

@@ -2,10 +2,9 @@ import json
 import os
 
 import xlrd
-from flask import request, jsonify, g, current_app, Response
+from flask import request, jsonify, current_app, Response
 from flask_restx import Resource, Namespace, reqparse
-from sqlalchemy import select, insert, update, delete, func
-from sqlalchemy.exc import IntegrityError
+from sqlalchemy import select, insert, update, delete
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 
@@ -345,7 +344,7 @@ class ImportDeviceApi(Resource):
         try:
             manage_path = os.path.dirname(os.path.abspath(__file__))
             config_yml_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(manage_path))), 'config',
-                                           'device.xlsx')
+                                           'device.xls')
 
             file_data = open(config_yml_path, 'rb')
             buf = file_data.read()
@@ -353,7 +352,7 @@ class ImportDeviceApi(Resource):
 
             response = Response(buf)
             response.headers['Content-Type'] = 'application/octet-stream'
-            response.headers['Content-Disposition'] = 'attachment; filename=%s' % 'device.xlsx'
+            response.headers['Content-Disposition'] = 'attachment; filename=%s' % 'device.xls'
 
             save_log(request, Module.DEVICE, OperationType.IMPORT, StatesCode.SUCCESS)
 
@@ -369,10 +368,7 @@ class ImportDeviceApi(Resource):
         device_file = request.files.get('files')
         device_group_id = request.form.get('group_id')
 
-        device_file_path = os.path.join(config.common.DEVICE_EXCEL_SAVE_PATH, device_file.name)
-        device_file.save(device_file_path)
-
-        xlsx = xlrd.open_workbook(device_file_path)
+        xlsx = xlrd.open_workbook(file_contents=device_file.read())
 
         with Session(current_app.engine) as session: