|
|
|
|
@ -14,12 +14,19 @@ from .serializers import MigrationSerializer, MigrationOverView
|
|
|
|
|
|
|
|
|
|
from .models import Migration
|
|
|
|
|
|
|
|
|
|
def checkLimit(limit):
|
|
|
|
|
if limit == "":
|
|
|
|
|
limit = None
|
|
|
|
|
else:
|
|
|
|
|
limit = int(limit)
|
|
|
|
|
return limit
|
|
|
|
|
class MigrationList(APIView):
|
|
|
|
|
'''
|
|
|
|
|
Returns a list of migrations with simpleData
|
|
|
|
|
'''
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
migrations = Migration.objects.all()
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = Migration.objects.all()[:limit]
|
|
|
|
|
serializer = MigrationOverView(migrations, many=True)
|
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
|
|
@ -59,8 +66,9 @@ class MigrationsBooked(APIView):
|
|
|
|
|
Returns list of booked migrations
|
|
|
|
|
'''
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = MigrationOverView(Migration.objects.filter(
|
|
|
|
|
migration_status="Booked",), many=True)
|
|
|
|
|
migration_status="Booked",)[:limit], many=True)
|
|
|
|
|
return Response(migrations.data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
|
|
class MigrationsWaitingTerm(APIView):
|
|
|
|
|
@ -68,8 +76,9 @@ class MigrationsWaitingTerm(APIView):
|
|
|
|
|
Returns list of booked migrations
|
|
|
|
|
'''
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = MigrationOverView(Migration.objects.filter(
|
|
|
|
|
migration_status="Waiting Termination",), many=True)
|
|
|
|
|
migration_status="Waiting Termination",)[:limit], many=True)
|
|
|
|
|
return Response(migrations.data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
|
|
class MigrationsCompleted(APIView):
|
|
|
|
|
@ -77,8 +86,9 @@ class MigrationsCompleted(APIView):
|
|
|
|
|
Returns list of booked migrations
|
|
|
|
|
'''
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = MigrationOverView(Migration.objects.filter(
|
|
|
|
|
migration_status="Completed",), many=True)
|
|
|
|
|
migration_status="Completed",)[:limit], many=True)
|
|
|
|
|
return Response(migrations.data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
|
|
class PendingMigrations(APIView):
|
|
|
|
|
@ -86,10 +96,11 @@ class PendingMigrations(APIView):
|
|
|
|
|
Returns list of 'pending' migrations (migrations that are booked for today (maybe before timezone.now))
|
|
|
|
|
'''
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = Migration.objects.filter(
|
|
|
|
|
migration_status="Booked", booked_time__lte=timezone.now() + datetime.timedelta(1),
|
|
|
|
|
booked_time__gte=(timezone.now() + datetime.timedelta(-1))
|
|
|
|
|
)
|
|
|
|
|
)[:limit]
|
|
|
|
|
serializer = MigrationOverView(migrations, many=True)
|
|
|
|
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
|
|
@ -98,10 +109,11 @@ class MissedMigrations(APIView):
|
|
|
|
|
Returns a list of missed migrations
|
|
|
|
|
'''
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = Migration.objects.filter(
|
|
|
|
|
booked_time__lte=timezone.now() + datetime.timedelta(-1),
|
|
|
|
|
migration_status="Booked"
|
|
|
|
|
)
|
|
|
|
|
)[:limit]
|
|
|
|
|
serializer = MigrationOverView(migrations, many=True)
|
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
|
|
@ -110,52 +122,16 @@ class PendingTerm(APIView):
|
|
|
|
|
Returns a list of accounts pending termination (might add an arg so we can specify how many days)
|
|
|
|
|
'''
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = Migration.objects.filter(
|
|
|
|
|
migration_status="Waiting Termination", term_date__lte=timezone.now() + datetime.timedelta(1)
|
|
|
|
|
)
|
|
|
|
|
)[:limit]
|
|
|
|
|
serializer = MigrationOverView(migrations, many=True)
|
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
|
|
# class MigrationViewSet(viewsets.ModelViewSet):
|
|
|
|
|
# ''' Class for defining the migration views '''
|
|
|
|
|
# queryset = Migration.objects.all()
|
|
|
|
|
# serializer_class = MigrationOverView
|
|
|
|
|
# # permission_classes = (AllowAny,)
|
|
|
|
|
|
|
|
|
|
# @action(detail=False, methods=['GET'])
|
|
|
|
|
# def upcoming(self, request):
|
|
|
|
|
# ''' 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):
|
|
|
|
|
# ''' 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):
|
|
|
|
|
# ''' 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)
|
|
|
|
|
|
|
|
|
|
# @action(detail=False, methods=['GET'])
|
|
|
|
|
# def completed(self, request):
|
|
|
|
|
# ''' Returns a list of the completed migrations '''
|
|
|
|
|
# queryset = MigrationSerializer(Migration.objects.filter(
|
|
|
|
|
# migration_status="Completed",), many=True)
|
|
|
|
|
# return Response(queryset.data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
|
|
# @action(detail=False, methods=['GET'])
|
|
|
|
|
# def awaitterm(self, request):
|
|
|
|
|
# ''' Returns migrations awaiting termination '''
|
|
|
|
|
# queryset = MigrationSerializer(Migration.objects.filter(
|
|
|
|
|
# migration_status="Waiting Termination", term_date__lte=timezone.now()), many=True)
|
|
|
|
|
# return Response(queryset.data, status=status.HTTP_200_OK)
|
|
|
|
|
class MigrationListAll(APIView):
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
limit = checkLimit(request.GET.get('limit', ''))
|
|
|
|
|
migrations = Migration.objects.all()[:limit]
|
|
|
|
|
serializer = MigrationSerializer(migrations, many=True)
|
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|