From 41eec53430d5bb85f3f1a40ef949534c04aca329 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Wed, 12 Aug 2015 22:59:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/views.py | 59 ++++++++++++++--------- static/src/js/app/admin/user/user_list.js | 2 +- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/account/views.py b/account/views.py index fe144644..f0539039 100644 --- a/account/views.py +++ b/account/views.py @@ -7,9 +7,11 @@ from rest_framework.views import APIView from utils.shortcuts import serializer_invalid_response, error_response, success_response, paginate +from .decorators import login_required from .models import User -from .serializers import UserLoginSerializer, UsernameCheckSerializer, UserRegisterSerializer, \ - UserChangePasswordSerializer, EmailCheckSerializer, UserSerializer, EditUserSerializer +from .serializers import (UserLoginSerializer, UsernameCheckSerializer, + UserRegisterSerializer, UserChangePasswordSerializer, + EmailCheckSerializer, UserSerializer, EditUserSerializer) class UserLoginAPIView(APIView): @@ -118,28 +120,6 @@ class EmailCheckAPIView(APIView): 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): def put(self, request): """ @@ -165,3 +145,34 @@ class UserAdminAPIView(APIView): return success_response(UserSerializer(user).data) else: 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) diff --git a/static/src/js/app/admin/user/user_list.js b/static/src/js/app/admin/user/user_list.js index 910c24a6..1e5f254a 100644 --- a/static/src/js/app/admin/user/user_list.js +++ b/static/src/js/app/admin/user/user_list.js @@ -63,7 +63,7 @@ require(["jquery", "avalon", "csrf", "bs_alert", "validation"], function ($, ava getPageData(1); //用户列表初始化 //Ajax get数据 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) url += "&admin_type=1"; if (vm.key_word != "")