Verified Commit 3b6f523d authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Add ordering instead of shortlist route

parent e60f6bfd
......@@ -179,7 +179,7 @@ class RegistrationSerializer(serializers.ModelSerializer):
def _queue_position(self, instance):
return (instance.queue_position()
if instance.queue_position() > 0 else None)
if instance.queue_position() > 0 else None)
def _is_cancelled(self, instance):
return instance.date_cancelled is not None
......
from datetime import datetime
from django.utils import timezone
from rest_framework import viewsets
from rest_framework import viewsets, filters
from rest_framework.decorators import list_route, detail_route
from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAuthenticated, IsAdminUser
......@@ -31,9 +31,11 @@ def _extract_date_range(request):
class EventViewset(viewsets.ReadOnlyModelViewSet):
queryset = Event.objects.filter(
end__gte=timezone.datetime.now(), published=True)
queryset = Event.objects.filter(end__gte=timezone.datetime.now(),
published=True)
permission_classes = [IsAuthenticated]
filter_backends = (filters.OrderingFilter,)
ordering_fields = ('start', 'end')
def get_serializer_class(self):
if self.action == 'list':
......@@ -67,21 +69,6 @@ class EventViewset(viewsets.ReadOnlyModelViewSet):
return Response(serializer.data)
@list_route()
def shortlist(self, request):
days = Event.objects.filter(
end__gte=timezone.datetime.now(), published=True
).datetimes('start', 'day')[:2]
data = list(map(lambda day: EventListSerializer(Event.objects.filter(
start__day=day.day,
start__month=day.month,
start__year=day.year,
published=True,
), many=True, context={'request': request}).data, days))
return Response(data)
@list_route(permission_classes=[])
def calendarjs(self, request):
end, start = _extract_date_range(request)
......
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