GET request

def GET_AUTH(self, courseid, scoreboardid):  # pylint: disable=arguments-differ
        """ GET request """
        course = self.course_factory.get_course(courseid)
        scoreboards = course.get_descriptor().get('scoreboard', [])

        try:
            scoreboardid = int(scoreboardid)
            scoreboard_name = scoreboards[scoreboardid]["name"]
            scoreboard_content = scoreboards[scoreboardid]["content"]
            scoreboard_reverse = bool(scoreboards[scoreboardid].get('reverse', False))
        except:
            raise web.notfound()

        # Convert scoreboard_content
        if isinstance(scoreboard_content, str):
            scoreboard_content = OrderedDict([(scoreboard_content, 1)])
        if isinstance(scoreboard_content, list):
            scoreboard_content = OrderedDict([(entry, 1) for entry in scoreboard_content])
        if not isinstance(scoreboard_content, OrderedDict):
            scoreboard_content = OrderedDict(iter(scoreboard_content.items()))

        # Get task names
        task_names = {}
        for taskid in scoreboard_content:
            try:
                task_names[taskid] = course.get_task(taskid).get_name(self.user_manager.session_language())
            except:
                raise web.notfound("Unknown task id "+taskid)

        # Get all submissions
        results = self.database.submissions.find({
            "courseid": courseid,
            "taskid": {"$in": list(scoreboard_content.keys())},
            "custom.score": {"$exists": True},
            "result": "success"
        }, ["taskid", "username", "custom.score"])

        # Get best results per users(/group)
        result_per_user = {}
        users = set()
        for submission in results:
            # Be sure we have a list
            if not isinstance(submission["username"], list):
                submission["username"] = [submission["username"]]
            submission["username"] = tuple(submission["username"])

            if submission["username"] not in result_per_user:
                result_per_user[submission["username"]] = {}


            if submission["taskid"] not in result_per_user[submission["username"]]:
                result_per_user[submission["username"]][submission["taskid"]] = submission["custom"]["score"]
            else:
                # keep best score
                current_score = result_per_user[submission["username"]][submission["taskid"]]
                new_score = submission["custom"]["score"]
                task_reversed = scoreboard_reverse != (scoreboard_content[submission["taskid"]] < 0)
                if task_reversed and current_score > new_score:
                    result_per_user[submission["username"]][submission["taskid"]] = new_score
                elif not task_reversed and current_score < new_score:
                    result_per_user[submission["username"]][submission["taskid"]] = new_score


            for user in submission["username"]:
                users.add(user)

        # Get user names
        users_realname = {}
        for username, userinfo in self.user_manager.get_users_info(list(users)).items():
            users_realname[username] = userinfo[0] if userinfo else username

        # Compute overall result per user, and sort them
        overall_result_per_user = {}
        for key, val in result_per_user.items():
            total = 0
            solved = 0
            for taskid, coef in scoreboard_content.items():
                if taskid in val:
                    total += val[taskid]*coef
                    solved += 1
            overall_result_per_user[key] = {"total": total, "solved": solved}
        sorted_users = list(overall_result_per_user.keys())
        sorted_users = sorted(sorted_users, key=sort_func(overall_result_per_user, scoreboard_reverse))

        # Compute table
        table = []

        # Header
        if len(scoreboard_content) == 1:
            header = ["", "Student(s)", "Score"]
            emphasized_columns = [2]
        else:
            header = ["", "Student(s)", "Solved", "Total score"] + [task_names[taskid] for taskid in list(scoreboard_content.keys())]
            emphasized_columns = [2, 3]

        # Lines
        old_score = ()
        rank = 0
        for user in sorted_users:
            # Increment rank if needed, and display it
            line = []
            if old_score != (overall_result_per_user[user]["solved"], overall_result_per_user[user]["total"]):
                rank += 1
                old_score = (overall_result_per_user[user]["solved"], overall_result_per_user[user]["total"])
                line.append(rank)
            else:
                line.append("")

            # Users
            line.append(",".join(sorted([users_realname[u] for u in user])))

            if len(scoreboard_content) == 1:
                line.append(overall_result_per_user[user]["total"])
            else:
                line.append(overall_result_per_user[user]["solved"])
                line.append(overall_result_per_user[user]["total"])
                for taskid in scoreboard_content:
                    line.append(result_per_user[user].get(taskid, ""))

            table.append(line)

        renderer = self.template_helper.get_custom_renderer('frontend/plugins/scoreboard')
        return renderer.scoreboard(course, scoreboardid, scoreboard_name, header, table, emphasized_columns)