Пример #1
0
def get_answer(request, task_id):
    task = get_object_or_404(Task, id=task_id)
    team = None
    if has_profile(request.user):
        team = request.user.profile.team_on
    game = task.task_group.game

    if not task.task_group.game.has_access('play', team=team):
        return NoGameAccessException('User {} has no access to game {}'.format(
            request.user.profile, game))

    mode = game.get_current_mode()

    if mode != 'general' and not task_ok_by_team(
            task, request.user.profile.team_on, mode):
        return NoAnswerAccessException(
            'User {} has no access to answers to task {} right now'.format(
                request.user.profile, task))

    return JsonResponse({
        'html':
        render(request, 'answer.html', {
            'task': task,
        }).content.decode('UTF-8'),
    })
Пример #2
0
    def get_games_list(self, request):
        team = None
        if has_profile(request.user):
            team = request.user.profile.team_on

        games_list = []

        project = get_object_or_404(Project, id=self.project_name)
        for game in Game.objects.filter(project=project):
            if game.has_access('see_game_preview', team=team):
                games_list.append(game)
        return sorted(games_list, key=lambda game: (game.start_time, game.name), reverse=True)
Пример #3
0
def process_user_request(request, user_id, action):
    active_user = request.user
    passive_user = get_object_or_404(get_user_model(), id=int(user_id))
    if has_profile(passive_user):
        if active_user != passive_user and \
           active_user.profile.team_on == passive_user.profile.team_requested:
            passive_user.profile.team_requested = None
            if action == 'confirm':
                passive_user.profile.team_on = active_user.profile.team_on
            else:
                passive_user.profile.team_on = None
            passive_user.profile.save()
    return redirect_to_referer(request)
Пример #4
0
def results_page(request, game_id, mode='general'):
    game = get_object_or_404(Game, id=game_id)
    if has_profile(request.user) and request.user.profile.team_on and \
       not game.has_access('see_results', mode=mode, team=request.user.profile.team_on):
        return defaults.page_not_found(request)

    team_to_list_attempts_info = {}
    team_to_score = {}
    team_to_max_best_time = {}
    team_task_to_attempts_info = {}

    task_groups = sorted(game.task_groups.all(), key=lambda tg: tg.number)
    task_group_to_tasks = {}

    for task_group in task_groups:
        task_group_to_tasks[task_group.number] = sorted(
            task_group.tasks.filter(
                ~Q(task_type='text_with_forms')
            )  # исключаем задания этого типа из таблички
            ,
            key=lambda t: t.key_sort())
        for task in task_group_to_tasks[task_group.number]:
            for attempts_info in Attempt.manager.get_task_attempts_infos(
                    task=task, mode=mode):
                if attempts_info.attempts or attempts_info.hint_attempts:
                    if attempts_info.attempts:
                        team = attempts_info.attempts[0].team
                    else:
                        team = attempts_info.hint_attempts[0].team
                    if not team.is_hidden:
                        if team not in team_to_score:
                            team_to_score[team] = 0
                        task_points = 0
                        if attempts_info.best_attempt is not None:
                            task_points = attempts_info.best_attempt.points

                        if task_points > 0:
                            team_to_score[team] += max(
                                0, task_points -
                                attempts_info.get_sum_hint_penalty())
                            if team not in team_to_max_best_time:
                                team_to_max_best_time[
                                    team] = attempts_info.best_attempt.time
                            else:
                                team_to_max_best_time[team] = max(
                                    team_to_max_best_time[team],
                                    attempts_info.best_attempt.time)

                        team_task_to_attempts_info[(team,
                                                    task)] = attempts_info

    for team in team_to_score.keys():
        for task_group in task_groups:
            for task in task_group_to_tasks[task_group.number]:
                if team not in team_to_list_attempts_info:
                    team_to_list_attempts_info[team] = []
                if (team, task) in team_task_to_attempts_info:
                    attempts_info = team_task_to_attempts_info[(team, task)]
                    team_to_list_attempts_info[team].append(attempts_info)
                else:
                    team_to_list_attempts_info[team].append(None)

    teams_sorted = []
    for team in team_to_score.keys():
        score = team_to_score[team]
        max_best_time = team_to_max_best_time.get(team, None)
        teams_sorted.append((-score, max_best_time, team))
    teams_sorted = [
        team for anti_score, max_best_time, team in sorted(
            teams_sorted, key=lambda t: (t[0], t[1], str(t[2])))
    ]

    return render(
        request, 'results.html', {
            'mode': mode,
            'game': game,
            'task_groups': task_groups,
            'task_group_to_tasks': task_group_to_tasks,
            'teams_sorted': teams_sorted,
            'team_to_list_attempts_info': team_to_list_attempts_info,
            'team_to_score': team_to_score,
            'team_to_max_best_time': team_to_max_best_time,
        })