|
@@ -1,9 +1,9 @@
|
|
|
-import random
|
|
|
import datetime
|
|
|
from django.db import IntegrityError
|
|
|
from django.http import HttpResponseNotFound, HttpResponseRedirect, JsonResponse, HttpResponseNotAllowed
|
|
|
from django.shortcuts import render
|
|
|
from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout
|
|
|
+from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
from .forms import CreateEventForm, LoginForm, UpdateSlotsForm
|
|
@@ -88,7 +88,6 @@ def login(request, url):
|
|
|
|
|
|
auth_login(request, user)
|
|
|
participant, created = Participant.objects.get_or_create(event=event, user=user)
|
|
|
- participant.slots = random.getrandbits(get_slot_count(event)).to_bytes((get_slot_count(event)+7) // 8, 'big')
|
|
|
participant.save()
|
|
|
request.session['user_id'] = user.id
|
|
|
return HttpResponseRedirect(f'/{event.url}')
|
|
@@ -120,6 +119,7 @@ def update_slots(request, url):
|
|
|
participant.save()
|
|
|
return HttpResponseRedirect(f'/{event.url}')
|
|
|
|
|
|
+@csrf_exempt
|
|
|
def slots_api(request, url):
|
|
|
"""
|
|
|
REST JSON API for slots of all participants of an event
|
|
@@ -136,6 +136,7 @@ def slots_api(request, url):
|
|
|
form = UpdateSlotsForm(request.POST, participant=participant)
|
|
|
if form.is_valid():
|
|
|
data = form.cleaned_data
|
|
|
+ print(data['slots'])
|
|
|
participant.slots = string2slots(data['slots'], slot_count)
|
|
|
participant.save()
|
|
|
|
|
@@ -144,7 +145,6 @@ def slots_api(request, url):
|
|
|
participants = event.participant_set.all()
|
|
|
for participant in participants:
|
|
|
data[participant.user.username] = slots2string(participant, slot_count)
|
|
|
- data[participant.user.username] = ''.join([random.choice(('0', '1')) for _ in range(slot_count)])
|
|
|
|
|
|
return JsonResponse(data)
|
|
|
|