fix: 导入时使用get('')结构,并先删除文件夹

This commit is contained in:
caoqianming 2023-04-07 10:40:36 +08:00
parent 2dfaa6a273
commit fae6fbde88
3 changed files with 16 additions and 4 deletions

View File

@ -3,8 +3,8 @@ ENV = 'development'
# base api # base api
#VUE_APP_BASE_API = 'http://10.0.11.127:8000/api' #VUE_APP_BASE_API = 'http://10.0.11.127:8000/api'
#VUE_APP_BASE_API = 'http://127.0.0.1:2222/api' VUE_APP_BASE_API = 'http://127.0.0.1:2222/api'
VUE_APP_BASE_API = 'https://testsearch.ctc.ac.cn/api' # VUE_APP_BASE_API = 'https://testsearch.ctc.ac.cn/api'
#VUE_APP_BASE_API = 'http://47.95.0.242:9101/api' #VUE_APP_BASE_API = 'http://47.95.0.242:9101/api'

View File

@ -219,6 +219,9 @@ class CMAViewSet(RecordMixin, ModelViewSet):
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST) return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
elif fullpath.endswith('.zip'): elif fullpath.endswith('.zip'):
fulldir = fullpath.replace('.zip','') fulldir = fullpath.replace('.zip','')
if os.path.exists(fulldir):
import shutil
shutil.rmtree(fulldir) # 先删除该文件夹
os.mkdir(fulldir) os.mkdir(fulldir)
os.chdir(fulldir) os.chdir(fulldir)
CMA.objects.filter(type='center').delete() CMA.objects.filter(type='center').delete()
@ -255,6 +258,9 @@ class CMAViewSet(RecordMixin, ModelViewSet):
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST) return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
elif fullpath.endswith('.zip'): elif fullpath.endswith('.zip'):
fulldir = fullpath.replace('.zip','') fulldir = fullpath.replace('.zip','')
if os.path.exists(fulldir):
import shutil
shutil.rmtree(fulldir) # 先删除该文件夹
os.mkdir(fulldir) os.mkdir(fulldir)
os.chdir(fulldir) os.chdir(fulldir)
# CMA.objects.filter(type='sub').delete() # CMA.objects.filter(type='sub').delete()
@ -416,6 +422,9 @@ class InspectionViewSet(RecordMixin, ModelViewSet):
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST) return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
elif fullpath.endswith('.zip'): elif fullpath.endswith('.zip'):
fulldir = fullpath.replace('.zip','') fulldir = fullpath.replace('.zip','')
if os.path.exists(fulldir):
import shutil
shutil.rmtree(fulldir) # 先删除该文件夹
os.mkdir(fulldir) os.mkdir(fulldir)
os.chdir(fulldir) os.chdir(fulldir)
# CMA.objects.filter(type='sub').delete() # CMA.objects.filter(type='sub').delete()
@ -481,6 +490,9 @@ class CNASViewSet(RecordMixin, ModelViewSet):
import_cnas(f, os.path.join(root,f)) import_cnas(f, os.path.join(root,f))
elif fullpath.endswith('.zip'): elif fullpath.endswith('.zip'):
fulldir = fullpath.replace('.zip','') fulldir = fullpath.replace('.zip','')
if os.path.exists(fulldir):
import shutil
shutil.rmtree(fulldir) # 先删除该文件夹
os.mkdir(fulldir) os.mkdir(fulldir)
os.chdir(fulldir) os.chdir(fulldir)
CNAS.objects.all().delete() CNAS.objects.all().delete()
@ -651,7 +663,7 @@ def import_cma2(filename, path):
data['lbxh'] = sheet['c'+str(i)].value data['lbxh'] = sheet['c'+str(i)].value
defaultv['lbxh'] = data['lbxh'] defaultv['lbxh'] = data['lbxh']
else: else:
data['lbxh'] = defaultv['lbxh'] data['lbxh'] = defaultv.get('lbxh', '')
if sheet['d'+str(i)].value: if sheet['d'+str(i)].value:
data['lbmc'] = sheet['d'+str(i)].value data['lbmc'] = sheet['d'+str(i)].value
defaultv['lbmc'] = data['lbmc'] defaultv['lbmc'] = data['lbmc']
@ -661,7 +673,7 @@ def import_cma2(filename, path):
data['xmxh'] = sheet['e'+str(i)].value data['xmxh'] = sheet['e'+str(i)].value
defaultv['xmxh'] = data['xmxh'] defaultv['xmxh'] = data['xmxh']
else: else:
data['xmxh'] = defaultv.get('xmxh', None) data['xmxh'] = defaultv.get('xmxh', '')
if sheet['f'+str(i)].value: if sheet['f'+str(i)].value:
data['xmmc'] = sheet['f'+str(i)].value data['xmmc'] = sheet['f'+str(i)].value
defaultv['xmmc'] = data['xmmc'] defaultv['xmmc'] = data['xmmc']