Example #1
0
def board(request, *, window_codename):
    """Displays rankings"""

    # Get window
    if window_codename == settings.OVERALL_WINDOW_CODENAME:
        window = None
    else:
        try:
            window = queries.get_window(window_codename)
        except models.Window.DoesNotExist:
            raise Http404()

    # Initialize context
    context = windowed_context(window)
    context['board'] = queries.board_cached(window)
    context['overall_window_codename'] = settings.OVERALL_WINDOW_CODENAME

    # Select correct template
    if window is None:
        context['score_normalization'] = settings.SCORE_NORMALIZATION
        context['current_window'] = queries.get_window()
        template_name = 'ctflex/board/overall.html'
    elif not window.started():
        template_name = 'ctflex/board/waiting.html'
    elif window.ended():
        template_name = 'ctflex/board/ended.html'
    else:
        template_name = 'ctflex/board/current.html'

    return render(request, template_name, context)
Example #2
0
def game(request, *, window_codename):
    """Display problems"""

    # Process request
    superuser = request.user.is_superuser
    team = request.user.competitor.team
    try:
        window = queries.get_window(window_codename)
    except models.Window.DoesNotExist:
        raise Http404()

    # Initialize context
    context = windowed_context(window)
    context['prob_list'] = queries.problem_list(team=team, window=window)
    context['max_flag_size'] = MAX_FLAG_SIZE
    js_context = {}

    if not window.started() and not superuser:
        template_name = 'ctflex/game/waiting.html'

        js_context[COUNTDOWN_ENDTIME_KEY] = window.start.isoformat()

    elif window.ended():
        template_name = 'ctflex/game/ended.html'

        current_window = queries.get_window()
        context['current_window'] = current_window

        # Check whether the current window is (in)active and
        # so whether the team could still solve problems
        context['can_compete_in_current_window'] = (
            current_window.ongoing()
            and (
                not team.has_timer(window)
                or team.has_active_timer(window)
            )
        )

    elif not team.has_timer(window) and not superuser:
        template_name = 'ctflex/game/inactive.html'

        js_context[COUNTDOWN_ENDTIME_KEY] = window.end.isoformat()
        js_context[COUNTDOWN_MAX_MICROSECONDS_KEY] = (
            window.personal_timer_duration.total_seconds() * 1000
        )

    elif not team.has_active_timer(window) and not superuser:
        template_name = 'ctflex/game/expired.html'

    else:
        template_name = 'ctflex/game/active.html'

        if superuser:
            messages.warning(request, "You are viewing this window as a superuser.")
        else:
            js_context[COUNTDOWN_ENDTIME_KEY] = team.timer(window).end.isoformat()

    context['js_context'] = json.dumps(js_context)
    return render(request, template_name, context)
Example #3
0
        def decorated(request, *args, window_codename=None, **kwargs):
            if window_codename is None:
                view_name = request.resolver_match.view_name
                kwargs['window_codename'] = queries.get_window().codename
                return HttpResponseRedirect(reverse(view_name, args=args, kwargs=kwargs))

            return view(request, *args, window_codename=window_codename, **kwargs)
Example #4
0
def announcements(request, *, window_codename):
    """List all announcements of window and mark them as read"""

    window = queries.get_window(window_codename)
    context = windowed_context(window)
    context['announcements'] = queries.announcements(window)

    commands.mark_announcements_read(request.user)

    return render(request, 'ctflex/misc/announcements.html', context)
Example #5
0
        def decorated(request, *args, window_codename=None, **kwargs):
            if window_codename is None:
                view_name = request.resolver_match.view_name
                try:
                    kwargs['window_codename'] = queries.get_window().codename
                except models.Window.DoesNotExist:
                    raise Http404()
                else:
                    return HttpResponseRedirect(reverse(view_name, args=args, kwargs=kwargs))

            return view(request, *args, window_codename=window_codename, **kwargs)
Example #6
0
def start_timer(request):
    """Start a team’s timer and redirect to the game"""

    window = queries.get_window()
    team = request.user.competitor.team

    success = commands.start_timer(team=team, window=window)

    if not success:
        messages.error(request, "Your timer could not be started.")

    return redirect(reverse('ctflex:game'))
Example #7
0
def start_timer(request):
    """Start a team’s timer and redirect to the game"""

    window = queries.get_window()
    team = request.user.competitor.team

    success = commands.start_timer(team=team, window=window)

    if not success:
        messages.error(request, "Your timer could not be started.")

    loggers.log_timer(request, success)

    return redirect(reverse('ctflex:game'))
Example #8
0
def announcements(request, *, window_codename):
    """List all announcements of window and mark them as read"""

    try:
        window = queries.get_window(window_codename)
    except models.Window.DoesNotExist:
        raise Http404()

    context = windowed_context(window)
    context['announcements'] = queries.announcements(window)

    commands.mark_announcements_read(request.user)

    return render(request, 'ctflex/misc/announcements.html', context)
Example #9
0
def unread_announcements(request):
    window = queries.get_window()
    count = queries.unread_announcements_count(window=window, user=request.user)
    return JsonResponse({
        'count': count,
    })
Example #10
0
def unread_announcements(request):
    window = queries.get_window()
    count = queries.unread_announcements_count(window=window, user=request.user)
    return JsonResponse({
        'count': count,
    })
Example #11
0
def solves(context, team):
    window = context.get('window', queries.get_window())
    return queries.solves(team=team, window=window).order_by('-date')


# endregion
Example #12
0
def score(context, team):
    window = context.get('window', queries.get_window())
    return queries.score(team=team, window=window)
Example #13
0
def solves(context, team):
    window = context.get('window', queries.get_window())
    return queries.solves(team=team, window=window).order_by('-date')


# endregion
Example #14
0
def score(context, team):
    window = context.get('window', queries.get_window())
    return queries.score(team=team, window=window)