This commit is contained in:
caoqianming 2020-07-05 17:08:20 +08:00
parent c710920f6e
commit 55b5d38fe3
2 changed files with 41 additions and 1 deletions

View File

@ -56,7 +56,21 @@ class CMAViewSet(ModelViewSet):
CMA.objects.filter(type='center').delete()
for root, dirs, files in os.walk(fulldir):
for f in files:
if f.endswith('.xls'):
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
import_cma(f, os.path.join(root,f))
elif fullpath.endswith('.zip'):
fulldir = fullpath.replace('.zip','')
os.mkdir(fulldir)
os.chdir(fulldir)
CMA.objects.filter(type='center').delete()
with zipfile.ZipFile(fullpath,'r') as zzz:
zzz.extractall(fulldir)
for root, dirs, files in os.walk(fulldir):
for f in files:
if f.endswith('.xls'):
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
import_cma(f.encode('cp437').decode('gbk'), os.path.join(root,f))
return Response(status = status.HTTP_200_OK)
@action(methods=['post'], detail=False, url_path='import2', url_name='cma_import2', perms_map = {'post':'cma_import2'})
@ -77,7 +91,21 @@ class CMAViewSet(ModelViewSet):
CMA.objects.filter(type='sub').delete()
for root, dirs, files in os.walk(fulldir):
for f in files:
if f.endswith('.xls'):
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
import_cma2(f, os.path.join(root,f))
elif fullpath.endswith('.zip'):
fulldir = fullpath.replace('.zip','')
os.mkdir(fulldir)
os.chdir(fulldir)
CMA.objects.filter(type='sub').delete()
with zipfile.ZipFile(fullpath,'r') as zzz:
zzz.extractall(fulldir)
for root, dirs, files in os.walk(fulldir):
for f in files:
if f.endswith('.xls'):
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
import_cma2(f.encode('cp437').decode('gbk'), os.path.join(root,f))
return Response(status = status.HTTP_200_OK)
class CNASViewSet(ModelViewSet):
@ -113,6 +141,18 @@ class CNASViewSet(ModelViewSet):
if f.endswith('.xls'):
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
import_cnas(f, os.path.join(root,f))
elif fullpath.endswith('.zip'):
fulldir = fullpath.replace('.zip','')
os.mkdir(fulldir)
os.chdir(fulldir)
CNAS.objects.all().delete()
with zipfile.ZipFile(fullpath,'r') as zzz:
zzz.extractall(fulldir)
for root, dirs, files in os.walk(fulldir):
for f in files:
if f.endswith('.xls'):
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
import_cnas(f.encode('cp437').decode('gbk'), os.path.join(root,f))
return Response(status = status.HTTP_200_OK)
def import_cma(filename, path):
@ -253,7 +293,7 @@ def import_cma2(filename, path):
m = m - 1
if sheet['h'+str(i)].value:
data['bzbh'] = sheet['h'+str(i)].value
else:
elif sheet['h3'].value:
m = i - 1
while True:
if sheet['h'+str(m)].value:

Binary file not shown.