diff --git a/src/controller/project/parsers.py b/src/controller/project/parsers.py index 2091ad4..a18d4c0 100644 --- a/src/controller/project/parsers.py +++ b/src/controller/project/parsers.py @@ -11,6 +11,24 @@ from models.project import models as projectModel 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: request_parse = None diff --git a/src/controller/project/views.py b/src/controller/project/views.py index 9d2f03c..0ddb372 100644 --- a/src/controller/project/views.py +++ b/src/controller/project/views.py @@ -1,6 +1,6 @@ """数据模型常规增删查改的接口""" -from flask import current_app as app +from flask_restful import inputs from models.project import fields from models.asset import models as assetModel @@ -10,19 +10,31 @@ from common.permission import session_or_token_required from controller.project import parsers -class ProjectViews(ListMixin, CreateMixin): +class ProjectViews(parsers.ProjectParse, ListMixin, CreateMixin): model = Project paging = False fields = fields.ProjectFields + uniq_fields = (("name", "fork"),) method_decorators = [session_or_token_required] 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 fields = fields.ProjectFields + uniq_fields = (("name", "fork"),) 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): model = Channel