完善项目创建、修改接口

This commit is contained in:
chenzuoqing 2021-12-16 19:39:04 +08:00
parent d4ca0aa483
commit 7b26d9ddbd
2 changed files with 33 additions and 3 deletions

View File

@ -11,6 +11,24 @@ from models.project import models as projectModel
from common.utils import abort_response from common.utils import abort_response
class ProjectParse:
request_parse = None
def init_parse(self):
self.request_parse = reqparse.RequestParser()
self.request_parse.add_argument("domain", type=str, location='json')
self.request_parse.add_argument("www_ip", type=str, location='json')
self.request_parse.add_argument("ops_ip", type=str, location='json')
self.request_parse.add_argument("transfer_ip", type=str, location='json')
self.request_parse.add_argument("webhook", type=str, location='json')
self.request_parse.add_argument("kw", type=str, location='json')
self.request_parse.add_argument("desc", type=str, location='json')
self.request_parse.add_argument("repository", type=str, location='json')
self.request_parse.add_argument("data", type=dict, location='json')
self.request_parse.add_argument("tags", type=list, location='json')
self.request_parse.add_argument("labels", type=dict, location='json')
class ChannelParse: class ChannelParse:
request_parse = None request_parse = None

View File

@ -1,6 +1,6 @@
"""数据模型常规增删查改的接口""" """数据模型常规增删查改的接口"""
from flask import current_app as app from flask_restful import inputs
from models.project import fields from models.project import fields
from models.asset import models as assetModel from models.asset import models as assetModel
@ -10,19 +10,31 @@ from common.permission import session_or_token_required
from controller.project import parsers from controller.project import parsers
class ProjectViews(ListMixin, CreateMixin): class ProjectViews(parsers.ProjectParse, ListMixin, CreateMixin):
model = Project model = Project
paging = False paging = False
fields = fields.ProjectFields fields = fields.ProjectFields
uniq_fields = (("name", "fork"),)
method_decorators = [session_or_token_required] method_decorators = [session_or_token_required]
filter_fields = (("name", ""), ("fork", ""), ("ops_ip", ""), ("domain", "icontains"), ("tags", "")) filter_fields = (("name", ""), ("fork", ""), ("ops_ip", ""), ("domain", "icontains"), ("tags", ""))
def __init__(self):
self.init_parse()
self.request_parse.add_argument("name", type=inputs.regex(r'^\w{4}$'), location='json', required=True)
self.request_parse.add_argument("fork", type=inputs.regex(r'^\w{2}$'), location='json', required=True)
class ProjectDetailViews(DetailViewSet):
class ProjectDetailViews(parsers.ProjectParse, DetailViewSet):
model = Project model = Project
fields = fields.ProjectFields fields = fields.ProjectFields
uniq_fields = (("name", "fork"),)
method_decorators = [session_or_token_required] method_decorators = [session_or_token_required]
def __init__(self):
self.init_parse()
self.request_parse.add_argument("name", type=inputs.regex(r'^\w{4}$'), location='json', required=False)
self.request_parse.add_argument("fork", type=inputs.regex(r'^\w{2}$'), location='json', required=False)
class ChannelViews(parsers.ChannelParse, ListCreateViewSet): class ChannelViews(parsers.ChannelParse, ListCreateViewSet):
model = Channel model = Channel