渠道、区服的版本编辑调整
This commit is contained in:
parent
94aaa33611
commit
cdcea7f9d6
|
@ -35,29 +35,23 @@ class ChannelParse:
|
||||||
def init_parse(self):
|
def init_parse(self):
|
||||||
self.request_parse = reqparse.RequestParser()
|
self.request_parse = reqparse.RequestParser()
|
||||||
|
|
||||||
self.request_parse.add_argument("name", type=str, location='json', default="")
|
self.request_parse.add_argument("name", type=str, location='json')
|
||||||
self.request_parse.add_argument("version", type=dict, location='json')
|
self.request_parse.add_argument("version", type=dict, location='json')
|
||||||
self.request_parse.add_argument("repository", type=str, location='json', default="")
|
self.request_parse.add_argument("repository", type=str, location='json')
|
||||||
self.request_parse.add_argument("branch", type=dict, location='json', default="")
|
self.request_parse.add_argument("branch", type=str, location='json')
|
||||||
|
|
||||||
self.request_parse.add_argument("data", type=dict, 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("tags", type=list, location='json')
|
||||||
self.request_parse.add_argument("labels", type=dict, location='json')
|
self.request_parse.add_argument("labels", type=dict, location='json')
|
||||||
|
|
||||||
def validate_fields(self, args: dict, create=True) -> dict:
|
def validate_fields(self, args: dict, **kwargs) -> dict:
|
||||||
if create:
|
"""处理内嵌的version字段"""
|
||||||
self.validate_relation_pk(args, projectModel.Project, key="project_id")
|
version = args.get("version", {})
|
||||||
spid = str(args.get("spid"))
|
if version and isinstance(version, dict):
|
||||||
if not spid.isalnum() or len(spid) != 3:
|
defaults = {}
|
||||||
abort_response(400, 1001, msg="spid 不合法")
|
for field in projectModel.Version._fields:
|
||||||
else:
|
defaults[field] = version.get(field, "")
|
||||||
if "project_id" in args:
|
args["version"] = projectModel.Version(**defaults)
|
||||||
self.validate_relation_pk(args, projectModel.Project, key="project_id")
|
|
||||||
if "spid" in args:
|
|
||||||
spid = str(args.get("spid"))
|
|
||||||
if not spid.isalnum() or len(spid) != 3:
|
|
||||||
abort_response(400, 1001, msg="spid 不合法")
|
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,17 +77,14 @@ class ServerParse:
|
||||||
self.request_parse.add_argument("weight", type=int, location='json')
|
self.request_parse.add_argument("weight", type=int, location='json')
|
||||||
self.request_parse.add_argument("slot", type=int, location='json')
|
self.request_parse.add_argument("slot", type=int, location='json')
|
||||||
|
|
||||||
def validate_fields(self, args: dict, create=True) -> dict:
|
def validate_fields(self, args: dict, **kwargs) -> dict:
|
||||||
# if not create:
|
version = args.get("version", {})
|
||||||
# if "channel_id" in args:
|
if version and isinstance(version, dict):
|
||||||
# self.validate_relation_pk(args, projectModel.Channel, key="channel_id")
|
defaults = {}
|
||||||
# if "host_id" in args:
|
# 以模型的字段为基准,从version参数中填充相同key的值
|
||||||
# self.validate_relation_pk(args, assetModel.Host, key="channel_id")
|
for field in projectModel.Version._fields:
|
||||||
# else:
|
defaults[field] = version.get(field, "")
|
||||||
# self.validate_relation_pk(args, projectModel.Channel, key="channel_id")
|
args["version"] = projectModel.Version(**defaults)
|
||||||
version = args.get("version")
|
|
||||||
if version:
|
|
||||||
args["version"] = projectModel.Version(**version)
|
|
||||||
game_db_id = args.get("game_db_id")
|
game_db_id = args.get("game_db_id")
|
||||||
if game_db_id:
|
if game_db_id:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -41,6 +41,7 @@ class ChannelViews(parsers.ChannelParse, ListCreateViewSet):
|
||||||
model = Channel
|
model = Channel
|
||||||
fields = fields.ChannelFields
|
fields = fields.ChannelFields
|
||||||
uniq_fields = (("spid", "project_id"),)
|
uniq_fields = (("spid", "project_id"),)
|
||||||
|
relation_fields = (("project_id", Project, True),)
|
||||||
method_decorators = [session_or_token_required]
|
method_decorators = [session_or_token_required]
|
||||||
filter_fields = (("name", ""), ("spid", ""), ("tags", ""))
|
filter_fields = (("name", ""), ("spid", ""), ("tags", ""))
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ class ChannelDetailViews(parsers.ChannelParse, DetailViewSet):
|
||||||
model = Channel
|
model = Channel
|
||||||
fields = fields.ChannelFields
|
fields = fields.ChannelFields
|
||||||
uniq_fields = (("spid", "project_id"),)
|
uniq_fields = (("spid", "project_id"),)
|
||||||
|
relation_fields = (("project_id", Project, True),)
|
||||||
method_decorators = [session_or_token_required]
|
method_decorators = [session_or_token_required]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Reference in New Issue