调整项目app的视图目录结构,模型增删查改分开

This commit is contained in:
chenzuoqing 2021-12-01 14:58:37 +08:00
parent 9f50ff389c
commit a2fd364343
4 changed files with 40 additions and 34 deletions

View File

@ -1,7 +1,7 @@
from flask import Blueprint
from flask_restful import Api
from project import views
from project.views import views, operation
# 当前app的蓝图以app名为前缀
@ -21,4 +21,4 @@ api.add_resource(views.ChannelDetailViews, '/channel/<string:pk>/', endpoint="ch
api.add_resource(views.ServerViews, '/server/', endpoint="server")
api.add_resource(views.ServerDetailView, '/server/<string:pk>/', endpoint="server-detail")
# 区服信息同步接口,更新区服信息
api.add_resource(views.ServerSyncView, '/server/sync/', endpoint="server-sync")
api.add_resource(operation.ServerSyncView, '/server/sync/', endpoint="server-sync")

View File

View File

@ -6,42 +6,11 @@ from flask_restful import reqparse
from asset.models import Host
from project import fields
from project.models import Project, Channel, Server, Version
from common.views import ListMixin, CreateMixin, ListCreateViewSet, DetailViewSet
from common.views import CreateMixin
from common.permission import token_header_required
from common.utils import make_response
class ProjectViews(ListMixin, CreateMixin):
model = Project
paging = False
fields = fields.ProjectFields
class ProjectDetailViews(DetailViewSet):
model = Project
fields = fields.ProjectFields
class ChannelViews(ListCreateViewSet):
model = Channel
fields = fields.ChannelFields
class ChannelDetailViews(DetailViewSet):
model = Channel
fields = fields.ChannelFields
class ServerViews(ListCreateViewSet):
model = Server
fields = fields.ServerFields
class ServerDetailView(DetailViewSet):
model = Server
fields = fields.ServerFields
class ServerSyncView(CreateMixin):
"""同步区服信息,由 `batchQuery` 程序发送采集内容,此视图更新保存"""
model = Server
@ -144,3 +113,4 @@ class ServerSyncView(CreateMixin):
return make_response(200, 1020, "有区服同步出错", errors=errors)
return make_response(200, 1000, "success")

View File

@ -0,0 +1,36 @@
"""数据模型常规增删查改的接口"""
from project import fields
from project.models import Project, Channel, Server
from common.views import ListMixin, CreateMixin, ListCreateViewSet, DetailViewSet
class ProjectViews(ListMixin, CreateMixin):
model = Project
paging = False
fields = fields.ProjectFields
class ProjectDetailViews(DetailViewSet):
model = Project
fields = fields.ProjectFields
class ChannelViews(ListCreateViewSet):
model = Channel
fields = fields.ChannelFields
class ChannelDetailViews(DetailViewSet):
model = Channel
fields = fields.ChannelFields
class ServerViews(ListCreateViewSet):
model = Server
fields = fields.ServerFields
class ServerDetailView(DetailViewSet):
model = Server
fields = fields.ServerFields