mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
合并用户管理的代码
This commit is contained in:
parent
f6c3ceee40
commit
41eec53430
@ -7,9 +7,11 @@ from rest_framework.views import APIView
|
|||||||
|
|
||||||
from utils.shortcuts import serializer_invalid_response, error_response, success_response, paginate
|
from utils.shortcuts import serializer_invalid_response, error_response, success_response, paginate
|
||||||
|
|
||||||
|
from .decorators import login_required
|
||||||
from .models import User
|
from .models import User
|
||||||
from .serializers import UserLoginSerializer, UsernameCheckSerializer, UserRegisterSerializer, \
|
from .serializers import (UserLoginSerializer, UsernameCheckSerializer,
|
||||||
UserChangePasswordSerializer, EmailCheckSerializer, UserSerializer, EditUserSerializer
|
UserRegisterSerializer, UserChangePasswordSerializer,
|
||||||
|
EmailCheckSerializer, UserSerializer, EditUserSerializer)
|
||||||
|
|
||||||
|
|
||||||
class UserLoginAPIView(APIView):
|
class UserLoginAPIView(APIView):
|
||||||
@ -118,28 +120,6 @@ class EmailCheckAPIView(APIView):
|
|||||||
return serializer_invalid_response(serializer)
|
return serializer_invalid_response(serializer)
|
||||||
|
|
||||||
|
|
||||||
class UserAPIView(APIView):
|
|
||||||
def get(self, request):
|
|
||||||
"""
|
|
||||||
用户分页json api接口
|
|
||||||
---
|
|
||||||
response_serializer: UserSerializer
|
|
||||||
"""
|
|
||||||
user = User.objects.all().order_by("-create_time")
|
|
||||||
admin_type = request.GET.get("admin_type", None)
|
|
||||||
if admin_type:
|
|
||||||
try:
|
|
||||||
user = user.filter(admin_type__gte=int(admin_type))
|
|
||||||
except ValueError:
|
|
||||||
return error_response(u"参数错误")
|
|
||||||
keyword = request.GET.get("keyword", None)
|
|
||||||
if keyword:
|
|
||||||
user = user.filter(Q(username__contains=keyword) |
|
|
||||||
Q(real_name__contains=keyword) |
|
|
||||||
Q(email__contains=keyword))
|
|
||||||
return paginate(request, user, UserSerializer)
|
|
||||||
|
|
||||||
|
|
||||||
class UserAdminAPIView(APIView):
|
class UserAdminAPIView(APIView):
|
||||||
def put(self, request):
|
def put(self, request):
|
||||||
"""
|
"""
|
||||||
@ -165,3 +145,34 @@ class UserAdminAPIView(APIView):
|
|||||||
return success_response(UserSerializer(user).data)
|
return success_response(UserSerializer(user).data)
|
||||||
else:
|
else:
|
||||||
return serializer_invalid_response(serializer)
|
return serializer_invalid_response(serializer)
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""
|
||||||
|
用户分页json api接口
|
||||||
|
---
|
||||||
|
response_serializer: UserSerializer
|
||||||
|
"""
|
||||||
|
user = User.objects.all().order_by("-create_time")
|
||||||
|
admin_type = request.GET.get("admin_type", None)
|
||||||
|
if admin_type:
|
||||||
|
try:
|
||||||
|
user = user.filter(admin_type__gte=int(admin_type))
|
||||||
|
except ValueError:
|
||||||
|
return error_response(u"参数错误")
|
||||||
|
keyword = request.GET.get("keyword", None)
|
||||||
|
if keyword:
|
||||||
|
user = user.filter(Q(username__contains=keyword) |
|
||||||
|
Q(real_name__contains=keyword) |
|
||||||
|
Q(email__contains=keyword))
|
||||||
|
return paginate(request, user, UserSerializer)
|
||||||
|
|
||||||
|
|
||||||
|
class UserInfoAPIView(APIView):
|
||||||
|
@login_required
|
||||||
|
def get(self, request):
|
||||||
|
"""
|
||||||
|
返回这个用户的个人信息
|
||||||
|
---
|
||||||
|
response_serializer: UserSerializer
|
||||||
|
"""
|
||||||
|
return success_response(UserSerializer(request.user).data)
|
||||||
|
|||||||
@ -63,7 +63,7 @@ require(["jquery", "avalon", "csrf", "bs_alert", "validation"], function ($, ava
|
|||||||
getPageData(1); //用户列表初始化
|
getPageData(1); //用户列表初始化
|
||||||
//Ajax get数据
|
//Ajax get数据
|
||||||
function getPageData(page) {
|
function getPageData(page) {
|
||||||
var url = "/api/admin/users/?paging=true&page=" + page + "&page_size=10";
|
var url = "/api/admin/user/?paging=true&page=" + page + "&page_size=10";
|
||||||
if (vm.showAdminOnly == true)
|
if (vm.showAdminOnly == true)
|
||||||
url += "&admin_type=1";
|
url += "&admin_type=1";
|
||||||
if (vm.key_word != "")
|
if (vm.key_word != "")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user