update
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
CODE_SUCCESS = 0
|
||||
CODE_FAILED = -1
|
||||
@@ -1,5 +1,6 @@
|
||||
from rest_framework.response import Response
|
||||
from server.util.constant_util import *
|
||||
|
||||
|
||||
def build_response(code=0, msg='', data=''):
|
||||
def build_response(code=CODE_SUCCESS, msg='', data=''):
|
||||
return Response({'code': code, 'msg': msg, 'data': data})
|
||||
|
||||
@@ -9,9 +9,10 @@ from server.filters import CooperationMindFilter
|
||||
from server.serializers import *
|
||||
from server.util.mix_util import build_response
|
||||
from server.util.pagination import NewPagination
|
||||
from server_auth.lib.auth import LoginRequiredJSONMixin
|
||||
|
||||
|
||||
class JsMindView(ListAPIView):
|
||||
class JsMindView(LoginRequiredJSONMixin, ListAPIView):
|
||||
"""
|
||||
思维导图view
|
||||
"""
|
||||
@@ -21,7 +22,6 @@ class JsMindView(ListAPIView):
|
||||
filter_class = CooperationMindFilter
|
||||
pagination_class = NewPagination
|
||||
|
||||
@login_required(login_url="dashboard")
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""
|
||||
查询思维导图
|
||||
@@ -34,7 +34,6 @@ class JsMindView(ListAPIView):
|
||||
return build_response(data=serializer.data)
|
||||
return self.list(request, *args, **kwargs)
|
||||
|
||||
@login_required(login_url="dashboard")
|
||||
def post(self, request):
|
||||
"""
|
||||
创建思维导图
|
||||
|
||||
+19
-5
@@ -1,8 +1,12 @@
|
||||
from django import http
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.backends import ModelBackend # 验证基类
|
||||
from server_auth.models import MindUser
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from rest_framework.views import APIView
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
|
||||
from server.util.constant_util import *
|
||||
from server.util.mix_util import build_response
|
||||
from server_auth.models import MindUser
|
||||
|
||||
|
||||
class AuthBackend(ModelBackend):
|
||||
@@ -43,8 +47,18 @@ class LoginView(APIView):
|
||||
if user.is_active:
|
||||
# 记住登录状态
|
||||
login(request, user)
|
||||
return build_response(code=0, msg='登录成功')
|
||||
return build_response(msg='登录成功')
|
||||
else:
|
||||
return build_response(code=-1, msg='登录失败')
|
||||
return build_response(code=CODE_FAILED, msg='登录失败')
|
||||
else:
|
||||
return build_response(code=-1, msg='登录失败')
|
||||
return build_response(code=CODE_FAILED, msg='登录失败')
|
||||
|
||||
|
||||
class LoginRequiredJSONMixin(LoginRequiredMixin):
|
||||
"""自定义LoginRequiredMixin
|
||||
如果用户未登录,响应JSON,且状态码为400
|
||||
"""
|
||||
|
||||
def handle_no_permission(self):
|
||||
# return build_response(code=CODE_FAILED, msg='用户未登录!')
|
||||
return http.JsonResponse({'code': CODE_FAILED, 'msg': '用户未登录'})
|
||||
|
||||
@@ -58,6 +58,10 @@
|
||||
get_param.coop_mind_name = this.get_search_coop_mind_name()
|
||||
}
|
||||
$.get('list', get_param, function (resp) {
|
||||
if (resp.code !== 0) {
|
||||
layer.msg(resp.msg)
|
||||
return
|
||||
}
|
||||
// 清空数据
|
||||
$('#layui-table tbody').empty()
|
||||
$('#' + me.opts.page_bar_elem).empty()
|
||||
|
||||
Reference in New Issue
Block a user