Verified Commit b5bca7fd authored by Gijs Hendriksen's avatar Gijs Hendriksen Committed by Sébastiaan Versteeg
Browse files

Added API for event info

parent b00f294c
......@@ -88,3 +88,10 @@ class UnpublishedEventSerializer(CalenderJSSerializer):
def _url(self, instance):
return reverse('events:admin-details', kwargs={
'event_id': instance.id})
class EventDataSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = ('title', 'description', 'start', 'end', 'organiser',
'location', 'price', 'fine')
......@@ -2,13 +2,13 @@ from datetime import datetime
from django.utils import timezone
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.decorators import list_route
from rest_framework.permissions import IsAuthenticated, IsAdminUser
from events.api.permissions import UnpublishedEventPermissions
from events.api.serializers import EventSerializer, UnpublishedEventSerializer
from events.api.serializers import EventSerializer, UnpublishedEventSerializer, EventDataSerializer
from events.models import Event
......@@ -54,3 +54,19 @@ class EventViewset(viewsets.ViewSet):
serializer = UnpublishedEventSerializer(queryset, many=True,
context={'user': request.user})
return Response(serializer.data)
@list_route(permission_classes=[IsAuthenticated])
def data(self, request):
if 'event_id' not in request.query_params:
raise ParseError(detail='missing required event_id parameter')
try:
serializer = EventDataSerializer(
Event.objects.get(pk=request.query_params['event_id'])
)
return Response(serializer.data)
except Event.DoesNotExist:
raise ParseError(detail='No event with id {}'.format(
request.query_params['event_id']
)
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment