Beispiel #1
0
    def put(self, request):
        initial_user = User.objects.get(pk=request.user.id)
        updated_user = UserSerializer(initial_user, data=request.data)
        if (updated_user.is_valid()):
            initial_user = updated_user
            initial_user.save()
            new_user = User.objects.get(pk=request.user.id)
            user_data = PopulatedUserSerializer(new_user)
            
            badges = get_user_badges(user_data)
            score = get_user_score(user_data)
            
            test_user = User.objects.get(pk=request.user.id)
            test_user.score = score
            badge_user = UserSerializer(test_user)
            badge_user.data['badges'].clear()
            badge_user.data['badges'].extend(badges)

            updated_badge_user = UserSerializer(test_user, data=badge_user.data)
            if (updated_badge_user.is_valid()):
                test_user = updated_badge_user
                test_user.save()

                all_users = User.objects.all()
                serialized_userList = PopulatedUserSerializer(all_users, many=True)
                get_platform_badges(serialized_userList)

                return Response(test_user.data)
            return Response(updated_badge_user.errors, status=HTTP_422_UNPROCESSABLE_ENTITY)
        return Response(updated_user.errors, status=HTTP_422_UNPROCESSABLE_ENTITY)
Beispiel #2
0
 def put(self, request):
     initial_user = User.objects.get(pk=request.user.id)
     updated_user = UserSerializer(initial_user, data=request.data)
     if (updated_user.is_valid()):
         initial_user = updated_user
         initial_user.save()
         return Response(initial_user.data)
     return Response(updated_user.errors, status=HTTP_422_UNPROCESSABLE_ENTITY)
Beispiel #3
0
    def post(self, request):
        # deserialiser the data
        serializer = UserSerializer(data=request.data)
        if serializer.is_valid():
            # auto sets user to be logged in user
            serializer = PopulatedUserSerializer()
            serializer.save()
            return Response(serializer.data, status=201)

        return Response(serializer.errors, status=422)