fix admin update user real_name problem

This commit is contained in:
zema1
2017-12-10 09:58:08 +08:00
parent 092bf9a73f
commit 10ecb79152
3 changed files with 16 additions and 2 deletions

View File

@@ -37,15 +37,18 @@ class UserProfileAPI(APIView):
user = request.user
if not user.is_authenticated():
return self.success()
show_real_name = False
username = request.GET.get("username")
try:
if username:
user = User.objects.get(username=username, is_disabled=False)
else:
user = request.user
# api返回的是自己的信息可以返real_name
show_real_name = True
except User.DoesNotExist:
return self.error("User does not exist")
return self.success(UserProfileSerializer(user.userprofile).data)
return self.success(UserProfileSerializer(user.userprofile, show_real_name=show_real_name).data)
@validate_serializer(EditUserProfileSerializer)
@login_required
@@ -55,7 +58,7 @@ class UserProfileAPI(APIView):
for k, v in data.items():
setattr(user_profile, k, v)
user_profile.save()
return self.success(UserProfileSerializer(user_profile).data)
return self.success(UserProfileSerializer(user_profile, show_real_name=True).data)
class AvatarUploadAPI(APIView):