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
a1a92499
authored
2020-06-22 14:24:08 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix demo interface
1 parent
0619bb0f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
12 deletions
src/apps/doc/consts.py
src/apps/doc/mixins.py
src/apps/doc/views.py
src/apps/urls.py
src/settings/__init__.py
src/settings/conf/_default_config.py
src/apps/doc/consts.py
0 → 100644
View file @
a1a9249
PAGE_DEFAULT
=
1
PAGE_SIZE_DEFAULT
=
10
src/apps/doc/mixins.py
View file @
a1a9249
import
os
from
settings
import
conf
from
.named_enum
import
DocStatus
class
DocHandler
:
@staticmethod
def
get_link
(
doc_id
,
file
=
'pdf'
):
data_path
=
os
.
path
.
join
(
conf
.
DATA_DIR
,
doc_id
)
data_path
=
os
.
path
.
join
(
conf
.
DATA_DIR
,
str
(
doc_id
)
)
if
file
==
'pdf'
:
return
os
.
path
.
join
(
data_path
,
'{0}.pdf'
.
format
(
doc_id
))
return
os
.
path
.
join
(
data_path
,
'{0}.pdf'
.
format
(
str
(
doc_id
)
))
elif
file
==
'img'
:
return
os
.
path
.
join
(
data_path
,
'{0}_img.zip'
.
format
(
doc_id
))
return
os
.
path
.
join
(
data_path
,
'{0}_img.zip'
.
format
(
str
(
doc_id
)
))
else
:
return
os
.
path
.
join
(
data_path
,
'{0}.xlsx'
.
format
(
doc_id
))
return
os
.
path
.
join
(
data_path
,
'{0}.xlsx'
.
format
(
str
(
doc_id
)
))
def
get_doc_list
(
self
,
doc_queryset
):
for
doc_dict
in
doc_queryset
:
if
doc_dict
[
'status'
]
!=
DocStatus
.
COMPLETE
.
value
:
continue
doc_id
=
doc_dict
.
get
(
'id'
)
doc_dict
[
'pdf_link'
]
=
self
.
get_link
(
doc_id
)
doc_dict
[
'img_link'
]
=
self
.
get_link
(
doc_id
,
'img'
)
...
...
src/apps/doc/views.py
View file @
a1a9249
...
...
@@ -13,6 +13,7 @@ from common.tools.file_tools import file_write
from
common.redis_cache
import
redis_handler
as
rh
from
.models
import
UploadDocRecords
,
DocStatus
from
.mixins
import
DocHandler
from
.
import
consts
# Create your views here.
...
...
@@ -49,6 +50,12 @@ doc_upload_args = {
}
doc_list_args
=
{
'page'
:
fields
.
Int
(
required
=
False
,
missing
=
consts
.
PAGE_DEFAULT
,
validate
=
lambda
val
:
val
>=
1
),
'page_size'
:
fields
.
Int
(
required
=
False
,
missing
=
consts
.
PAGE_SIZE_DEFAULT
,
validate
=
lambda
val
:
val
>=
1
),
'status'
:
fields
.
Int
(
required
=
False
,
validate
=
validate
.
OneOf
(
DocStatus
.
get_value_lst
())),
'application_id'
:
fields
.
Str
(
required
=
False
,
validate
=
validate
.
Length
(
max
=
64
)),
...
...
@@ -120,6 +127,8 @@ class DocView(GenericView, DocHandler):
# 文件列表页
@use_args
(
doc_list_args
,
location
=
'querystring'
)
def
get
(
self
,
request
,
args
):
page
=
args
.
get
(
'page'
,
consts
.
PAGE_DEFAULT
)
page_size
=
args
.
get
(
'page_size'
,
consts
.
PAGE_SIZE_DEFAULT
)
status
=
args
.
get
(
'status'
)
application_id
=
args
.
get
(
'application_id'
)
data_source
=
args
.
get
(
'data_source'
)
...
...
@@ -135,9 +144,20 @@ class DocView(GenericView, DocHandler):
query
=
status_query
&
application_id_query
&
data_source_query
&
business_type_query
\
&
upload_finish_time_query
&
create_time_query
doc_queryset
=
UploadDocRecords
.
objects
.
filter
(
query
)
.
values
(
'id'
,
'application_id'
,
'upload_finish_time'
,
'create_time'
,
'business_type'
,
'data_source'
)
'id'
,
'application_id'
,
'upload_finish_time'
,
'create_time'
,
'business_type'
,
'data_source'
,
'status'
)
doc_list
=
self
.
get_doc_list
(
doc_queryset
)
return
response
.
ok
(
data
=
doc_list
)
total
=
len
(
doc_list
)
start_index
=
page_size
*
(
page
-
1
)
end_index
=
page_size
*
page
if
start_index
>=
total
>
0
:
raise
self
.
invalid_params
(
'页数不存在'
)
pagination
=
{
'current'
:
page
,
'total'
:
total
,
'page_size'
:
page_size
}
res
=
{
'pagination'
:
pagination
,
'doc_list'
:
doc_list
[
start_index
:
end_index
]
}
return
response
.
ok
(
data
=
res
)
# 上传pdf,模拟下单
@use_args
(
upload_pdf_args
,
location
=
'files'
)
...
...
@@ -159,7 +179,9 @@ class DocView(GenericView, DocHandler):
rh
.
enqueue
(
doc
.
id
)
pdf_file
=
args
.
get
(
'pdf_file'
)
file_save_path
=
os
.
path
.
join
(
conf
.
DATA_DIR
,
doc
.
id
,
'{0}.pdf'
.
format
(
doc
.
id
))
file_write
(
pdf_file
,
file_save_path
)
self
.
running_log
.
info
(
'[doc upload success] [args={0}]'
.
format
(
args
))
save_dir_path
=
os
.
path
.
join
(
conf
.
DATA_DIR
,
str
(
doc
.
id
))
save_file_path
=
os
.
path
.
join
(
save_dir_path
,
'{0}.pdf'
.
format
(
doc
.
id
))
os
.
makedirs
(
save_dir_path
,
exist_ok
=
True
)
file_write
(
pdf_file
,
save_file_path
)
self
.
running_log
.
info
(
'[mock doc upload success] [doc_id={0}]'
.
format
(
doc
.
id
))
return
response
.
ok
()
...
...
src/apps/urls.py
View file @
a1a9249
...
...
@@ -18,7 +18,7 @@ from django.urls import path, include
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
r'api/user'
,
include
(
'apps.account.urls'
)),
path
(
r'api/user
/
'
,
include
(
'apps.account.urls'
)),
path
(
r'api/create/v1'
,
include
(
'apps.doc.urls'
)),
path
(
r'api/doc'
,
include
(
'apps.doc.internal_urls'
)),
path
(
r'api/doc
/
'
,
include
(
'apps.doc.internal_urls'
)),
]
...
...
src/settings/__init__.py
View file @
a1a9249
...
...
@@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import
os
import
hashlib
import
datetime
from
.
import
conf
,
database
from
logging
import
config
...
...
@@ -150,3 +152,17 @@ config.fileConfig(conf.LOGGING_CONFIG_FILE, disable_existing_loggers=False)
# url路径添加/
APPEND_SLASH
=
False
# JWT Settings
secret_key_md5
=
hashlib
.
md5
()
secret_key_md5
.
update
(
conf
.
JWT_SECRET_KEY
.
encode
(
'utf-8'
))
JWT_AUTH
=
{
'JWT_EXPIRATION_DELTA'
:
datetime
.
timedelta
(
days
=
conf
.
JWT_EXPIRATION_DAYS
),
'JWT_AUTH_HEADER_PREFIX'
:
'Bearer'
,
'JWT_SECRET_KEY'
:
secret_key_md5
.
hexdigest
(),
'JWT_ALGORITHM'
:
'HS256'
,
'JWT_LEEWAY'
:
0
,
'JWT_VERIFY'
:
True
,
'JWT_VERIFY_EXPIRATION'
:
True
,
'JWT_ALLOW_REFRESH'
:
True
,
}
...
...
src/settings/conf/_default_config.py
View file @
a1a9249
...
...
@@ -15,4 +15,4 @@ LOG_DIR = os.path.join(os.path.dirname(BASE_DIR), 'logs')
ALLOWED_HOSTS
=
'*'
# jwt过期时间
#
JWT_EXPIRATION_DAYS = 1
JWT_EXPIRATION_DAYS
=
1
...
...
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