43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
import datetime
|
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
from django.http import HttpResponseRedirect, JsonResponse
|
|
from django.views import generic
|
|
from django.urls import reverse
|
|
from django.utils import timezone
|
|
from rest_framework import status, viewsets
|
|
from rest_framework.response import Response
|
|
from rest_framework.decorators import action
|
|
from .serializers import MigrationSerializer
|
|
|
|
|
|
from .models import Migration
|
|
|
|
|
|
class MigrationViewSet(viewsets.ModelViewSet):
|
|
''' Class for defining the migration views '''
|
|
queryset = Migration.objects.all()
|
|
serializer_class = MigrationSerializer
|
|
# permission_classes = (AllowAny,)
|
|
|
|
@action(detail=False, methods=['GET'])
|
|
def upcoming(self, request, *args, **kwargs):
|
|
''' Returns a list of the migrations due today '''
|
|
queryset = MigrationSerializer(
|
|
Migration.objects.filter(booked_time=timezone.now(), migration_status="Booked"), many=True)
|
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
|
|
|
@action(detail=False, methods=['GET'])
|
|
def missed(self, request, *args, **kwargs):
|
|
''' Returns a list of the missed migrations (Still have the status booked and date is greater then today) '''
|
|
queryset = MigrationSerializer(
|
|
Migration.objects.filter(booked_time__gte=timezone.now() + datetime.timedelta(1), migration_status="Booked"), many=True)
|
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
|
|
|
@action(detail=False, methods=['GET'])
|
|
def booked(self, request, *args, **kwargs):
|
|
''' Returns a list of the booked migrations '''
|
|
queryset = MigrationSerializer(Migration.objects.filter(
|
|
migration_status="booked",), many=True)
|
|
return Response(queryset.data, status=status.HTTP_200_OK)
|