Compare commits

..

No commits in common. "7dad96d79fe47d1fd40726b89f7f5811da25b2b4" and "280ba0d1fcd799b0821206589738a09b5e94fb92" have entirely different histories.

2 changed files with 1 additions and 31 deletions

View File

@ -3,5 +3,4 @@ from . import views
urlpatterns = [ urlpatterns = [
path('bot/discord', views.discord_bot, name='discord_bot'), path('bot/discord', views.discord_bot, name='discord_bot'),
path('events/<str:event_slug>', views.events_data, name='events_data'),
] ]

View File

@ -2,8 +2,6 @@ from django.shortcuts import render
from accounts.models import UserProfileInfo from accounts.models import UserProfileInfo
from django.http import JsonResponse from django.http import JsonResponse
import os import os
from events.models import Event, Team, EventPlayer
from django.shortcuts import get_object_or_404
# Create your views here. # Create your views here.
@ -27,30 +25,3 @@ def discord_bot(request):
rank += 1 rank += 1
return JsonResponse(data) return JsonResponse(data)
def events_data(request, event_slug):
if request.method != 'GET':
return JsonResponse({'error':'bad request'})
event_info = get_object_or_404(Event, slug=event_slug)
if event_info.password and request.GET.get('password') != event_info.password:
return JsonResponse({'error':'not authorized'})
players = EventPlayer.objects.filter(event=event_info)
data = {}
if event_info.team_size > 1:
for player in players:
if not player.team:
continue
if not player.team.name in data:
data[player.team.name] = []
data[player.team.name].append({"name": player.user.username, "score": player.score})
else:
for player in players:
data[player.user.username] = player.score
return JsonResponse(data)