|
|
|
|
@ -21,51 +21,72 @@ from qr_code.qrcode.utils import QRCodeOptions |
|
|
|
|
|
|
|
|
|
def index(request): |
|
|
|
|
|
|
|
|
|
tomorrow = date.today() + timedelta(days=1) |
|
|
|
|
|
|
|
|
|
club_id = request.GET.get('club') |
|
|
|
|
q_base = Q(is_private=False, is_deleted=False) |
|
|
|
|
future = future_tournaments(club_id) |
|
|
|
|
live = live_tournaments(club_id) |
|
|
|
|
finished = finished_tournaments(club_id) |
|
|
|
|
|
|
|
|
|
return render( |
|
|
|
|
request, |
|
|
|
|
"tournaments/tournaments.html", |
|
|
|
|
{ |
|
|
|
|
'future': future[:10], |
|
|
|
|
'live': live[:10], |
|
|
|
|
'ended': finished[:10], |
|
|
|
|
'club': club, |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
q_after_tomorrow = [q_base, Q(end_date__isnull=True, start_date__gt=tomorrow)] |
|
|
|
|
q_unfinished = [q_base, Q(end_date__isnull=True)] |
|
|
|
|
q_ended = [q_base, Q(end_date__isnull=False)] |
|
|
|
|
def tournaments_query(query, club_id, ascending): |
|
|
|
|
queries = [query, Q(is_private=False, is_deleted=False)] |
|
|
|
|
|
|
|
|
|
club = None |
|
|
|
|
if club_id: |
|
|
|
|
club = get_object_or_404(Club, pk=club_id) |
|
|
|
|
|
|
|
|
|
q_club = Q(event__club=club) |
|
|
|
|
q_after_tomorrow.append(q_club) |
|
|
|
|
q_unfinished.append(q_club) |
|
|
|
|
q_ended.append(q_club) |
|
|
|
|
queries.append(q_club) |
|
|
|
|
|
|
|
|
|
sortkey = 'start_date' |
|
|
|
|
if not ascending: |
|
|
|
|
sortkey = '-start_date' |
|
|
|
|
return Tournament.objects.filter(*queries).order_by(sortkey) |
|
|
|
|
|
|
|
|
|
after_tomorrow_tournaments = Tournament.objects.filter(*q_after_tomorrow).order_by('start_date') |
|
|
|
|
filtered_after_tomorrow_tournaments = [] |
|
|
|
|
for tournament in after_tomorrow_tournaments: |
|
|
|
|
if tournament.display_tournament(): |
|
|
|
|
filtered_after_tomorrow_tournaments.append(tournament) |
|
|
|
|
def finished_tournaments(club_id): |
|
|
|
|
ended_tournaments = tournaments_query(Q(end_date__isnull=False), club_id, False) |
|
|
|
|
return [t for t in ended_tournaments if t.display_tournament()] |
|
|
|
|
|
|
|
|
|
unfinished_tournaments = Tournament.objects.filter(*q_unfinished).order_by('start_date') |
|
|
|
|
def live_tournaments(club_id): |
|
|
|
|
tournaments = tournaments_query(Q(end_date__isnull=True), club_id, True) |
|
|
|
|
return [t for t in tournaments if t.display_tournament() and t.supposedly_in_progress()] |
|
|
|
|
|
|
|
|
|
live_tournaments = [] |
|
|
|
|
for tournament in unfinished_tournaments: |
|
|
|
|
if tournament.supposedly_in_progress() and tournament.display_tournament(): |
|
|
|
|
live_tournaments.append(tournament) |
|
|
|
|
def future_tournaments(club_id): |
|
|
|
|
tomorrow = date.today() + timedelta(days=1) |
|
|
|
|
tournaments = tournaments_query(Q(end_date__isnull=True, start_date__gt=tomorrow), club_id, True) |
|
|
|
|
return [t for t in tournaments if t.display_tournament()] |
|
|
|
|
|
|
|
|
|
def tournaments(request): |
|
|
|
|
|
|
|
|
|
ended_tournaments = Tournament.objects.filter(*q_ended).order_by('-start_date') |
|
|
|
|
filter = int(request.GET.get('filter')) |
|
|
|
|
club_id = request.GET.get('club') |
|
|
|
|
|
|
|
|
|
filtered_ended_tournaments = [] |
|
|
|
|
for tournament in ended_tournaments: |
|
|
|
|
if tournament.display_tournament(): |
|
|
|
|
filtered_ended_tournaments.append(tournament) |
|
|
|
|
title = '' |
|
|
|
|
tournaments = [] |
|
|
|
|
if filter==0: |
|
|
|
|
title = 'À venir' |
|
|
|
|
tournaments = future_tournaments(club_id) |
|
|
|
|
elif filter==1: |
|
|
|
|
title = 'En cours' |
|
|
|
|
tournaments = live_tournaments(club_id) |
|
|
|
|
elif filter==2: |
|
|
|
|
title = 'Terminés' |
|
|
|
|
tournaments = finished_tournaments(club_id) |
|
|
|
|
|
|
|
|
|
return render( |
|
|
|
|
request, |
|
|
|
|
"tournaments/tournaments.html", |
|
|
|
|
"tournaments/tournaments_list.html", |
|
|
|
|
{ |
|
|
|
|
'future': filtered_after_tomorrow_tournaments, |
|
|
|
|
'live': live_tournaments, |
|
|
|
|
'ended': filtered_ended_tournaments, |
|
|
|
|
'tournaments': tournaments, |
|
|
|
|
'title': title, |
|
|
|
|
'club': club, |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|