<commit_before>from django.shortcuts import render, redirect
from datetime import datetime, timedelta
from .models import *
from .forms import *

# TODO: Make behavior consistent when a league has no seasons

def league_home(request, league_tag=None, season_id=None):
    league = _get_league(league_tag)
    current_season = _get_default_season(league_tag)
    season_list = list(Season.objects.filter(league=_get_league(league_tag)).order_by('-start_date', '-id'))
    season_list.remove(current_season)
    registration_season = Season.objects.filter(league=league, registration_open=True).order_by('-start_date')[0]
    
    team_scores = enumerate(sorted(TeamScore.objects.filter(team__season=current_season), reverse=True)[0:5], 1)
    
    rules_doc = LeagueDocument.objects.filter(league=league, type='rules').first()
    rules_doc_tag = rules_doc.tag if rules_doc is not None else None
    intro_doc = LeagueDocument.objects.filter(league=league, type='intro').first()
    
    # TODO: Use the lichess api to check the game status and remove games even if a game link hasn't been posted yet
    # TODO: Convert game times to the user's local time (maybe in JS?)
    current_game_time_min = datetime.utcnow() - timedelta(hours=3)
    current_game_time_max = datetime.utcnow() + timedelta(minutes=5)
    current_games = Pairing.objects.filter(team_pairing__round__season=current_season, result='', date_played__gt=current_game_time_min, date_played__lt=current_game_time_max).exclude(game_link='').order_by('date_played')
    upcoming_game_time_min = datetime.utcnow() - timedelta(minutes=5)
    upcoming_game_time_max = datetime.utcnow() + timedelta(hours=12)
    upcoming_games = Pairing.objects.filter(team_pairing__round__season=current_season, game_link='', result='', date_played__gt=upcoming_game_time_min, date_played__lt=upcoming_game_time_max).order_by('date_played')
    
    context = {
        'league_tag': league_tag,
        'season_id': season_id,
        'season': current_season,
        'league': league,
        'team_scores': team_scores,
        'season_list': season_list,
        'rules_doc_tag': rules_doc_tag,
        'intro_doc': intro_doc,
        'can_edit_document': request.user.has_perm('tournament.change_document'),
        'registration_season': registration_season,
        'current_games': current_games,
        'upcoming_games': upcoming_games,
    }
    return render(request, 'tournament/league_home.html', context)

def season_landing(request, league_tag=None, season_id=None):
    season = _get_season(league_tag, season_id)
    default_season = _get_default_season(league_tag)
    season_list = list(Season.objects.filter(league=_get_league(league_tag)).order_by('-start_date', '-id'))
    season_list.remove(default_season)
    
    active_round = Round.objects.filter(season=season).order_by('-number').first()
    last_round = Round.objects.filter(season=season, is_completed=True).order_by('-number').first()
    last_round_pairings = last_round.teampairing_set.all()
    team_scores = enumerate(sorted(TeamScore.objects.filter(team__season=season), reverse=True)[:5], 1)
    tie_score = season.boards
    
    context = {
        'league_tag': league_tag,
        'season_id': season_id,
        'season': season,<commit_msg>Minor fixes<commit_after>from django.shortcuts import render, redirect
from datetime import datetime, timedelta
from .models import *
from .forms import *

# TODO: Make behavior consistent when a league has no seasons

def league_home(request, league_tag=None, season_id=None):
    league = _get_league(league_tag)
    current_season = _get_default_season(league_tag)
    season_list = Season.objects.filter(league=_get_league(league_tag)).order_by('-start_date', '-id').exclude(pk=current_season.pk)
    registration_season = Season.objects.filter(league=league, registration_open=True).order_by('-start_date').first()
    
    team_scores = enumerate(sorted(TeamScore.objects.filter(team__season=current_season), reverse=True)[:5], 1)
    
    rules_doc = LeagueDocument.objects.filter(league=league, type='rules').first()
    rules_doc_tag = rules_doc.tag if rules_doc is not None else None
    intro_doc = LeagueDocument.objects.filter(league=league, type='intro').first()
    
    # TODO: Use the lichess api to check the game status and remove games even if a game link hasn't been posted yet
    # TODO: Convert game times to the user's local time (maybe in JS?)
    current_game_time_min = datetime.utcnow() - timedelta(hours=3)
    current_game_time_max = datetime.utcnow() + timedelta(minutes=5)
    current_games = Pairing.objects.filter(team_pairing__round__season=current_season, result='', date_played__gt=current_game_time_min, date_played__lt=current_game_time_max).exclude(game_link='').order_by('date_played')
    upcoming_game_time_min = datetime.utcnow() - timedelta(minutes=5)
    upcoming_game_time_max = datetime.utcnow() + timedelta(hours=12)
    upcoming_games = Pairing.objects.filter(team_pairing__round__season=current_season, game_link='', result='', date_played__gt=upcoming_game_time_min, date_played__lt=upcoming_game_time_max).order_by('date_played')
    
    context = {
        'league_tag': league_tag,
        'season_id': season_id,
        'season': current_season,
        'league': league,
        'team_scores': team_scores,
        'season_list': season_list,
        'rules_doc_tag': rules_doc_tag,
        'intro_doc': intro_doc,
        'can_edit_document': request.user.has_perm('tournament.change_document'),
        'registration_season': registration_season,
        'current_games': current_games,
        'upcoming_games': upcoming_games,
    }
    return render(request, 'tournament/league_home.html', context)

def season_landing(request, league_tag=None, season_id=None):
    season = _get_season(league_tag, season_id)
    default_season = _get_default_season(league_tag)
    season_list = Season.objects.filter(league=_get_league(league_tag)).order_by('-start_date', '-id').exclude(pk=default_season.pk)
    
    active_round = Round.objects.filter(season=season).order_by('-number').first()
    last_round = Round.objects.filter(season=season, is_completed=True).order_by('-number').first()
    last_round_pairings = last_round.teampairing_set.all() if last_round is not None else None
    team_scores = enumerate(sorted(TeamScore.objects.filter(team__season=season), reverse=True)[:5], 1)
    tie_score = season.boards
    
    context = {
        'league_tag': league_tag,
        'season_id': season_id,
        'season': season,
{'fraction_non_alphanumeric': 0.11244674376141205, 'fraction_numerical': 0.0030432136335970784, 'mean_word_length': 4.9863387978142075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92516', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2057, 'n_words': 363}