2020-07-22 04:08:30 +02:00
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.shortcuts import render, get_object_or_404
|
2020-07-22 05:03:01 +02:00
|
|
|
|
2020-07-22 04:08:30 +02:00
|
|
|
from django.utils import timezone
|
|
|
|
from django.urls import reverse
|
|
|
|
import datetime
|
2020-07-21 22:24:45 +02:00
|
|
|
|
2020-07-22 04:08:30 +02:00
|
|
|
from .models import Event, EventRegistration, CustomUser
|
2020-07-21 22:24:45 +02:00
|
|
|
|
2020-07-22 04:02:13 +02:00
|
|
|
from events.tasks import assign_reservations
|
|
|
|
|
2020-07-21 22:24:45 +02:00
|
|
|
|
|
|
|
def index(request):
|
2020-07-22 04:08:30 +02:00
|
|
|
events = Event.objects.filter(date__gte=timezone.now().date()).order_by("date")[:20]
|
|
|
|
return render(request, "events/index.html", {"events": events})
|
2020-07-22 04:02:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
def view_score_stuff(request):
|
|
|
|
return HttpResponse(
|
|
|
|
assign_reservations()
|
|
|
|
)
|
2020-07-22 04:13:20 +02:00
|
|
|
|
|
|
|
|
2020-07-22 04:08:30 +02:00
|
|
|
def register(request, event_id):
|
|
|
|
if request.method == "POST":
|
|
|
|
event = get_object_or_404(Event, id=event_id)
|
|
|
|
|
2020-07-22 04:45:01 +02:00
|
|
|
event.eventregistration_set.create(
|
2020-07-22 05:03:01 +02:00
|
|
|
state=EventRegistration.INTERESTED,
|
|
|
|
event=event,
|
|
|
|
user=CustomUser.objects.get(),
|
2020-07-22 04:45:01 +02:00
|
|
|
)
|
2020-07-22 04:27:18 +02:00
|
|
|
return HttpResponseRedirect(reverse("events:index") + f"#{event.id}")
|