mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-28 16:12:13 +00:00
update
This commit is contained in:
parent
796f748d10
commit
5447dd90ac
@ -33,15 +33,21 @@ class SimpleGroupSerializer(serializers.ModelSerializer):
|
||||
created_by = UsernameSerializer()
|
||||
password = serializers.SerializerMethodField()
|
||||
me = serializers.BooleanField()
|
||||
members = UsernameSerializer(many=True)
|
||||
|
||||
def get_password(self, obj):
|
||||
return obj.password != ""
|
||||
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = ["id", "created_by", "name", "password", "me"]
|
||||
fields = ["id", "created_by", "name", "password", "me", "members"]
|
||||
|
||||
|
||||
class JoinGroupSerializer(serializers.Serializer):
|
||||
group_name = serializers.CharField()
|
||||
password = serializers.CharField(allow_blank=True)
|
||||
password = serializers.CharField(allow_blank=True)
|
||||
|
||||
|
||||
class AddUserToGroupSerializer(serializers.Serializer):
|
||||
group_id = serializers.IntegerField()
|
||||
username = serializers.CharField()
|
||||
|
@ -1,7 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from ..views.admin import GroupAPI
|
||||
from ..views.admin import GroupAPI, AddUserToGroupAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^group/?$", GroupAPI.as_view(), name="group_api"),
|
||||
url(r"^group/add_user?$", AddUserToGroupAPI.as_view(), name="add_user_to_group_api"),
|
||||
]
|
||||
|
@ -5,7 +5,7 @@ from account.models import User
|
||||
from utils.api import APIView, validate_serializer
|
||||
|
||||
from ..models import Group
|
||||
from ..serializers import GroupSerializer, CreateGroupSerializer, EditGroupSerializer, DeleteGroupSerializer
|
||||
from ..serializers import GroupSerializer, CreateGroupSerializer, EditGroupSerializer, DeleteGroupSerializer, AddUserToGroupSerializer
|
||||
|
||||
|
||||
class GroupAPI(APIView):
|
||||
@ -68,3 +68,15 @@ class GroupAPI(APIView):
|
||||
else:
|
||||
group.members.remove(User.objects.get(id=data["user_id"]))
|
||||
return self.success(GroupSerializer(group).data)
|
||||
|
||||
|
||||
class AddUserToGroupAPI(APIView):
|
||||
@validate_serializer(AddUserToGroupSerializer)
|
||||
def post(self, request):
|
||||
try:
|
||||
user = User.objects.get(username=request.data["username"])
|
||||
group = Group.objects.get(id=request.data["group_id"])
|
||||
except Exception:
|
||||
return self.error("用户不存在")
|
||||
group.members.add(user)
|
||||
return self.success(GroupSerializer(group).data)
|
||||
|
Loading…
Reference in New Issue
Block a user