def handle_form_and_redirect_to_ladder(request, ladder_id, form_class, template, context=None, form_name='form'): if not context: context = {} ladder = get_ladder_or_404(pk=ladder_id) if request.POST: form = form_class(ladder, request.POST) if form.is_valid(): form.save() return redirect(ladder) else: form = form_class(ladder) context[form_name] = form return view_with_ladder(request, ladder, template, context=context)
def handle_form(request, ladder_id, form_class, template, context=None, form_name='form'): if not context: context = {} ladder = get_ladder_or_404(pk=ladder_id) if request.POST: form = form_class(ladder, request.POST) if form.is_valid(): form.save() form.success = "Form submitted successfully" else: form = form_class(ladder) context[form_name] = form return view_with_ladder(request, ladder, template, context=context)
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)
def create_match(request, ladder_id): ladder = get_ladder_or_404(pk=ladder_id) games = int_or_none(request.GET.get('games')) if request.POST: form = get_match_form(ladder, post_dictionary=request.POST, number_of_games=games) if form.is_valid(): match = form.save() adjust_rankings(match) form = get_match_form(ladder, number_of_games=games) form.success = "Match created successfully" else: form = get_match_form(ladder, number_of_games=games) return view_with_ladder(request, ladder, 'leaderboard/content/match_entry_form.html', context={'form': form, 'ladder_players': get_ladder_players_for_match_entry(ladder)} )
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)
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)
def display_ladder(request, ladder_id): ladder = get_ladder_or_404(pk=ladder_id) return view_with_ladder(request, ladder, 'leaderboard/content/ladder.html')
def ladder_page(request, ladder_id): ladder = get_ladder_or_404(pk=ladder_id) return view_with_ladder(request, ladder, 'basic/ladder_page.html', {'navbar_active': 'ladder'} )
def decorated(request, ladder_id, *args, **kwargs): ladder = get_ladder_or_404(pk=ladder_id) if ladder.is_private and not (request.user.is_authenticated() and get_watcher(request.user, ladder)): return redirect('/home/') return f(request, ladder_id, *args, **kwargs)
def decorated(request, ladder_id, *args, **kwargs): ladder = get_ladder_or_404(pk=ladder_id) if not ladder.is_active: raise Http404() return f(request, ladder_id, *args, **kwargs)
def matches_page(request, ladder_id): ladder = get_ladder_or_404(pk=ladder_id) match_id = int_or_none(request.GET.get('id', None)) return view_with_ladder(request, ladder, 'leaderboard/matches_page.html', {'navbar_active': 'matches', 'match_id': match_id, 'match_feed_size': 10, })