|
|
|
@ -2,6 +2,8 @@ from django.shortcuts import render
|
|
|
|
|
from accounts.models import UserProfileInfo
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
import os
|
|
|
|
|
from events.models import Event, Team, EventPlayer
|
|
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
@ -24,4 +26,31 @@ def discord_bot(request):
|
|
|
|
|
data[user.discord_id] = rank
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|