diff --git a/events/models.py b/events/models.py
index dabbbfc..4f4fcf4 100644
--- a/events/models.py
+++ b/events/models.py
@@ -35,12 +35,20 @@ class Event(models.Model):
return self.count_with_status(EventRegistration.ADMITTED)
+ def registration_of(self, user):
+ registrations = self.eventregistration_set.filter(user=user).all()
+ if not registrations:
+ return None
+ assert len(registrations) == 1, "Registrations should be unique per user and event"
+ return registrations[0]
+
+
class EventRegistration(models.Model):
INTERESTED = "I"
ADMITTED = "A"
REGISTRATION_STATE = {
- INTERESTED: "Interested",
- ADMITTED: "Admitted",
+ INTERESTED: "Op wachtlijst",
+ ADMITTED: "Bevestigd",
}
event = models.ForeignKey(Event, on_delete=models.CASCADE)
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
diff --git a/events/templates/events/index.html b/events/templates/events/index.html
index ea02fed..6394b1f 100644
--- a/events/templates/events/index.html
+++ b/events/templates/events/index.html
@@ -2,16 +2,9 @@
{% block content %}
- {% for event in events %}
- - {{ event.date }} {{ event.time_str }}
-
+ {% for x in events %}
+
- {{ x.event.date }} {{ x.event.time_str }}
+ {% include "events/registrations.html" with event=x.event my_registration=x.my_registration %}
{% endfor %}
diff --git a/events/templates/events/registrations.html b/events/templates/events/registrations.html
new file mode 100644
index 0000000..49a777e
--- /dev/null
+++ b/events/templates/events/registrations.html
@@ -0,0 +1,14 @@
+
diff --git a/events/views.py b/events/views.py
index c2a1367..b2dcc6a 100644
--- a/events/views.py
+++ b/events/views.py
@@ -12,7 +12,12 @@ from events.tasks import assign_reservations
def index(request):
events = Event.objects.filter(date__gte=timezone.now().date()).order_by("date")[:20]
- return render(request, "events/index.html", {"events": events})
+
+ events_data = [
+ { "event": event, "my_registration": event.registration_of(request.user) }
+ for event in events
+ ]
+ return render(request, "events/index.html", {"events": events_data})
def view_score_stuff(request):
@@ -26,8 +31,8 @@ def register(request, event_id):
event = get_object_or_404(Event, id=event_id)
event.eventregistration_set.create(
- state=EventRegistration.INTERESTED,
- event=event,
- user=CustomUser.objects.get(),
+ state=EventRegistration.INTERESTED,
+ event=event,
+ user=request.user,
)
return HttpResponseRedirect(reverse("events:index") + f"#{event.id}")