Skip to content
Snippets Groups Projects
Commit 8fa33406 authored by Roang's avatar Roang
Browse files

Fix event detail lookup

Event lookups should lead to 404 when the event was not found.
Ref: https://www.django-rest-framework.org/api-guide/generic-views/#genericapiview

Fixes 366
parent 2ce90e33
No related branches found
No related tags found
No related merge requests found
from rest_framework import generics
from core.models.events import Event from core.models.events import Event
from django.shortcuts import get_object_or_404
from rest_framework import generics
from ..serializers import EventSerializer from ..serializers import EventSerializer
from .mixins import ConferenceSlugMixin from .mixins import ConferenceSlugMixin
...@@ -10,12 +10,14 @@ class EventList(ConferenceSlugMixin, generics.ListAPIView): ...@@ -10,12 +10,14 @@ class EventList(ConferenceSlugMixin, generics.ListAPIView):
serializer_class = EventSerializer serializer_class = EventSerializer
def get_queryset(self, **kwargs): def get_queryset(self, **kwargs):
return Event.objects.filter(conference=self.conference).order_by('name') return Event.objects.filter(conference=self.conference).order_by("name")
class EventDetail(ConferenceSlugMixin, generics.RetrieveAPIView): class EventDetail(ConferenceSlugMixin, generics.RetrieveAPIView):
serializer_class = EventSerializer serializer_class = EventSerializer
def get_object(self, **kwargs): def get_object(self, **kwargs):
event_id = self.request.resolver_match.kwargs['pk'] event_id = self.request.resolver_match.kwargs["pk"]
return Event.objects.conference_accessible(conference=self.conference).get(pk=event_id) return get_object_or_404(
Event.objects.conference_accessible(conference=self.conference), pk=event_id
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment