Пример #1
0
def stats(request):
    """
    Returns statistics for the given user
    """
    user_id = empty_string_if_none(int_or_none(request.GET.get('user_id')))
    ladder_id = empty_string_if_none(int_or_none(request.GET.get('ladder_id')))
    if not user_id:
        return HttpResponseBadRequest()
    context = {'stats_user': get_user_or_404(pk=user_id), 'stats_ladder': None}
    if ladder_id:
        context['stats_ladder'] = get_ladder_or_404(pk=ladder_id)
    context['stats_user_ladders'] = get_played_ladder_feed(context['stats_user'], order='name')
    context['stats'] = get_stats(user_id, ladder=ladder_id)
    return render(request, 'leaderboard/content/player_stats.html', context)
Пример #2
0
def matchups(request):
    ladder_id = empty_string_if_none(int_or_none(request.GET.get('ladder_id')))
    user_id = empty_string_if_none(int_or_none(request.GET.get('user_id')))
    page_number = empty_string_if_none(int_or_none(request.GET.get('page')))
    size = empty_string_if_none(int_or_none(request.GET.get('size', 5)))

    if ladder_id:
        ladder = get_ladder_or_404(pk=ladder_id)
    if user_id:
        user = get_user_or_404(pk=user_id)

    context = {
        'matchup_user': user if user_id else user_id,
        'feed_ladder': ladder if ladder_id else ladder_id,
        'feed_ladder_options': get_played_ladder_feed(user, order='name') if user_id else None,
    }

    paginator = Paginator(users_played(user_id=user_id, ladder_id=ladder_id), size)
    page = get_page(paginator, page_number)
    context['feed'] = page

    for matchup_user in page:
        matchup_user.stats = get_stats(user_id, ladder=ladder_id, other_user_id=matchup_user.id)
        matchup_user.user = matchup_user
        if ladder_id:
            matchup_user.ladder = ladder

    context['feed_info'] = {
        'name': 'Matchups',
        'prefix': 'matchup',
        'span_name': 'matchup-feed-span',
        'span_size': 6,
        'url': '/ladders/leaderboard/content/matchups/',
        'url_parameters': {
            'ladder_id': ladder_id if ladder_id else '',
            'user_id': user_id if user_id else '',
            'size': size,
        },
    }
    return render(request, 'leaderboard/content/matchup_feed.html', context)