cma2
This commit is contained in:
parent
c710920f6e
commit
55b5d38fe3
|
|
@ -56,7 +56,21 @@ class CMAViewSet(ModelViewSet):
|
||||||
CMA.objects.filter(type='center').delete()
|
CMA.objects.filter(type='center').delete()
|
||||||
for root, dirs, files in os.walk(fulldir):
|
for root, dirs, files in os.walk(fulldir):
|
||||||
for f in files:
|
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))
|
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)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
@action(methods=['post'], detail=False, url_path='import2', url_name='cma_import2', perms_map = {'post':'cma_import2'})
|
@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()
|
CMA.objects.filter(type='sub').delete()
|
||||||
for root, dirs, files in os.walk(fulldir):
|
for root, dirs, files in os.walk(fulldir):
|
||||||
for f in files:
|
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))
|
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)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
class CNASViewSet(ModelViewSet):
|
class CNASViewSet(ModelViewSet):
|
||||||
|
|
@ -113,6 +141,18 @@ class CNASViewSet(ModelViewSet):
|
||||||
if f.endswith('.xls'):
|
if f.endswith('.xls'):
|
||||||
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
|
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
|
||||||
import_cnas(f, os.path.join(root,f))
|
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)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
def import_cma(filename, path):
|
def import_cma(filename, path):
|
||||||
|
|
@ -253,7 +293,7 @@ def import_cma2(filename, path):
|
||||||
m = m - 1
|
m = m - 1
|
||||||
if sheet['h'+str(i)].value:
|
if sheet['h'+str(i)].value:
|
||||||
data['bzbh'] = sheet['h'+str(i)].value
|
data['bzbh'] = sheet['h'+str(i)].value
|
||||||
else:
|
elif sheet['h3'].value:
|
||||||
m = i - 1
|
m = i - 1
|
||||||
while True:
|
while True:
|
||||||
if sheet['h'+str(m)].value:
|
if sheet['h'+str(m)].value:
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue