Example #1
0
    def post(self, request, image_id, format=None):

        cur_user = request.user

        try:
            found_image = models.Image.objects.get(id=image_id)
        except models.Image.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        try:
            pre_existing_like = models.Like.objects.get(creator=cur_user,
                                                        image=found_image)

            pre_existing_like.delete()

            return Response(status=status.HTTP_204_NO_CONTENT)

        except models.Like.DoesNotExist:

            models.Like.objects.create(creator=cur_user, image=found_image)

            notification_views.create_notification(cur_user,
                                                   found_image.creator, 'like',
                                                   found_image)

        return Response(status=status.HTTP_201_CREATED)
Example #2
0
    def post(self, request, image_id, format=None):

        user = request.user

        try:
            found_image = models.Image.objects.get(id=image_id)
        except models.Image.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = serializers.CommentSerializer(data=request.data)

        if serializer.is_valid():

            serializer.save(creator=user, image=found_image)

            notification_views.create_notification(user, found_image.creator,
                                                   'comment', found_image,
                                                   serializer.data['message'])

            return Response(data=serializer.data,
                            status=status.HTTP_201_CREATED)

        else:

            return Response(data=serializer.data,
                            status=status.HTTP_400_BAD_REQUEST)
Example #3
0
    def post(self, request, image_id, format=None):

        user = request.user

        try:
            found_image = models.Image.objects.get(id=image_id)
        except models.Image.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        try:
            preexisting_like = models.Like.objects.get(creator=user,
                                                       image=found_image)

            return Response(status=status.HTTP_304_NOT_MODIFIED)

        except models.Like.DoesNotExist:
            new_like = models.Like.objects.create(creator=user,
                                                  image=found_image)

            new_like.save()

            notification_views.create_notification(user, found_image.creator,
                                                   'like', found_image)

            return Response(status=status.HTTP_201_CREATED)
Example #4
0
    def post(self, request, user_id, format=None):

        user = request.user

        try:
            user_to_follow = models.User.objects.get(id=user_id)
        except models.User.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        user.following.add(user_to_follow)
        user.save()

        notification_views.create_notification(user, user_to_follow, 'follow')

        return Response(status=status.HTTP_200_OK)