Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tabbycat/utils/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from django.conf import settings
from django.db.models import Case, Q, Value, When

from tournaments.models import Tournament


def debate_context(request):
tournaments = Tournament.objects.filter(active=True)
Comment thread
merv1n34k marked this conversation as resolved.

context = {
'tabbycat_version': settings.TABBYCAT_VERSION or "",
'tabbycat_codename': settings.TABBYCAT_CODENAME or "no codename",
'all_tournaments': Tournament.objects.filter(active=True),
'all_tournaments': tournaments,
'disable_sentry': getattr(settings, 'DISABLE_SENTRY', False),
'on_local': getattr(settings, 'ON_LOCAL', False),
'hmr': getattr(settings, 'USE_WEBPACK_SERVER', False),
Expand All @@ -17,6 +19,16 @@ def debate_context(request):
if hasattr(request, 'tournament'):
current_round = request.tournament.current_round

# Put the current tournament first, include it even if inactive
context['all_tournaments'] = Tournament.objects.filter(
Q(active=True) | Q(pk=request.tournament.pk),
).annotate(
is_current=Case(
When(pk=request.tournament.pk, then=Value(0)),
default=Value(1),
),
).order_by('is_current', 'seq')

context.update({
'tournament': request.tournament,
'pref': request.tournament.preferences.by_name(),
Expand Down
Loading