feat: clock + place games

This commit is contained in:
2026-09-17 01:33:54 +02:00
parent d104480188
commit 6866b45f66
46 changed files with 2043 additions and 10 deletions
+14 -6
View File
@@ -7,17 +7,25 @@ from events.models import Event
from .models import Game
def require_game_enabled(steam_app_id: int):
def require_game_enabled(steam_app_id: int | None = None, *, path: str | None = None):
"""Gate a view (or, via @decorate_view, an API operation) behind an
EventGame being enabled for the current event. Steam games are looked up
by steam_app_id (the original, positional form); custom non-Steam games
(no steam_app_id) are looked up by their Game.path instead, e.g.
require_game_enabled(path="clock")."""
def decorator(view_func):
@wraps(view_func)
def wrapper(request, *args, **kwargs):
event = get_object_or_404(Event, path=kwargs.get("event_path"))
games = Game.objects.enabled_for_event(event)
games = (
games.filter(steam_app_id=steam_app_id)
if steam_app_id is not None
else games.filter(path=path)
)
if (
not Game.objects.enabled_for_event(event)
.filter(steam_app_id=steam_app_id)
.exists()
):
if not games.exists():
raise PermissionDenied
return view_func(request, *args, **kwargs)