Compare commits
2 Commits
e9388ee78f
...
1e54a033a8
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e54a033a8 | |||
| dacbfdca33 |
@ -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']
|
'username', 'ticket_id', 'migration_status', 'agent_booked', 'booked_date']
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Migration, MigrationAdmin)
|
admin.site.register(Migration, MigrationAdmin)
|
||||||
|
|||||||
@ -15,4 +15,5 @@ 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,12 +5,15 @@ 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
|
||||||
|
|
||||||
@ -43,6 +46,11 @@ 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()
|
||||||
@ -144,3 +152,12 @@ 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,3 +134,5 @@ 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