upload doc interface
Showing
10 changed files
with
117 additions
and
1 deletions
src/apps/doc/__init__.py
0 → 100644
File mode changed
src/apps/doc/admin.py
0 → 100644
src/apps/doc/apps.py
0 → 100644
src/apps/doc/models.py
0 → 100644
1 | from django.db import models | ||
2 | |||
3 | # Create your models here. | ||
4 | |||
5 | |||
6 | class Document(models.Model): | ||
7 | id = models.AutoField(primary_key=True, verbose_name="id") | ||
8 | application_id = models.CharField(max_length=64, verbose_name="申请id") | ||
9 | main_applicant = models.CharField(max_length=16, verbose_name="主申请人") | ||
10 | co_applicant = models.CharField(max_length=16, verbose_name="共同申请人") | ||
11 | guarantor_1 = models.CharField(max_length=16, verbose_name="担保人1") | ||
12 | guarantor_2 = models.CharField(max_length=16, verbose_name="担保人2") | ||
13 | document_name = models.CharField(max_length=255, verbose_name="文件名") | ||
14 | document_scheme = models.CharField(max_length=64, verbose_name="文件格式") # TODO 确认verbose_name | ||
15 | business_type = models.CharField(max_length=64, verbose_name="业务类型") | ||
16 | data_source = models.CharField(max_length=64, verbose_name="数据源") | ||
17 | metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id") | ||
18 | upload_finish_time = models.DateTimeField(verbose_name="上传完成时间") | ||
19 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') | ||
20 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
21 | |||
22 | class Meta: | ||
23 | managed = False | ||
24 | db_table = 'document' | ||
25 |
src/apps/doc/tests.py
0 → 100644
src/apps/doc/urls.py
0 → 100644
src/apps/doc/views.py
0 → 100644
1 | from django.shortcuts import render | ||
2 | from webargs import fields | ||
3 | from webargs.djangoparser import use_args, parser | ||
4 | from common.mixins import GenericView | ||
5 | from common import response | ||
6 | from .models import Document | ||
7 | |||
8 | # Create your views here. | ||
9 | |||
10 | |||
11 | # restframework将request.body封装至request.data, webargs从request.data中获取参数 | ||
12 | @parser.location_loader("data") | ||
13 | def load_data(request, schema): | ||
14 | return request.data | ||
15 | |||
16 | |||
17 | application_data = {'applicationId': fields.Str(required=True)} | ||
18 | |||
19 | applicant_data = { | ||
20 | 'mainApplicantName': fields.Str(required=True), | ||
21 | 'coApplicantName': fields.Str(required=True), | ||
22 | 'guarantor1Name': fields.Str(required=True), | ||
23 | 'guarantor2Name': fields.Str(required=True), | ||
24 | } | ||
25 | |||
26 | document = { | ||
27 | 'documentName': fields.Str(required=True), | ||
28 | 'documentScheme': fields.Str(required=True), | ||
29 | 'businessType': fields.Str(required=True), | ||
30 | 'uploadFinishTime': fields.DateTime(required=True), | ||
31 | 'dataSource': fields.Str(required=True), | ||
32 | 'metadataVersionId': fields.Str(required=True), | ||
33 | } | ||
34 | |||
35 | doc_upload = { | ||
36 | 'applicationData': fields.Nested(application_data, required=True), | ||
37 | 'applicantData': fields.Nested(applicant_data, required=True), | ||
38 | 'document': fields.Nested(document, required=True), | ||
39 | } | ||
40 | |||
41 | |||
42 | class DocView(GenericView): | ||
43 | permission_classes = [] | ||
44 | |||
45 | # 创建模型 | ||
46 | @use_args(doc_upload, location='data') | ||
47 | def post(self, request, args): | ||
48 | Document.objects.create( | ||
49 | application_id=args.get('applicationId'), | ||
50 | main_applicant=args.get('mainApplicantName'), | ||
51 | co_applicant=args.get('coApplicantName'), | ||
52 | guarantor_1=args.get('guarantor1Name'), | ||
53 | guarantor_2=args.get('guarantor2Name'), | ||
54 | document_name=args.get('documentName'), | ||
55 | document_scheme=args.get('documentScheme'), | ||
56 | business_type=args.get('businessType'), | ||
57 | data_source=args.get('dataSource'), | ||
58 | metadata_version_id=args.get('metadataVersionId'), | ||
59 | upload_finish_time=args.get('uploadFinishTime'), | ||
60 | ) | ||
61 | self.running_log.info('[doc upload success] [args={0}]'.format(args)) | ||
62 | return response.ok() |
... | @@ -19,4 +19,5 @@ from django.urls import path, include | ... | @@ -19,4 +19,5 @@ from django.urls import path, include |
19 | urlpatterns = [ | 19 | urlpatterns = [ |
20 | path('admin/', admin.site.urls), | 20 | path('admin/', admin.site.urls), |
21 | path(r'apis/v1/users/', include('apps.account.urls')), | 21 | path(r'apis/v1/users/', include('apps.account.urls')), |
22 | path(r'apis/v1/doc/', include('apps.doc.urls')), | ||
22 | ] | 23 | ] | ... | ... |
... | @@ -5,6 +5,7 @@ from django.utils.translation import ugettext_lazy as _ | ... | @@ -5,6 +5,7 @@ from django.utils.translation import ugettext_lazy as _ |
5 | from django.http import Http404 | 5 | from django.http import Http404 |
6 | from rest_framework import exceptions, status | 6 | from rest_framework import exceptions, status |
7 | from rest_framework.response import Response | 7 | from rest_framework.response import Response |
8 | from marshmallow.exceptions import ValidationError | ||
8 | 9 | ||
9 | from .response import MetaStatus, res_content, APIResponse | 10 | from .response import MetaStatus, res_content, APIResponse |
10 | 11 | ||
... | @@ -47,6 +48,11 @@ def exception_handler(exc, context): | ... | @@ -47,6 +48,11 @@ def exception_handler(exc, context): |
47 | 48 | ||
48 | return Response(data, status=status.HTTP_403_FORBIDDEN) | 49 | return Response(data, status=status.HTTP_403_FORBIDDEN) |
49 | 50 | ||
51 | elif isinstance(exc, ValidationError): | ||
52 | meta_status = MetaStatus.INVALID_PARAMS.value | ||
53 | # msg = MetaStatus.INVALID_PARAMS.verbose_name | ||
54 | return APIResponse(meta_status, msg=str(exc)) | ||
55 | |||
50 | elif isinstance(exc, Exception) and hasattr(exc, 'API_META_STATUS'): | 56 | elif isinstance(exc, Exception) and hasattr(exc, 'API_META_STATUS'): |
51 | msg = exc.API_META_STATUS.verbose_name | 57 | msg = exc.API_META_STATUS.verbose_name |
52 | return APIResponse(exc.API_META_STATUS.value, msg=msg) | 58 | return APIResponse(exc.API_META_STATUS.value, msg=msg) | ... | ... |
... | @@ -22,7 +22,7 @@ BASE_DIR = conf.BASE_DIR | ... | @@ -22,7 +22,7 @@ BASE_DIR = conf.BASE_DIR |
22 | # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ | 22 | # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ |
23 | 23 | ||
24 | # SECURITY WARNING: keep the secret key used in production secret! | 24 | # SECURITY WARNING: keep the secret key used in production secret! |
25 | SECRET_KEY = 'd!l6b6vz6s5dm9ysdfc-y1n*q3vukr-cix9rntx&5me$-)@wli' | 25 | SECRET_KEY = conf.SECRET_KEY |
26 | 26 | ||
27 | # SECURITY WARNING: don't run with debug turned on in production! | 27 | # SECURITY WARNING: don't run with debug turned on in production! |
28 | DEBUG = conf.DEBUG | 28 | DEBUG = conf.DEBUG |
... | @@ -41,6 +41,7 @@ INSTALLED_APPS = [ | ... | @@ -41,6 +41,7 @@ INSTALLED_APPS = [ |
41 | 'django.contrib.staticfiles', | 41 | 'django.contrib.staticfiles', |
42 | 'rest_framework', | 42 | 'rest_framework', |
43 | 'common', | 43 | 'common', |
44 | 'apps.account', | ||
44 | ] | 45 | ] |
45 | 46 | ||
46 | MIDDLEWARE = [ | 47 | MIDDLEWARE = [ |
... | @@ -139,3 +140,6 @@ REST_FRAMEWORK = { | ... | @@ -139,3 +140,6 @@ REST_FRAMEWORK = { |
139 | # 日志配置 | 140 | # 日志配置 |
140 | LOGGING_CONFIG = None | 141 | LOGGING_CONFIG = None |
141 | config.fileConfig(conf.LOGGING_CONFIG_FILE, disable_existing_loggers=False) | 142 | config.fileConfig(conf.LOGGING_CONFIG_FILE, disable_existing_loggers=False) |
143 | |||
144 | # url路径添加/ | ||
145 | APPEND_SLASH = False | ... | ... |
-
Please register or sign in to post a comment