Added dateRange to timeslot details

This commit is contained in:
pepper 2021-01-20 22:20:39 -05:00
parent 210fefeaf1
commit d4e6a67d42

View File

@ -24,7 +24,13 @@ def checkLimit(limit):
limit = int(limit)
return limit
def checkDays(days):
def checkValue(value):
if value:
return True
else:
return False
def checkDayNumber(days):
if days == "":
days = 0
else:
@ -104,7 +110,7 @@ class MigrationsWaitingTerm(APIView):
Returns list of booked migrations
'''
def get(self, request, format=None):
days = checkDays(request.GET.get('days', ''))
days = checkDayNumber(request.GET.get('days', ''))
limit = checkLimit(request.GET.get('limit', ''))
migrations = MigrationSerializer(Migration.objects.filter(migration_status="Waiting Termination", term_date=datetime.datetime.now().date() + datetime.timedelta(days))[:limit], many=True)
return Response(migrations.data, status=status.HTTP_200_OK)
@ -125,7 +131,7 @@ class PendingMigrations(APIView):
are booked for today (maybe before timezone.now))
'''
def get(self, request, format=None):
days = checkDays(request.GET.get('days', ''))
days = checkDayNumber(request.GET.get('days', ''))
limit = checkLimit(request.GET.get('limit', ''))
migrations = Migration.objects.filter(
migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(days)
@ -166,10 +172,28 @@ class MigrationListAll(APIView):
class MigrationTimeslotDetails(APIView):
def get(self, request):
slotDict = {}
days = checkDays(request.GET.get('days', ''))
#TODO: FIX THIS GARBAGE I HATE IT
# 5 days starting day before - Return Array of arrays
day = checkDayNumber(request.GET.get('day', ''))
days = checkDayNumber(request.GET.get('noOfDays', ''))
# timeslots = ['00:00-03:00', '03:00-06:00', '06:00-09:00', '08:00-12:00', '12:00-18:00', '18:00-00:00']
timeslots = settings.MIG_TIMESLOTS
if checkValue(request.GET.get('values', '')):
slotArray = []
if days:
daySlotArray = []
for daynum in range(days):
for slot in timeslots:
slotArray.append(Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(daynum -1), booked_time=slot).count())
print(slotArray)
daySlotArray.append(slotArray)
slotArray = []
return Response(daySlotArray)
for slot in timeslots:
slotArray.append(Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(days), booked_time=slot).count())
return Response(slotArray)
else:
slotDict = {}
for slot in timeslots:
slotDict[slot] = Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(days), booked_time=slot).count()
return Response(slotDict)