def create(self, request): #for creating game user = request.user serializer = GameSerializer(data=request.data) if (serializer.is_valid()): serializer.save(instructor=user) return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_406_NOT_ACCEPTABLE)
def create_game(request): try: data = JSONParser().parse(request) except ParseError: return HttpResponse(status=400) serializer = GameSerializer(data=data, context={'request': request}) if serializer.is_valid(): serializer.save() return JsonResponse(serializer.data, status=status.HTTP_201_CREATED) else: return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): game = self.get_object(pk) serializer = GameSerializer(game, data=request.data) if serializer.is_valid(): serializer.save() newGame = self.get_object(pk) content = { 'mineFieldSetup': newGame.mineFieldSetup, 'turn': newGame.turn, 'player1score': newGame.player1score, 'player2score': newGame.player2score } pusher_client.trigger((str(pk) + '_game'), 'event', content) return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)