Added timeslots and migs_per_slot
This commit is contained in:
parent
dacbfdca33
commit
1e54a033a8
@ -15,4 +15,5 @@ urlpatterns = [
|
||||
path('migrations/missed/', views.MissedMigrations.as_view()),
|
||||
path('migrations/pendingterm/', views.PendingTerm.as_view()),
|
||||
path('migrations/<str:pk>/', views.MigrationDetails.as_view()),
|
||||
path('migrations/timeslots', views.MigrationTimeslotDetails.as_view())
|
||||
]
|
||||
|
||||
@ -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,10 +46,15 @@ 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()
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
class MigrationDetails(APIView):
|
||||
@ -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()})
|
||||
@ -134,3 +134,5 @@ CORS_ORIGIN_ALLOW_ALL = True
|
||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
MIGS_PER_TIMESLOT = 12
|
||||
Reference in New Issue
Block a user