Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
97574eac
authored
2023-03-30 14:48:17 +0800
by
冯轩
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
MOD:文件和参数不能同时获取的问题
1 parent
97905aa8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
10 deletions
src/apps/doc/views.py
src/common/mixins.py
src/apps/doc/views.py
View file @
97574ea
...
...
@@ -17,7 +17,7 @@ from webargs import fields, validate
from
webargs.djangoparser
import
use_args
,
parser
from
settings
import
conf
from
common
import
response
from
common.mixins
import
GenericView
from
common.mixins
import
GenericView
,
DocGenericView
from
common.tools.file_tools
import
file_write
from
common.redis_cache
import
redis_handler
as
rh
from
.models
import
(
...
...
@@ -1039,7 +1039,7 @@ class CompareOfflineView(GenericView):
'''
class
DocView
(
GenericView
,
DocHandler
):
class
DocView
(
Doc
GenericView
,
DocHandler
):
# 文件列表页
@use_args
(
doc_list_args
,
location
=
'querystring'
)
...
...
@@ -1096,21 +1096,21 @@ class DocView(GenericView, DocHandler):
return
response
.
ok
(
data
=
res
)
# 上传pdf,模拟下单
@use_args
(
upload_pdf_args
,
location
=
'files'
)
def
post
(
self
,
request
,
args
):
# @use_args(upload_pdf_args
)
def
post
(
self
,
request
):
random_int
=
random
.
randint
(
0
,
consts
.
TIME_NUM
)
metadata_version_id
=
str
(
int
(
time
.
time
())
-
random_int
)
pdf_file
=
args
.
get
(
'pdf_file'
)
pdf_file
=
request
.
FILES
.
get
(
'pdf_file'
)
if
isinstance
(
pdf_file
.
name
,
str
):
if
not
pdf_file
.
name
.
endswith
(
'pdf'
)
and
not
pdf_file
.
name
.
endswith
(
'PDF'
):
self
.
invalid_params
(
msg
=
'invalid params: not a PDF file'
)
business_type
=
args
.
get
(
'business_type'
,
''
)
document_scheme
=
args
.
get
(
'document_scheme'
,
''
)
data_source
=
args
.
get
(
'data_source'
,
''
)
document_name
=
args
.
get
(
'document_name'
,
''
)
business_type
=
request
.
POST
.
get
(
'business_type'
,
''
)
document_scheme
=
request
.
POST
.
get
(
'document_scheme'
,
''
)
data_source
=
request
.
POST
.
get
(
'data_source'
,
''
)
document_name
=
request
.
POST
.
get
(
'document_name'
,
''
)
args
=
{
'business_type'
:
business_type
,
'document_scheme'
:
document_scheme
,
'data_source'
:
data_source
,
'document_name'
:
document_name
,
'pdf_file'
:
pdf_file
}
# business_type = random.choice(consts.BUSINESS_TYPE_LIST)
# business_type = consts.BUSINESS_TYPE_LIST[0]
tmp_save_path
=
os
.
path
.
join
(
conf
.
DATA_DIR
,
business_type
,
'{0}.pdf'
.
format
(
metadata_version_id
))
...
...
src/common/mixins.py
View file @
97574ea
...
...
@@ -104,6 +104,62 @@ class GenericView(LoggerMixin, GenericExceptionMixin, GenericAPIView):
def
get_object
(
self
):
return
None
class
DocGenericView
(
LoggerMixin
,
GenericExceptionMixin
,
GenericAPIView
):
need_print_logger
=
True
def
print_logger
(
self
,
request
):
# parameters = getattr(request, request.method, {})
parameters
=
None
if
not
parameters
:
parameters
=
getattr
(
request
,
'data'
,
{})
if
not
parameters
:
parameters
=
{}
parameters_string
=
''
for
key
,
value
in
parameters
.
items
():
parameters_string
+=
'[
%
s=
%
s] '
%
(
key
,
value
)
for
key
,
value
in
self
.
kwargs
.
items
():
parameters_string
+=
'[
%
s=
%
s] '
%
(
key
,
value
)
if
request
.
user
and
not
isinstance
(
request
.
user
,
AnonymousUser
):
user_id
=
request
.
user
.
id
else
:
user_id
=
0
self
.
running_log
.
info
(
'[
%
s_
%
s_request] with parameters [user_id=
%
s]
%
s'
%
(
self
.
__class__
.
__name__
,
request
.
method
,
user_id
,
parameters_string
))
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
"""
`.dispatch()` is pretty much the same as Django's regular dispatch,
but with extra hooks for startup, finalize, and exception handling.
"""
self
.
args
=
args
self
.
kwargs
=
kwargs
request
=
self
.
initialize_request
(
request
,
*
args
,
**
kwargs
)
self
.
request
=
request
self
.
headers
=
self
.
default_response_headers
# deprecate?
try
:
self
.
initial
(
request
,
*
args
,
**
kwargs
)
# Get the appropriate handler method
if
request
.
method
.
lower
()
in
self
.
http_method_names
:
handler
=
getattr
(
self
,
request
.
method
.
lower
(),
self
.
http_method_not_allowed
)
else
:
handler
=
self
.
http_method_not_allowed
if
self
.
need_print_logger
:
self
.
print_logger
(
request
)
response
=
handler
(
request
,
*
args
,
**
kwargs
)
except
Exception
as
exc
:
response
=
self
.
handle_exception
(
exc
)
self
.
response
=
self
.
finalize_response
(
request
,
response
,
*
args
,
**
kwargs
)
return
self
.
response
def
get_object
(
self
):
return
None
class
IWABaseView
:
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment