Example #1
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)
Example #2
0
def matches(request):
    """
    Returns a paged feed of matches
    """
    ladder_id = empty_string_if_none(int_or_none(request.GET.get('ladder_id')))
    match_id = empty_string_if_none(int_or_none(request.GET.get('match_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)

    paginator = Paginator(get_match_feed(ladder=ladder_id, user=user_id), size)
    page = get_page_with_item(paginator, match_id) if match_id else get_page(paginator, page_number)

    context = {'feed': page, 'match_feed_size': size,
        'match_id': match_id,
        'feed_ladder': ladder if ladder_id else ladder_id,
        'matches_user': user if user_id else user_id,
        'feed_ladder_options': get_played_ladder_feed(user, order='name') if user_id else None,
    }

    context['feed_info'] = {
        'name': 'Match History',
        'prefix': 'match',
        'span_name': 'match-feed-span',
        'span_size': 6,
        'url': '/ladders/leaderboard/content/matches/',
        '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/match_feed.html', context)