118 lines
4.2 KiB
Python
118 lines
4.2 KiB
Python
"""
|
|
URL configuration for polylan_submitter project.
|
|
|
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
|
https://docs.djangoproject.com/en/5.2/topics/http/urls/
|
|
Examples:
|
|
Function views
|
|
1. Add an import: from my_app import views
|
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
|
Class-based views
|
|
1. Add an import: from other_app.views import Home
|
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
|
Including another URLconf
|
|
1. Import the include() function: from django.urls import include, path
|
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
|
"""
|
|
|
|
from django.contrib import admin
|
|
from django.http import Http404, HttpRequest
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
from django.urls import path
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.conf import settings
|
|
from django.conf.urls.static import static
|
|
from simple_cas_views import SimpleCASLoginView, SimpleCASLogoutView
|
|
from events.models import Event
|
|
from games.decorators import require_game_enabled
|
|
from market.views import market_home
|
|
from submissions.views import submission_home, submission_view
|
|
from .api import api
|
|
|
|
NOITA_APP_ID = 881100
|
|
OPUS_MAGNUM_APP_ID = 558990
|
|
|
|
|
|
@login_required
|
|
def home(request: HttpRequest):
|
|
event = Event.objects.order_by("-created_at").first()
|
|
if event is None:
|
|
raise Http404("No event configured")
|
|
return redirect("event.home", event_path=event.path)
|
|
|
|
|
|
@login_required
|
|
def event_home(request: HttpRequest, event_path: str):
|
|
get_object_or_404(Event, path=event_path)
|
|
return render(request, "app.html")
|
|
|
|
|
|
@login_required
|
|
@require_game_enabled(OPUS_MAGNUM_APP_ID)
|
|
def opus_magnum_home(request: HttpRequest, event_path: str):
|
|
get_object_or_404(Event, path=event_path)
|
|
return render(request, "app.html")
|
|
|
|
|
|
@login_required
|
|
@require_game_enabled(NOITA_APP_ID)
|
|
def noita_home(request: HttpRequest, event_path: str):
|
|
get_object_or_404(Event, path=event_path)
|
|
return render(request, "app.html")
|
|
|
|
|
|
@login_required
|
|
@require_game_enabled(path="clock")
|
|
def clock_home(request: HttpRequest, event_path: str):
|
|
get_object_or_404(Event, path=event_path)
|
|
return render(request, "app.html")
|
|
|
|
|
|
@login_required
|
|
@require_game_enabled(path="place")
|
|
def place_home(request: HttpRequest, event_path: str):
|
|
get_object_or_404(Event, path=event_path)
|
|
return render(request, "app.html")
|
|
|
|
|
|
# Deliberately not behind @login_required: this is meant to be dropped into
|
|
# an <iframe> (an OBS browser source, a stream overlay) that can't do the
|
|
# CAS SSO login flow. It's read-only anyway - placing a pixel still requires
|
|
# a logged-in websocket connection (see place/consumers.py) - so the only
|
|
# thing this exposes to anonymous viewers is the live canvas itself, same as
|
|
# watching the non-embed page already allows.
|
|
@require_game_enabled(path="place")
|
|
def place_embed(request: HttpRequest, event_path: str):
|
|
get_object_or_404(Event, path=event_path)
|
|
return render(request, "app.html")
|
|
|
|
|
|
urlpatterns = [
|
|
path("admin/", admin.site.urls),
|
|
path("cas/login/", SimpleCASLoginView.as_view(), name="cas_ng_login"),
|
|
path("cas/logout/", SimpleCASLogoutView.as_view(), name="cas_ng_logout"),
|
|
path("api/", api.urls),
|
|
path("<slug:event_path>/market", market_home, name="market.home"),
|
|
path("<slug:event_path>/opus-magnum", opus_magnum_home, name="opus-magnum.home"),
|
|
path("<slug:event_path>/noita", noita_home, name="noita.home"),
|
|
path("<slug:event_path>/clock", clock_home, name="clock.home"),
|
|
path("<slug:event_path>/place", place_home, name="place.home"),
|
|
path("<slug:event_path>/place/embed", place_embed, name="place.embed"),
|
|
path(
|
|
"<slug:event_path>/submissions/<slug:game_path>",
|
|
submission_home,
|
|
name="submissions.home",
|
|
),
|
|
path(
|
|
"<slug:event_path>/submissions/<slug:game_path>/<uuid:scope_id>",
|
|
submission_view,
|
|
name="submissions.view",
|
|
),
|
|
path("<slug:event_path>/", event_home, name="event.home"),
|
|
path("", home, name="home"),
|
|
]
|
|
|
|
# Serve media files in development
|
|
if settings.DEBUG:
|
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|