from django.conf import settings from django.contrib.auth.decorators import login_required from django.shortcuts import render from fupogfakta.models import Category from .feature_flags import use_spa_ui from .i18n import lobby_i18n_catalog, resolve_locale def _render_spa_shell(request, shell_route: str, shell_kind: str): return render( request, "lobby/spa_shell.html", { "shell_route": shell_route, "shell_kind": shell_kind, "spa_asset_base": settings.WPP_SPA_ASSET_BASE, "spa_asset_version": getattr(settings, "WPP_SPA_ASSET_VERSION", "dev"), "lobby_i18n": lobby_i18n_catalog(), "shell_locale": resolve_locale(request), }, ) @login_required def host_screen(request, spa_path=None): if use_spa_ui(): host_route = "/host" if spa_path: normalized_spa_path = "/".join(segment for segment in spa_path.split("/") if segment) if normalized_spa_path: host_route = f"/host/{normalized_spa_path}" return _render_spa_shell(request, host_route, "host") categories = Category.objects.filter(is_active=True).order_by("name") return render( request, "lobby/host_screen.html", { "categories": categories, "lobby_i18n": lobby_i18n_catalog(), "shell_locale": resolve_locale(request), }, ) def player_screen(request): if use_spa_ui(): return _render_spa_shell(request, "/player", "player") return render( request, "lobby/player_screen.html", {"lobby_i18n": lobby_i18n_catalog(), "shell_locale": resolve_locale(request)}, )