97574eac by 冯轩

MOD:文件和参数不能同时获取的问题

1 parent 97905aa8
...@@ -17,7 +17,7 @@ from webargs import fields, validate ...@@ -17,7 +17,7 @@ from webargs import fields, validate
17 from webargs.djangoparser import use_args, parser 17 from webargs.djangoparser import use_args, parser
18 from settings import conf 18 from settings import conf
19 from common import response 19 from common import response
20 from common.mixins import GenericView 20 from common.mixins import GenericView,DocGenericView
21 from common.tools.file_tools import file_write 21 from common.tools.file_tools import file_write
22 from common.redis_cache import redis_handler as rh 22 from common.redis_cache import redis_handler as rh
23 from .models import ( 23 from .models import (
...@@ -1039,7 +1039,7 @@ class CompareOfflineView(GenericView): ...@@ -1039,7 +1039,7 @@ class CompareOfflineView(GenericView):
1039 ''' 1039 '''
1040 1040
1041 1041
1042 class DocView(GenericView, DocHandler): 1042 class DocView(DocGenericView, DocHandler):
1043 1043
1044 # 文件列表页 1044 # 文件列表页
1045 @use_args(doc_list_args, location='querystring') 1045 @use_args(doc_list_args, location='querystring')
...@@ -1096,21 +1096,21 @@ class DocView(GenericView, DocHandler): ...@@ -1096,21 +1096,21 @@ class DocView(GenericView, DocHandler):
1096 return response.ok(data=res) 1096 return response.ok(data=res)
1097 1097
1098 # 上传pdf,模拟下单 1098 # 上传pdf,模拟下单
1099 @use_args(upload_pdf_args, location='files') 1099 # @use_args(upload_pdf_args)
1100 def post(self, request, args): 1100 def post(self, request):
1101 random_int = random.randint(0, consts.TIME_NUM) 1101 random_int = random.randint(0, consts.TIME_NUM)
1102 metadata_version_id = str(int(time.time()) - random_int) 1102 metadata_version_id = str(int(time.time()) - random_int)
1103 1103
1104 pdf_file = args.get('pdf_file') 1104 pdf_file = request.FILES.get('pdf_file')
1105 if isinstance(pdf_file.name, str): 1105 if isinstance(pdf_file.name, str):
1106 if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'): 1106 if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'):
1107 self.invalid_params(msg='invalid params: not a PDF file') 1107 self.invalid_params(msg='invalid params: not a PDF file')
1108 1108
1109 business_type = args.get('business_type', '') 1109 business_type = request.POST.get('business_type', '')
1110 document_scheme = args.get('document_scheme', '') 1110 document_scheme = request.POST.get('document_scheme', '')
1111 data_source = args.get('data_source', '') 1111 data_source = request.POST.get('data_source', '')
1112 document_name = args.get('document_name', '') 1112 document_name = request.POST.get('document_name', '')
1113 1113 args = {'business_type':business_type,'document_scheme':document_scheme,'data_source':data_source,'document_name':document_name,'pdf_file':pdf_file}
1114 # business_type = random.choice(consts.BUSINESS_TYPE_LIST) 1114 # business_type = random.choice(consts.BUSINESS_TYPE_LIST)
1115 # business_type = consts.BUSINESS_TYPE_LIST[0] 1115 # business_type = consts.BUSINESS_TYPE_LIST[0]
1116 tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id)) 1116 tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id))
......
...@@ -104,6 +104,62 @@ class GenericView(LoggerMixin, GenericExceptionMixin, GenericAPIView): ...@@ -104,6 +104,62 @@ class GenericView(LoggerMixin, GenericExceptionMixin, GenericAPIView):
104 def get_object(self): 104 def get_object(self):
105 return None 105 return None
106 106
107 class DocGenericView(LoggerMixin, GenericExceptionMixin, GenericAPIView):
108 need_print_logger = True
109
110 def print_logger(self, request):
111 # parameters = getattr(request, request.method, {})
112 parameters = None
113 if not parameters:
114 parameters = getattr(request, 'data', {})
115 if not parameters:
116 parameters = {}
117 parameters_string = ''
118 for key, value in parameters.items():
119 parameters_string += '[%s=%s] ' % (key, value)
120 for key, value in self.kwargs.items():
121 parameters_string += '[%s=%s] ' % (key, value)
122 if request.user and not isinstance(request.user, AnonymousUser):
123 user_id = request.user.id
124 else:
125 user_id = 0
126 self.running_log.info('[%s_%s_request] with parameters [user_id=%s] %s'
127 % (self.__class__.__name__, request.method,
128 user_id, parameters_string))
129
130 def dispatch(self, request, *args, **kwargs):
131 """
132 `.dispatch()` is pretty much the same as Django's regular dispatch,
133 but with extra hooks for startup, finalize, and exception handling.
134 """
135 self.args = args
136 self.kwargs = kwargs
137 request = self.initialize_request(request, *args, **kwargs)
138 self.request = request
139 self.headers = self.default_response_headers # deprecate?
140 try:
141 self.initial(request, *args, **kwargs)
142
143 # Get the appropriate handler method
144 if request.method.lower() in self.http_method_names:
145 handler = getattr(self, request.method.lower(),
146 self.http_method_not_allowed)
147 else:
148 handler = self.http_method_not_allowed
149
150 if self.need_print_logger:
151 self.print_logger(request)
152
153 response = handler(request, *args, **kwargs)
154 except Exception as exc:
155 response = self.handle_exception(exc)
156
157 self.response = self.finalize_response(
158 request, response, *args, **kwargs)
159 return self.response
160
161 def get_object(self):
162 return None
107 163
108 class IWABaseView: 164 class IWABaseView:
109 165
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!