调整UserSerializer

This commit is contained in:
zema1 2017-11-30 11:35:48 +08:00
parent 04eae5f4b4
commit 5429e99465
5 changed files with 20 additions and 10 deletions

View File

@ -44,7 +44,7 @@
![contest-list](https://user-images.githubusercontent.com/20637881/33372509-40d880dc-d539-11e7-9eba-1f08dcb6b9a0.png) ![contest-list](https://user-images.githubusercontent.com/20637881/33372509-40d880dc-d539-11e7-9eba-1f08dcb6b9a0.png)
Rankings 中可以控制图表和菜单的显隐 Rankings 中可以控制图表和菜单的显隐
![acm-rankings](https://user-images.githubusercontent.com/20637881/33372510-41117f68-d539-11e7-9947-70e60bad3cf2.png) ![acm-rankings](https://user-images.githubusercontent.com/20637881/33372510-41117f68-d539-11e7-9947-70e60bad3cf2.png)
![oi-rankings](https://user-images.githubusercontent.com/20637881/33372511-41d406fa-d539-11e7-9947-7a2a088785b0.png) ![oi-rankings](https://user-images.githubusercontent.com/20637881/33372511-41d406fa-d539-11e7-9947-7a2a088785b0.png)

View File

@ -44,7 +44,7 @@ Follow me: [https://github.com/QingdaoU/OnlineJudgeDeploy/tree/2.0](https://git
![contest-list](https://user-images.githubusercontent.com/20637881/33372509-40d880dc-d539-11e7-9eba-1f08dcb6b9a0.png) ![contest-list](https://user-images.githubusercontent.com/20637881/33372509-40d880dc-d539-11e7-9eba-1f08dcb6b9a0.png)
You can control the menu and chart status in rankings You can control the menu and chart status in rankings.
![acm-rankings](https://user-images.githubusercontent.com/20637881/33372510-41117f68-d539-11e7-9947-70e60bad3cf2.png) ![acm-rankings](https://user-images.githubusercontent.com/20637881/33372510-41117f68-d539-11e7-9947-70e60bad3cf2.png)
![oi-rankings](https://user-images.githubusercontent.com/20637881/33372511-41d406fa-d539-11e7-9947-7a2a088785b0.png) ![oi-rankings](https://user-images.githubusercontent.com/20637881/33372511-41d406fa-d539-11e7-9947-7a2a088785b0.png)

View File

@ -48,6 +48,20 @@ class ImportUserSeralizer(serializers.Serializer):
child=serializers.ListField(child=serializers.CharField(max_length=64))) child=serializers.ListField(child=serializers.CharField(max_length=64)))
class UserAdminSerializer(serializers.ModelSerializer):
real_name = serializers.SerializerMethodField()
create_time = DateTimeTZField()
last_login = DateTimeTZField()
class Meta:
model = User
fields = ["id", "username", "email", "admin_type", "problem_permission", "real_name",
"create_time", "last_login", "two_factor_auth", "open_api", "is_disabled"]
def get_real_name(self, obj):
return obj.userprofile.real_name
class UserSerializer(serializers.ModelSerializer): class UserSerializer(serializers.ModelSerializer):
create_time = DateTimeTZField() create_time = DateTimeTZField()
last_login = DateTimeTZField() last_login = DateTimeTZField()

View File

@ -13,7 +13,7 @@ from utils.shortcuts import rand_str
from ..decorators import super_admin_required from ..decorators import super_admin_required
from ..models import AdminType, ProblemPermission, User, UserProfile from ..models import AdminType, ProblemPermission, User, UserProfile
from ..serializers import EditUserSerializer, UserSerializer, GenerateUserSerializer from ..serializers import EditUserSerializer, UserAdminSerializer, GenerateUserSerializer
from ..serializers import ImportUserSeralizer from ..serializers import ImportUserSeralizer
@ -95,7 +95,7 @@ class UserAdminAPI(APIView):
user.save() user.save()
if pre_username != user.username: if pre_username != user.username:
Submission.objects.filter(username=pre_username).update(username=user.username) Submission.objects.filter(username=pre_username).update(username=user.username)
return self.success(UserSerializer(user).data) return self.success(UserAdminSerializer(user).data)
@super_admin_required @super_admin_required
def get(self, request): def get(self, request):
@ -108,7 +108,7 @@ class UserAdminAPI(APIView):
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
except User.DoesNotExist: except User.DoesNotExist:
return self.error("User does not exist") return self.error("User does not exist")
return self.success(UserSerializer(user).data) return self.success(UserAdminSerializer(user).data)
user = User.objects.all().order_by("-create_time") user = User.objects.all().order_by("-create_time")
@ -117,7 +117,7 @@ class UserAdminAPI(APIView):
user = user.filter(Q(username__icontains=keyword) | user = user.filter(Q(username__icontains=keyword) |
Q(userprofile__real_name__icontains=keyword) | Q(userprofile__real_name__icontains=keyword) |
Q(email__icontains=keyword)) Q(email__icontains=keyword))
return self.success(self.paginate_data(request, user, UserSerializer)) return self.success(self.paginate_data(request, user, UserAdminSerializer))
def delete_one(self, user_id): def delete_one(self, user_id):
try: try:

View File

@ -7,10 +7,6 @@ class DateTimeTZField(serializers.DateTimeField):
return super(DateTimeTZField, self).to_representation(value) return super(DateTimeTZField, self).to_representation(value)
class IDOnlySerializer(serializers.Serializer):
id = serializers.IntegerField()
class UsernameSerializer(serializers.Serializer): class UsernameSerializer(serializers.Serializer):
id = serializers.IntegerField() id = serializers.IntegerField()
username = serializers.CharField() username = serializers.CharField()