93fa8104 by Gruel

upload doc interface

1 parent 23b64aee
File mode changed
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class DocConfig(AppConfig):
name = 'doc'
from django.db import models
# Create your models here.
class Document(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id")
application_id = models.CharField(max_length=64, verbose_name="申请id")
main_applicant = models.CharField(max_length=16, verbose_name="主申请人")
co_applicant = models.CharField(max_length=16, verbose_name="共同申请人")
guarantor_1 = models.CharField(max_length=16, verbose_name="担保人1")
guarantor_2 = models.CharField(max_length=16, verbose_name="担保人2")
document_name = models.CharField(max_length=255, verbose_name="文件名")
document_scheme = models.CharField(max_length=64, verbose_name="文件格式") # TODO 确认verbose_name
business_type = models.CharField(max_length=64, verbose_name="业务类型")
data_source = models.CharField(max_length=64, verbose_name="数据源")
metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id")
upload_finish_time = models.DateTimeField(verbose_name="上传完成时间")
update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'document'
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path(r'', views.DocView.as_view()),
]
from django.shortcuts import render
from webargs import fields
from webargs.djangoparser import use_args, parser
from common.mixins import GenericView
from common import response
from .models import Document
# Create your views here.
# restframework将request.body封装至request.data, webargs从request.data中获取参数
@parser.location_loader("data")
def load_data(request, schema):
return request.data
application_data = {'applicationId': fields.Str(required=True)}
applicant_data = {
'mainApplicantName': fields.Str(required=True),
'coApplicantName': fields.Str(required=True),
'guarantor1Name': fields.Str(required=True),
'guarantor2Name': fields.Str(required=True),
}
document = {
'documentName': fields.Str(required=True),
'documentScheme': fields.Str(required=True),
'businessType': fields.Str(required=True),
'uploadFinishTime': fields.DateTime(required=True),
'dataSource': fields.Str(required=True),
'metadataVersionId': fields.Str(required=True),
}
doc_upload = {
'applicationData': fields.Nested(application_data, required=True),
'applicantData': fields.Nested(applicant_data, required=True),
'document': fields.Nested(document, required=True),
}
class DocView(GenericView):
permission_classes = []
# 创建模型
@use_args(doc_upload, location='data')
def post(self, request, args):
Document.objects.create(
application_id=args.get('applicationId'),
main_applicant=args.get('mainApplicantName'),
co_applicant=args.get('coApplicantName'),
guarantor_1=args.get('guarantor1Name'),
guarantor_2=args.get('guarantor2Name'),
document_name=args.get('documentName'),
document_scheme=args.get('documentScheme'),
business_type=args.get('businessType'),
data_source=args.get('dataSource'),
metadata_version_id=args.get('metadataVersionId'),
upload_finish_time=args.get('uploadFinishTime'),
)
self.running_log.info('[doc upload success] [args={0}]'.format(args))
return response.ok()
......@@ -19,4 +19,5 @@ from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path(r'apis/v1/users/', include('apps.account.urls')),
path(r'apis/v1/doc/', include('apps.doc.urls')),
]
......
......@@ -5,6 +5,7 @@ from django.utils.translation import ugettext_lazy as _
from django.http import Http404
from rest_framework import exceptions, status
from rest_framework.response import Response
from marshmallow.exceptions import ValidationError
from .response import MetaStatus, res_content, APIResponse
......@@ -47,6 +48,11 @@ def exception_handler(exc, context):
return Response(data, status=status.HTTP_403_FORBIDDEN)
elif isinstance(exc, ValidationError):
meta_status = MetaStatus.INVALID_PARAMS.value
# msg = MetaStatus.INVALID_PARAMS.verbose_name
return APIResponse(meta_status, msg=str(exc))
elif isinstance(exc, Exception) and hasattr(exc, 'API_META_STATUS'):
msg = exc.API_META_STATUS.verbose_name
return APIResponse(exc.API_META_STATUS.value, msg=msg)
......
......@@ -22,7 +22,7 @@ BASE_DIR = conf.BASE_DIR
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'd!l6b6vz6s5dm9ysdfc-y1n*q3vukr-cix9rntx&5me$-)@wli'
SECRET_KEY = conf.SECRET_KEY
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = conf.DEBUG
......@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'rest_framework',
'common',
'apps.account',
]
MIDDLEWARE = [
......@@ -139,3 +140,6 @@ REST_FRAMEWORK = {
# 日志配置
LOGGING_CONFIG = None
config.fileConfig(conf.LOGGING_CONFIG_FILE, disable_existing_loggers=False)
# url路径添加/
APPEND_SLASH = False
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!