diff --git a/server/apps/ability/views.py b/server/apps/ability/views.py index 88f855d..2351e76 100644 --- a/server/apps/ability/views.py +++ b/server/apps/ability/views.py @@ -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: diff --git a/server/db.sqlite3 b/server/db.sqlite3 index 1321971..ef598b6 100644 Binary files a/server/db.sqlite3 and b/server/db.sqlite3 differ