e2d5dd6f by 冯轩

init

1 parent c8bacd75
1 from mimetypes import suffix_map
1 import os 2 import os
2 import io 3 import io
3 import time 4 import time
...@@ -1125,10 +1126,18 @@ class DocView(DocGenericView, DocHandler): ...@@ -1125,10 +1126,18 @@ class DocView(DocGenericView, DocHandler):
1125 random_int = random.randint(0, consts.TIME_NUM) 1126 random_int = random.randint(0, consts.TIME_NUM)
1126 metadata_version_id = str(int(time.time()) - random_int) 1127 metadata_version_id = str(int(time.time()) - random_int)
1127 1128
1129 # 现在不只接受pdf 图片也接收
1128 pdf_file = request.FILES.get('pdf_file') 1130 pdf_file = request.FILES.get('pdf_file')
1131 file_suffux = ''
1129 if isinstance(pdf_file.name, str): 1132 if isinstance(pdf_file.name, str):
1130 if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'): 1133 # if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'):
1131 self.invalid_params(msg='invalid params: not a PDF file') 1134 # self.invalid_params(msg='invalid params: not a PDF file')
1135 if '.' in pdf_file.name:
1136 file_suffux = pdf_file.name.split('.')[-1]
1137 else:
1138 self.invalid_params(msg='invalid params: invalid file name')
1139 else:
1140 self.invalid_params(msg='invalid params: invalid file name')
1132 1141
1133 business_type = request.POST.get('business_type', '') 1142 business_type = request.POST.get('business_type', '')
1134 document_scheme = request.POST.get('document_scheme', '') 1143 document_scheme = request.POST.get('document_scheme', '')
...@@ -1138,9 +1147,10 @@ class DocView(DocGenericView, DocHandler): ...@@ -1138,9 +1147,10 @@ class DocView(DocGenericView, DocHandler):
1138 args = {'business_type':business_type,'document_scheme':document_scheme,'data_source':data_source,'document_name':document_name,'pdf_file':pdf_file,'fsm':fsm} 1147 args = {'business_type':business_type,'document_scheme':document_scheme,'data_source':data_source,'document_name':document_name,'pdf_file':pdf_file,'fsm':fsm}
1139 # business_type = random.choice(consts.BUSINESS_TYPE_LIST) 1148 # business_type = random.choice(consts.BUSINESS_TYPE_LIST)
1140 # business_type = consts.BUSINESS_TYPE_LIST[0] 1149 # business_type = consts.BUSINESS_TYPE_LIST[0]
1141 tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id)) 1150 tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.{1}}'.format(metadata_version_id, file_suffux))
1142 file_write(pdf_file, tmp_save_path) 1151 file_write(pdf_file, tmp_save_path)
1143 1152
1153 if file_suffux.lower() == 'pdf':
1144 try: 1154 try:
1145 file = fitz.Document(tmp_save_path) 1155 file = fitz.Document(tmp_save_path)
1146 except Exception as e: 1156 except Exception as e:
...@@ -1194,7 +1204,7 @@ class DocView(DocGenericView, DocHandler): ...@@ -1194,7 +1204,7 @@ class DocView(DocGenericView, DocHandler):
1194 1204
1195 # 3.pdf文件移动 1205 # 3.pdf文件移动
1196 save_dir_path = os.path.join(conf.DATA_DIR, business_type, consts.TMP_DIR_NAME, str(doc.id)) 1206 save_dir_path = os.path.join(conf.DATA_DIR, business_type, consts.TMP_DIR_NAME, str(doc.id))
1197 save_file_path = os.path.join(save_dir_path, '{0}.pdf'.format(doc.id)) 1207 save_file_path = os.path.join(save_dir_path, '{0}.{1}'.format(doc.id, file_suffux))
1198 os.makedirs(save_dir_path, exist_ok=True) 1208 os.makedirs(save_dir_path, exist_ok=True)
1199 # file_write(pdf_file, save_file_path) 1209 # file_write(pdf_file, save_file_path)
1200 shutil.move(tmp_save_path, save_file_path) 1210 shutil.move(tmp_save_path, save_file_path)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!