コード例 #1
0
ファイル: views.py プロジェクト: rakeshyadavitan/Chatroom
def join_room(request, room_timestamp
              ):  # Join room based on the timestamp of the created room
    if request.method == 'PUT':
        data = JSONParser().parse(request)
        room = Room.objects.filter(timestamp=room_timestamp)
        serializer = RoomSerializer(room, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)
コード例 #2
0
ファイル: views.py プロジェクト: rakeshyadavitan/Chatroom
def room_list(request, owner=None, member=None):
    # List all required room, or create a new room.
    if request.method == 'GET':
        # rooms = Room.objects.filter(owner_id=owner, member_id=member)
        rooms = Room.objects.all()  #get all rooms lists
        serializer = RoomSerializer(rooms,
                                    many=True,
                                    context={'request': request})
        print('----------------')
        print(serializer.data)
        return JsonResponse(serializer.data, safe=False)
    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = RoomSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)
コード例 #3
0
 def get(self, request):
     rooms = Room.objects.all()
     serializer = RoomSerializer(rooms, many=True)
     return Response({'data': serializer.data})
コード例 #4
0
 def get(self, request):
     rooms = Room.objects.filter(
         Q(creator=request.user) | Q(invited=request.user)).distinct()
     serializer = RoomSerializer(rooms, many=True)
     return Response({'data': serializer.data})