Esempio n. 1
0
    def get(self, request):
        # if user isn't logged in, 404
        if not request.user.is_authenticated:
            raise Http404

        # user might still not have osu_user if not they are a non-linked account (ie. admin)
        user = request.user
        if user.osu_user is not None:
            fetch_user(user_id=user.osu_user_id
                       )  # TODO: specify gamemode based on user preferences

        serialiser = UserSerialiser(user)
        return Response(serialiser.data)
Esempio n. 2
0
def me(request):
    """
    API Endpoint for checking the currently logged in user
    """

    # if user isn't logged in, 404
    if not request.user.is_authenticated:
        raise Http404

    # user might still not have osu_user if not they are a non-linked account (ie. admin)
    osu_user = request.user.osu_user
    if osu_user is not None:
        fetch_user(user_id=osu_user.id
                   )  # TODO: specify gamemode based on user preferences

    serialiser = OsuUserSerialiser(osu_user)
    return Response(serialiser.data)
Esempio n. 3
0
    def get(self, request, user_string, gamemode):
        """
        Return UserStats based on a user_string and gamemode
        """
        user_id_type = request.query_params.get("user_id_type") or "id"

        try:
            if user_id_type == "id":
                user_stats = fetch_user(user_id=user_string, gamemode=gamemode)
            elif user_id_type == "username":
                user_stats = fetch_user(username=user_string,
                                        gamemode=gamemode)
            else:
                raise NotFound("User not found.")
        except UserStats.DoesNotExist:
            raise NotFound("User not found.")

        serialiser = UserStatsSerialiser(user_stats)
        return Response(serialiser.data)
    def handle(self, *args, **options):
        gamemode = options["gamemode"][0]

        user_ids = options["user_ids"]

        if options["file"]:
            file_path = os.path.join(settings.BASE_DIR, options["file"])
            with open(file_path, "r") as fp:
                user_ids += fp.readlines()

        for user_id in user_ids:
            user_stats = fetch_user(user_id=user_id, gamemode=gamemode)

            self.stdout.write(
                self.style.SUCCESS(
                    f"Successfully updated user {user_stats.user.username} ({user_stats.user_id})"
                ))