def view_tips(request, round_id): """ Display the Legends tips and results for the round. Show results, tips and tip forms depending on the state of play. Handle tip submission via ajax. """ if round_id: selected_round = Round.objects.get(id=int(round_id)) else: selected_round = Round.objects.get(id=request.session['live_round']) request.session['selected_round'] = selected_round.id selected_round.set_tipping_deadline() games = selected_round.games.all() clubs = selected_round.clubs_by_games(games) # We want to see results, tips or tip forms depending on the state of the # round form_games = [] result_games = [] tip_games = [] for game in games: tips = game.tips_by_club(clubs) if game.status == 'Scheduled': if game.deadline_has_passed: tip_games.append((game, tips)) else: form_games.append((game, tips)) else: result_games.append((game, tips)) tip_games.append((game, tips)) # Render the round navigation buttons content = render_round_nav(request, selected_round) # Render tip results/tips/forms content += render_results(request, selected_round, result_games) content += render_tips(request, selected_round, tip_games) content += render_tip_forms(request, selected_round, form_games) # Render login or change password form content += render_auth_form(request) context = { 'content': content, 'live_round': Round.objects.get(id=request.session['live_round']), 'club': Club.objects.get(id=request.session['club']), 'selected_page': selected_page, } return render_to_response( 'main.html', context, context_instance=RequestContext(request) )
def index(request): """ Render the index page """ today = datetime.datetime.today() year = today.year while True: try: season = Season.objects.get(season=year) break except Season.DoesNotExist: year -= 1 request.session['live_season'] = season.season live_round = season.live_round request.session['live_round'] = live_round.id # Set the tipping deadline - needed for "split" rounds and rounds with games # played on days other than Friday, Saturday or Sunday live_round.set_tipping_deadline() if request.user.is_authenticated(): club = request.user.clubs.all()[0] request.session['club'] = club.id return redirect('%s/tips/' % live_round.id) else: request.session['club'] = None context = { 'content': render_auth_form(request), 'live_round': live_round, 'selected_page': active_page } return render_to_response( 'main.html', context, context_instance=RequestContext(request) )
def view_ladder(request, round_id=None, view_name=None): """ Show: * the ladder for the latest completed round if round_id isn't specified or final. * the ladder for the last home/away round if round is a finals round. * the Legends ladder if view_name isn't specified. """ live_round = Round.objects.get(id=request.session['live_round']) if round_id: selected_round = Round.objects.get(id=int(round_id)) else: selected_round = live_round if selected_round.is_finals: selected_round = Round.objects \ .filter(season=selected_round.season) \ .filter(is_finals=False) \ .reverse()[0] if view_name: redirect_url = '/legends/%s/%s/' % (selected_round.id, view_name) else: redirect_url = '/legends/%s/ladders/' % selected_round.id return redirect(redirect_url) if not selected_round.status in ('Provisional', 'Final'): # There won't be a ladder if no games have been played for the season, # so redirect to the tips page for Round 1 (eventually) if selected_round.name == 'Round 1': redirect_url = '/legends/%s/tips/' % selected_round.id else: selected_round = selected_round.previous_round if view_name: redirect_url = '/legends/%s/%s/' % (selected_round.id, view_name) else: redirect_url = '/legends/%s/ladders/' % selected_round.id return redirect(redirect_url) if not view_name: view_name = 'view_legends_ladder' ladder_name = view_name.split('_')[1] content = render_ladder_nav(request, selected_round, ladder_name) content += render_ladder(request, ladder_name, selected_round) auth_form = render_auth_form(request) content += auth_form context = { 'content': content, 'club': Club.objects.get(id=request.session['club']), 'live_round': live_round, 'selected_page': selected_page } return render_to_response( 'main.html', context, context_instance=RequestContext(request) )