feat: 新增pdf 删除
This commit is contained in:
parent
67eb4d8031
commit
bbca1a5114
|
@ -67,7 +67,7 @@ class AuditLogSerializer(serializers.ModelSerializer):
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class ParsepdfSerializer(serializers.ModelSerializer):
|
class ParsepdfSerializer(serializers.ModelSerializer):
|
||||||
|
dep = serializers.CharField(source='belong_dept.name', read_only=True)
|
||||||
class Meta(BaseMeta):
|
class Meta(BaseMeta):
|
||||||
model = Parsepdf
|
model = Parsepdf
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
|
@ -367,6 +367,21 @@ class ParsePdfViewSet(RbacFilterSet, CreateUpdateCustomMixin, ModelViewSet):
|
||||||
filterset_fields = ['belong_dept', 'annual']
|
filterset_fields = ['belong_dept', 'annual']
|
||||||
perms_map = {'get': '*', 'post': 'pdf_create'}
|
perms_map = {'get': '*', 'post': 'pdf_create'}
|
||||||
|
|
||||||
|
def destroy(self, request, *args, **kwargs):
|
||||||
|
# 判断执行状态,如果是“执行中”,则不允许删除
|
||||||
|
if self.get_object().status == "执行中":
|
||||||
|
return Response({'message': '执行中的数据不能删除'}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
# 删除文件
|
||||||
|
file_path = os.path.join(settings.BASE_DIR, self.get_object().parse_excel)
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
os.remove(file_path)
|
||||||
|
pdf_path = os.path.join(settings.BASE_DIR, self.get_object().pdf_path)
|
||||||
|
if os.path.exists(pdf_path):
|
||||||
|
os.remove(pdf_path)
|
||||||
|
|
||||||
|
# 删除数据库记录
|
||||||
|
return super().destroy(request, *args, **kwargs)
|
||||||
|
|
||||||
#解析pdf到excel
|
#解析pdf到excel
|
||||||
@action(detail=False, methods=['post'], perms_map={'post':'pdf_create'})
|
@action(detail=False, methods=['post'], perms_map={'post':'pdf_create'})
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
|
|
|
@ -345,7 +345,6 @@ def get_index(text, pattern, span):
|
||||||
return remain_text
|
return remain_text
|
||||||
|
|
||||||
def run(pdf_path, excel_path, id):
|
def run(pdf_path, excel_path, id):
|
||||||
print("-----------ids", id)
|
|
||||||
# 提取PDF文本
|
# 提取PDF文本
|
||||||
text = extract_text_from_pdf(pdf_path)
|
text = extract_text_from_pdf(pdf_path)
|
||||||
with open("pdf2txt.txt", "w", encoding="utf-8") as f:
|
with open("pdf2txt.txt", "w", encoding="utf-8") as f:
|
||||||
|
@ -353,7 +352,6 @@ def run(pdf_path, excel_path, id):
|
||||||
for pattern, local in RE_LIST:
|
for pattern, local in RE_LIST:
|
||||||
# 使用正则表达式匹配文本
|
# 使用正则表达式匹配文本
|
||||||
matches = match_text_with_regex(text, pattern, 1)
|
matches = match_text_with_regex(text, pattern, 1)
|
||||||
print(matches,"------")
|
|
||||||
fill_excel(matches, excel_path, local)
|
fill_excel(matches, excel_path, local)
|
||||||
# 特殊处理的
|
# 特殊处理的
|
||||||
for p, l, s in SPECIALLIST:
|
for p, l, s in SPECIALLIST:
|
||||||
|
|
Loading…
Reference in New Issue