From fd0b89825f706aca6862f8c1a0be9323264218b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?=
 <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de>
Date: Wed, 17 Feb 2021 23:22:12 +0100
Subject: [PATCH] Fix API detail views

Previously, the event from the url was not parsed correctly for API endpoints for individual AKs, AKRooms, etc. This led to self.event being None and the queryset being empty, hence the AK, AKRoom etc. could not be found by the API. This fix makes sure, the event is loaded as part of the API initialization for all endpoints and methods.
---
 AKModel/views.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/AKModel/views.py b/AKModel/views.py
index d560e9f6..c06090a0 100644
--- a/AKModel/views.py
+++ b/AKModel/views.py
@@ -38,6 +38,11 @@ class EventSlugMixin:
         self._load_event()
         return super().create(request, *args, **kwargs)
 
+    def initial(self, request, *args, **kwargs):
+        if self.event is None:
+            self._load_event()
+        super().initial(request, *args, **kwargs)
+
     def get_context_data(self, *, object_list=None, **kwargs):
         context = super().get_context_data(object_list=object_list, **kwargs)
         # Add event to context (to make it accessible in templates)
-- 
GitLab