Compare commits
No commits in common. "1e54a033a8bd6e2a9c8b942ca26f8c1ba8f16c7d" and "e9388ee78feb5b19d2b30809cd3d78bbc979d2ab" have entirely different histories.
1e54a033a8
...
e9388ee78f
@ -8,7 +8,7 @@ class MigrationAdmin(admin.ModelAdmin):
|
|||||||
list_display = ('ticket_id', 'booked_date' , 'booked_time',
|
list_display = ('ticket_id', 'booked_date' , 'booked_time',
|
||||||
'migration_status', 'domain', 'brand', 'agent_booked')
|
'migration_status', 'domain', 'brand', 'agent_booked')
|
||||||
search_fields = ['domain', 'booked_time',
|
search_fields = ['domain', 'booked_time',
|
||||||
'username', 'ticket_id', 'migration_status', 'agent_booked', 'booked_date']
|
'username', 'ticket_id', 'migration_status', 'agent_booked']
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Migration, MigrationAdmin)
|
admin.site.register(Migration, MigrationAdmin)
|
||||||
|
|||||||
@ -15,5 +15,4 @@ urlpatterns = [
|
|||||||
path('migrations/missed/', views.MissedMigrations.as_view()),
|
path('migrations/missed/', views.MissedMigrations.as_view()),
|
||||||
path('migrations/pendingterm/', views.PendingTerm.as_view()),
|
path('migrations/pendingterm/', views.PendingTerm.as_view()),
|
||||||
path('migrations/<str:pk>/', views.MigrationDetails.as_view()),
|
path('migrations/<str:pk>/', views.MigrationDetails.as_view()),
|
||||||
path('migrations/timeslots', views.MigrationTimeslotDetails.as_view())
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -5,15 +5,12 @@ from django.http import HttpResponseRedirect, JsonResponse, Http404
|
|||||||
from django.views import generic
|
from django.views import generic
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.conf import settings
|
|
||||||
from rest_framework import status, viewsets
|
from rest_framework import status, viewsets
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from .serializers import MigrationSerializer
|
from .serializers import MigrationSerializer
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
|
|
||||||
from .models import Migration
|
from .models import Migration
|
||||||
|
|
||||||
@ -46,15 +43,10 @@ class MigrationList(APIView):
|
|||||||
# return Response(serializer.data)
|
# return Response(serializer.data)
|
||||||
|
|
||||||
def post(self, request, format=None):
|
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)
|
serializer = MigrationSerializer(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class MigrationDetails(APIView):
|
class MigrationDetails(APIView):
|
||||||
@ -152,12 +144,3 @@ class MigrationListAll(APIView):
|
|||||||
migrations = getAllMigrations(limit)
|
migrations = getAllMigrations(limit)
|
||||||
serializer = MigrationSerializer(migrations, many=True)
|
serializer = MigrationSerializer(migrations, many=True)
|
||||||
return Response(serializer.data)
|
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,5 +134,3 @@ CORS_ORIGIN_ALLOW_ALL = True
|
|||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
MIGS_PER_TIMESLOT = 12
|
|
||||||
Reference in New Issue
Block a user