fix demo interface
Showing
6 changed files
with
55 additions
and
12 deletions
src/apps/doc/consts.py
0 → 100644
| 1 | import os | 1 | import os |
| 2 | from settings import conf | 2 | from settings import conf |
| 3 | from .named_enum import DocStatus | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | class DocHandler: | 6 | class DocHandler: |
| 6 | 7 | ||
| 7 | @staticmethod | 8 | @staticmethod |
| 8 | def get_link(doc_id, file='pdf'): | 9 | def get_link(doc_id, file='pdf'): |
| 9 | data_path = os.path.join(conf.DATA_DIR, doc_id) | 10 | data_path = os.path.join(conf.DATA_DIR, str(doc_id)) |
| 10 | if file == 'pdf': | 11 | if file == 'pdf': |
| 11 | return os.path.join(data_path, '{0}.pdf'.format(doc_id)) | 12 | return os.path.join(data_path, '{0}.pdf'.format(str(doc_id))) |
| 12 | elif file == 'img': | 13 | elif file == 'img': |
| 13 | return os.path.join(data_path, '{0}_img.zip'.format(doc_id)) | 14 | return os.path.join(data_path, '{0}_img.zip'.format(str(doc_id))) |
| 14 | else: | 15 | else: |
| 15 | return os.path.join(data_path, '{0}.xlsx'.format(doc_id)) | 16 | return os.path.join(data_path, '{0}.xlsx'.format(str(doc_id))) |
| 16 | 17 | ||
| 17 | def get_doc_list(self, doc_queryset): | 18 | def get_doc_list(self, doc_queryset): |
| 18 | for doc_dict in doc_queryset: | 19 | for doc_dict in doc_queryset: |
| 20 | if doc_dict['status'] != DocStatus.COMPLETE.value: | ||
| 21 | continue | ||
| 19 | doc_id = doc_dict.get('id') | 22 | doc_id = doc_dict.get('id') |
| 20 | doc_dict['pdf_link'] = self.get_link(doc_id) | 23 | doc_dict['pdf_link'] = self.get_link(doc_id) |
| 21 | doc_dict['img_link'] = self.get_link(doc_id, 'img') | 24 | doc_dict['img_link'] = self.get_link(doc_id, 'img') | ... | ... |
| ... | @@ -13,6 +13,7 @@ from common.tools.file_tools import file_write | ... | @@ -13,6 +13,7 @@ from common.tools.file_tools import file_write |
| 13 | from common.redis_cache import redis_handler as rh | 13 | from common.redis_cache import redis_handler as rh |
| 14 | from .models import UploadDocRecords, DocStatus | 14 | from .models import UploadDocRecords, DocStatus |
| 15 | from .mixins import DocHandler | 15 | from .mixins import DocHandler |
| 16 | from . import consts | ||
| 16 | 17 | ||
| 17 | # Create your views here. | 18 | # Create your views here. |
| 18 | 19 | ||
| ... | @@ -49,6 +50,12 @@ doc_upload_args = { | ... | @@ -49,6 +50,12 @@ doc_upload_args = { |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | doc_list_args = { | 52 | doc_list_args = { |
| 53 | 'page': fields.Int(required=False, | ||
| 54 | missing=consts.PAGE_DEFAULT, | ||
| 55 | validate=lambda val: val >= 1), | ||
| 56 | 'page_size': fields.Int(required=False, | ||
| 57 | missing=consts.PAGE_SIZE_DEFAULT, | ||
| 58 | validate=lambda val: val >= 1), | ||
| 52 | 'status': fields.Int(required=False, | 59 | 'status': fields.Int(required=False, |
| 53 | validate=validate.OneOf(DocStatus.get_value_lst())), | 60 | validate=validate.OneOf(DocStatus.get_value_lst())), |
| 54 | 'application_id': fields.Str(required=False, validate=validate.Length(max=64)), | 61 | 'application_id': fields.Str(required=False, validate=validate.Length(max=64)), |
| ... | @@ -120,6 +127,8 @@ class DocView(GenericView, DocHandler): | ... | @@ -120,6 +127,8 @@ class DocView(GenericView, DocHandler): |
| 120 | # 文件列表页 | 127 | # 文件列表页 |
| 121 | @use_args(doc_list_args, location='querystring') | 128 | @use_args(doc_list_args, location='querystring') |
| 122 | def get(self, request, args): | 129 | def get(self, request, args): |
| 130 | page = args.get('page', consts.PAGE_DEFAULT) | ||
| 131 | page_size = args.get('page_size', consts.PAGE_SIZE_DEFAULT) | ||
| 123 | status = args.get('status') | 132 | status = args.get('status') |
| 124 | application_id = args.get('application_id') | 133 | application_id = args.get('application_id') |
| 125 | data_source = args.get('data_source') | 134 | data_source = args.get('data_source') |
| ... | @@ -135,9 +144,20 @@ class DocView(GenericView, DocHandler): | ... | @@ -135,9 +144,20 @@ class DocView(GenericView, DocHandler): |
| 135 | query = status_query & application_id_query & data_source_query & business_type_query\ | 144 | query = status_query & application_id_query & data_source_query & business_type_query\ |
| 136 | & upload_finish_time_query & create_time_query | 145 | & upload_finish_time_query & create_time_query |
| 137 | doc_queryset = UploadDocRecords.objects.filter(query).values( | 146 | doc_queryset = UploadDocRecords.objects.filter(query).values( |
| 138 | 'id', 'application_id', 'upload_finish_time', 'create_time', 'business_type', 'data_source') | 147 | 'id', 'application_id', 'upload_finish_time', 'create_time', 'business_type', 'data_source', 'status') |
| 139 | doc_list = self.get_doc_list(doc_queryset) | 148 | doc_list = self.get_doc_list(doc_queryset) |
| 140 | return response.ok(data=doc_list) | 149 | |
| 150 | total = len(doc_list) | ||
| 151 | start_index = page_size * (page - 1) | ||
| 152 | end_index = page_size * page | ||
| 153 | if start_index >= total > 0: | ||
| 154 | raise self.invalid_params('页数不存在') | ||
| 155 | pagination = {'current': page, 'total': total, 'page_size': page_size} | ||
| 156 | res = { | ||
| 157 | 'pagination': pagination, | ||
| 158 | 'doc_list': doc_list[start_index: end_index] | ||
| 159 | } | ||
| 160 | return response.ok(data=res) | ||
| 141 | 161 | ||
| 142 | # 上传pdf,模拟下单 | 162 | # 上传pdf,模拟下单 |
| 143 | @use_args(upload_pdf_args, location='files') | 163 | @use_args(upload_pdf_args, location='files') |
| ... | @@ -159,7 +179,9 @@ class DocView(GenericView, DocHandler): | ... | @@ -159,7 +179,9 @@ class DocView(GenericView, DocHandler): |
| 159 | rh.enqueue(doc.id) | 179 | rh.enqueue(doc.id) |
| 160 | 180 | ||
| 161 | pdf_file = args.get('pdf_file') | 181 | pdf_file = args.get('pdf_file') |
| 162 | file_save_path = os.path.join(conf.DATA_DIR, doc.id, '{0}.pdf'.format(doc.id)) | 182 | save_dir_path = os.path.join(conf.DATA_DIR, str(doc.id)) |
| 163 | file_write(pdf_file, file_save_path) | 183 | save_file_path = os.path.join(save_dir_path, '{0}.pdf'.format(doc.id)) |
| 164 | self.running_log.info('[doc upload success] [args={0}]'.format(args)) | 184 | os.makedirs(save_dir_path, exist_ok=True) |
| 185 | file_write(pdf_file, save_file_path) | ||
| 186 | self.running_log.info('[mock doc upload success] [doc_id={0}]'.format(doc.id)) | ||
| 165 | return response.ok() | 187 | return response.ok() | ... | ... |
| ... | @@ -18,7 +18,7 @@ from django.urls import path, include | ... | @@ -18,7 +18,7 @@ from django.urls import path, include |
| 18 | 18 | ||
| 19 | urlpatterns = [ | 19 | urlpatterns = [ |
| 20 | path('admin/', admin.site.urls), | 20 | path('admin/', admin.site.urls), |
| 21 | path(r'api/user', include('apps.account.urls')), | 21 | path(r'api/user/', include('apps.account.urls')), |
| 22 | path(r'api/create/v1', include('apps.doc.urls')), | 22 | path(r'api/create/v1', include('apps.doc.urls')), |
| 23 | path(r'api/doc', include('apps.doc.internal_urls')), | 23 | path(r'api/doc/', include('apps.doc.internal_urls')), |
| 24 | ] | 24 | ] | ... | ... |
| ... | @@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ | ... | @@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ |
| 11 | """ | 11 | """ |
| 12 | 12 | ||
| 13 | import os | 13 | import os |
| 14 | import hashlib | ||
| 15 | import datetime | ||
| 14 | from . import conf, database | 16 | from . import conf, database |
| 15 | from logging import config | 17 | from logging import config |
| 16 | 18 | ||
| ... | @@ -150,3 +152,17 @@ config.fileConfig(conf.LOGGING_CONFIG_FILE, disable_existing_loggers=False) | ... | @@ -150,3 +152,17 @@ config.fileConfig(conf.LOGGING_CONFIG_FILE, disable_existing_loggers=False) |
| 150 | 152 | ||
| 151 | # url路径添加/ | 153 | # url路径添加/ |
| 152 | APPEND_SLASH = False | 154 | APPEND_SLASH = False |
| 155 | |||
| 156 | # JWT Settings | ||
| 157 | secret_key_md5 = hashlib.md5() | ||
| 158 | secret_key_md5.update(conf.JWT_SECRET_KEY.encode('utf-8')) | ||
| 159 | JWT_AUTH = { | ||
| 160 | 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=conf.JWT_EXPIRATION_DAYS), | ||
| 161 | 'JWT_AUTH_HEADER_PREFIX': 'Bearer', | ||
| 162 | 'JWT_SECRET_KEY': secret_key_md5.hexdigest(), | ||
| 163 | 'JWT_ALGORITHM': 'HS256', | ||
| 164 | 'JWT_LEEWAY': 0, | ||
| 165 | 'JWT_VERIFY': True, | ||
| 166 | 'JWT_VERIFY_EXPIRATION': True, | ||
| 167 | 'JWT_ALLOW_REFRESH': True, | ||
| 168 | } | ... | ... |
-
Please register or sign in to post a comment