Updated book path and added api key
This commit is contained in:
parent
1e54a033a8
commit
c498286dbe
5
.pylintrc
Normal file
5
.pylintrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
load-plugins=pylint_django
|
||||||
|
|
||||||
|
disable=all
|
||||||
|
|
||||||
|
enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode
|
||||||
@ -7,6 +7,7 @@ from rest_framework import routers
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('migrations/', views.MigrationList.as_view()),
|
path('migrations/', views.MigrationList.as_view()),
|
||||||
|
path('migrations/book/', views.BookMigration.as_view()),
|
||||||
path('migrations/all/', views.MigrationListAll.as_view()),
|
path('migrations/all/', views.MigrationListAll.as_view()),
|
||||||
path('migrations/booked/', views.MigrationsBooked.as_view()),
|
path('migrations/booked/', views.MigrationsBooked.as_view()),
|
||||||
path('migrations/waitingterm/', views.MigrationsWaitingTerm.as_view()),
|
path('migrations/waitingterm/', views.MigrationsWaitingTerm.as_view()),
|
||||||
@ -14,6 +15,7 @@ urlpatterns = [
|
|||||||
path('migrations/pending/', views.PendingMigrations.as_view()),
|
path('migrations/pending/', views.PendingMigrations.as_view()),
|
||||||
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/bookedslots/', views.MigrationTimeslotDetails.as_view()),
|
||||||
|
path('migrations/gettimeslots/', views.getTimeslots.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())
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -24,6 +24,13 @@ def checkLimit(limit):
|
|||||||
limit = int(limit)
|
limit = int(limit)
|
||||||
return limit
|
return limit
|
||||||
|
|
||||||
|
def checkDays(days):
|
||||||
|
if days == "":
|
||||||
|
days = 0
|
||||||
|
else:
|
||||||
|
days = int(days)
|
||||||
|
return days
|
||||||
|
|
||||||
def getAllMigrations(limit):
|
def getAllMigrations(limit):
|
||||||
return Migration.objects.all()[:limit]
|
return Migration.objects.all()[:limit]
|
||||||
|
|
||||||
@ -34,6 +41,7 @@ class MigrationList(APIView):
|
|||||||
'''
|
'''
|
||||||
Returns a list of migrations with simpleData
|
Returns a list of migrations with simpleData
|
||||||
'''
|
'''
|
||||||
|
permission_classes = []
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
return Response({'booked_count': Migration.objects.filter(migration_status="Booked").count(),
|
return Response({'booked_count': Migration.objects.filter(migration_status="Booked").count(),
|
||||||
'pendterm_count': Migration.objects.filter(migration_status="Waiting Termination", term_date=timezone.now()).count(),
|
'pendterm_count': Migration.objects.filter(migration_status="Waiting Termination", term_date=timezone.now()).count(),
|
||||||
@ -43,8 +51,8 @@ class MigrationList(APIView):
|
|||||||
migration_status="Booked"
|
migration_status="Booked"
|
||||||
).count(),
|
).count(),
|
||||||
"upcoming_count":Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date()).count()})
|
"upcoming_count":Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date()).count()})
|
||||||
# return Response(serializer.data)
|
|
||||||
|
|
||||||
|
class BookMigration(APIView):
|
||||||
def post(self, request, format=None):
|
def post(self, request, format=None):
|
||||||
booked_date = request.data["booked_date"]
|
booked_date = request.data["booked_date"]
|
||||||
timeslot = request.data["booked_time"]
|
timeslot = request.data["booked_time"]
|
||||||
@ -86,9 +94,10 @@ class MigrationsBooked(APIView):
|
|||||||
Returns list of booked migrations
|
Returns list of booked migrations
|
||||||
'''
|
'''
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
|
days = checkDays(request.GET.get('days', ''))
|
||||||
limit = checkLimit(request.GET.get('limit', ''))
|
limit = checkLimit(request.GET.get('limit', ''))
|
||||||
migrations = MigrationSerializer(Migration.objects.filter(
|
migrations = MigrationSerializer(Migration.objects.filter(
|
||||||
migration_status="Booked",)[:limit], many=True)
|
migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(days))[:limit], many=True)
|
||||||
return Response(migrations.data, status=status.HTTP_200_OK)
|
return Response(migrations.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
class MigrationsWaitingTerm(APIView):
|
class MigrationsWaitingTerm(APIView):
|
||||||
@ -96,8 +105,9 @@ class MigrationsWaitingTerm(APIView):
|
|||||||
Returns list of booked migrations
|
Returns list of booked migrations
|
||||||
'''
|
'''
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
|
days = checkDays(request.GET.get('days', ''))
|
||||||
limit = checkLimit(request.GET.get('limit', ''))
|
limit = checkLimit(request.GET.get('limit', ''))
|
||||||
migrations = MigrationSerializer(Migration.objects.filter(migration_status="Waiting Termination", term_date=timezone.now())[:limit], many=True)
|
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)
|
return Response(migrations.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
class MigrationsCompleted(APIView):
|
class MigrationsCompleted(APIView):
|
||||||
@ -112,7 +122,8 @@ class MigrationsCompleted(APIView):
|
|||||||
|
|
||||||
class PendingMigrations(APIView):
|
class PendingMigrations(APIView):
|
||||||
'''
|
'''
|
||||||
Returns list of 'pending' migrations (migrations that are booked for today (maybe before timezone.now))
|
Returns list of 'pending' migrations (migrations that
|
||||||
|
are booked for today (maybe before timezone.now))
|
||||||
'''
|
'''
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
limit = checkLimit(request.GET.get('limit', ''))
|
limit = checkLimit(request.GET.get('limit', ''))
|
||||||
@ -155,9 +166,15 @@ class MigrationListAll(APIView):
|
|||||||
|
|
||||||
class MigrationTimeslotDetails(APIView):
|
class MigrationTimeslotDetails(APIView):
|
||||||
def get(self, request):
|
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(),
|
slotDict = {}
|
||||||
'03:00-06:00': Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='03:00-06:00').count(),
|
days = checkDays(request.GET.get('days', ''))
|
||||||
'06:00-09:00': Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='06:00-09:00').count(),
|
# 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']
|
||||||
'08:00-12:00': Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='08:00-12:00').count(),
|
timeslots = settings.MIG_TIMESLOTS
|
||||||
'12:00-18:00':Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='12:00-18:00').count(),
|
for slot in timeslots:
|
||||||
'18:00-00:00':Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date(), booked_time='18:00-00:00').count()})
|
slotDict[slot] = Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(days), booked_time=slot).count()
|
||||||
|
return Response(slotDict)
|
||||||
|
|
||||||
|
|
||||||
|
class getTimeslots(APIView):
|
||||||
|
def get(self, request):
|
||||||
|
return Response(settings.MIG_TIMESLOTS)
|
||||||
@ -40,6 +40,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
|
"rest_framework_api_key",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@ -88,6 +89,12 @@ DATABASES = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
"DEFAULT_PERMISSION_CLASSES": [
|
||||||
|
"rest_framework_api_key.permissions.HasAPIKey",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
# DATABASES = {
|
# DATABASES = {
|
||||||
# 'default': {
|
# 'default': {
|
||||||
# 'ENGINE': 'django.db.backends.sqlite3',
|
# 'ENGINE': 'django.db.backends.sqlite3',
|
||||||
@ -135,4 +142,6 @@ CORS_ORIGIN_ALLOW_ALL = True
|
|||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
MIG_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']
|
||||||
MIGS_PER_TIMESLOT = 12
|
MIGS_PER_TIMESLOT = 12
|
||||||
|
# API_KEY_CUSTOM_HEADER = "HTTP_X_API_KEY"
|
||||||
Reference in New Issue
Block a user