|
|
|
|
@ -5,12 +5,15 @@ from django.http import HttpResponseRedirect, JsonResponse, Http404
|
|
|
|
|
from django.views import generic
|
|
|
|
|
from django.urls import reverse
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from rest_framework import status, viewsets
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
from rest_framework.decorators import action
|
|
|
|
|
from .serializers import MigrationSerializer
|
|
|
|
|
|
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from .models import Migration
|
|
|
|
|
|
|
|
|
|
@ -43,6 +46,11 @@ class MigrationList(APIView):
|
|
|
|
|
# return Response(serializer.data)
|
|
|
|
|
|
|
|
|
|
def post(self, request, format=None):
|
|
|
|
|
booked_date = request.data["booked_date"]
|
|
|
|
|
timeslot = request.data["booked_time"]
|
|
|
|
|
migs_in_slot = Migration.objects.filter(migration_status="Booked", booked_date=booked_date, booked_time=timeslot).count()
|
|
|
|
|
if migs_in_slot >= settings.MIGS_PER_TIMESLOT:
|
|
|
|
|
return Response({"SlotError": f"More than {settings.MIGS_PER_TIMESLOT} in timeslot {request.data['booked_time']}"}, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
serializer = MigrationSerializer(data=request.data)
|
|
|
|
|
if serializer.is_valid():
|
|
|
|
|
serializer.save()
|
|
|
|
|
@ -144,3 +152,12 @@ class MigrationListAll(APIView):
|
|
|
|
|
migrations = getAllMigrations(limit)
|
|
|
|
|
serializer = MigrationSerializer(migrations, many=True)
|
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
|
|
class MigrationTimeslotDetails(APIView):
|
|
|
|
|
def get(self, request):
|
|
|
|
|
return Response({'00:00-03:00': Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='00:00-03:00').count(),
|
|
|
|
|
'03:00-06:00': Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='03:00-06:00').count(),
|
|
|
|
|
'06:00-09:00': Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='06:00-09:00').count(),
|
|
|
|
|
'08:00-12:00': Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='08:00-12:00').count(),
|
|
|
|
|
'12:00-18:00':Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='12:00-18:00').count(),
|
|
|
|
|
'18:00-00:00':Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='18:00-00:00').count()})
|