Compare commits
No commits in common. "070a647fdd1fef67eae8a10bd73fbf2c091c2732" and "125fe62da0f77c59af05aeddf10eef20457b4609" have entirely different histories.
070a647fdd
...
125fe62da0
@ -30,7 +30,7 @@ class Migration(models.Model):
|
|||||||
|
|
||||||
def print_missed_migrations(self):
|
def print_missed_migrations(self):
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
return now >= self.booked_time and self.migration_status == 'Booked'
|
return now >= self.booked_time
|
||||||
print_missed_migrations.admin_order_field = 'booked_time'
|
print_missed_migrations.admin_order_field = 'booked_time'
|
||||||
print_missed_migrations.boolean = True
|
print_missed_migrations.boolean = True
|
||||||
print_missed_migrations.short_description = "Was this migration missed?"
|
print_missed_migrations.short_description = "Was this migration missed?"
|
||||||
|
|||||||
@ -1,14 +1,6 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import Migration
|
from .models import Migration
|
||||||
|
|
||||||
class MigrationOverView(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Migration
|
|
||||||
fields = ['id',
|
|
||||||
'domain',
|
|
||||||
'booked_time',
|
|
||||||
'migration_status',
|
|
||||||
'term_date']
|
|
||||||
|
|
||||||
class MigrationSerializer(serializers.ModelSerializer):
|
class MigrationSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@ -2,16 +2,9 @@ from django.urls import include, path
|
|||||||
from . import views
|
from . import views
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
# router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
# router.register('migrations', views.MigrationList)
|
router.register('migrations', views.MigrationViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('migrations/', views.MigrationList.as_view()),
|
path('', include(router.urls))
|
||||||
path('migrations/booked/', views.MigrationsBooked.as_view()),
|
|
||||||
path('migrations/waitingterm/', views.MigrationsWaitingTerm.as_view()),
|
|
||||||
path('migrations/completed/', views.MigrationsCompleted.as_view()),
|
|
||||||
path('migrations/pending/', views.PendingMigrations.as_view()),
|
|
||||||
path('migrations/missed/', views.MissedMigrations.as_view()),
|
|
||||||
path('migrations/pendingterm/', views.PendingTerm.as_view()),
|
|
||||||
path('migrations/<str:pk>/', views.MigrationDetails.as_view()),
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,161 +1,59 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.http import HttpResponseRedirect, JsonResponse, Http404
|
from django.http import HttpResponseRedirect, JsonResponse
|
||||||
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 rest_framework import status, viewsets
|
from rest_framework import status, viewsets
|
||||||
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, MigrationOverView
|
from .serializers import MigrationSerializer
|
||||||
|
|
||||||
|
|
||||||
from .models import Migration
|
from .models import Migration
|
||||||
|
|
||||||
class MigrationList(APIView):
|
|
||||||
'''
|
|
||||||
Returns a list of migrations with simpleData
|
|
||||||
'''
|
|
||||||
def get(self, request, format=None):
|
|
||||||
migrations = Migration.objects.all()
|
|
||||||
serializer = MigrationOverView(migrations, many=True)
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
||||||
def post(self, request, format=None):
|
class MigrationViewSet(viewsets.ModelViewSet):
|
||||||
serializer = MigrationSerializer(data=request.data)
|
''' Class for defining the migration views '''
|
||||||
if serializer.is_valid():
|
queryset = Migration.objects.all()
|
||||||
serializer.save()
|
serializer_class = MigrationSerializer
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
# permission_classes = (AllowAny,)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
class MigrationDetails(APIView):
|
@action(detail=False, methods=['GET'])
|
||||||
'''
|
def upcoming(self, request):
|
||||||
Returns full migration details
|
''' Returns a list of the migrations due today '''
|
||||||
'''
|
queryset = MigrationSerializer(
|
||||||
def getObject(self, pk):
|
Migration.objects.filter(booked_time=timezone.now(),
|
||||||
try:
|
migration_status="Booked"), many=True)
|
||||||
migration = Migration.objects.get(id=pk)
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||||
return migration
|
|
||||||
except Migration.DoesNotExist:
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
def get(self, request, pk, format=None):
|
@action(detail=False, methods=['GET'])
|
||||||
migration = self.getObject(pk)
|
def missed(self, request):
|
||||||
serializer = MigrationSerializer(migration)
|
''' Returns a list of the missed migrations (Still have the status
|
||||||
return Response(serializer.data)
|
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)
|
||||||
|
|
||||||
def put(self, request, pk, format=None):
|
@action(detail=False, methods=['GET'])
|
||||||
migration = self.getObject(pk)
|
def booked(self, request):
|
||||||
serializer = MigrationSerializer(migration, data=request.data)
|
''' Returns a list of the booked migrations '''
|
||||||
if serializer.is_valid():
|
queryset = MigrationSerializer(Migration.objects.filter(
|
||||||
serializer.save()
|
|
||||||
return Response(serializer.data)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
class MigrationsBooked(APIView):
|
|
||||||
'''
|
|
||||||
Returns list of booked migrations
|
|
||||||
'''
|
|
||||||
def get(self, request, format=None):
|
|
||||||
migrations = MigrationOverView(Migration.objects.filter(
|
|
||||||
migration_status="Booked",), many=True)
|
migration_status="Booked",), many=True)
|
||||||
return Response(migrations.data, status=status.HTTP_200_OK)
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
class MigrationsWaitingTerm(APIView):
|
@action(detail=False, methods=['GET'])
|
||||||
'''
|
def completed(self, request):
|
||||||
Returns list of booked migrations
|
''' Returns a list of the completed migrations '''
|
||||||
'''
|
queryset = MigrationSerializer(Migration.objects.filter(
|
||||||
def get(self, request, format=None):
|
|
||||||
migrations = MigrationOverView(Migration.objects.filter(
|
|
||||||
migration_status="Waiting Termination",), many=True)
|
|
||||||
return Response(migrations.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
class MigrationsCompleted(APIView):
|
|
||||||
'''
|
|
||||||
Returns list of booked migrations
|
|
||||||
'''
|
|
||||||
def get(self, request, format=None):
|
|
||||||
migrations = MigrationOverView(Migration.objects.filter(
|
|
||||||
migration_status="Completed",), many=True)
|
migration_status="Completed",), many=True)
|
||||||
return Response(migrations.data, status=status.HTTP_200_OK)
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
class PendingMigrations(APIView):
|
@action(detail=False, methods=['GET'])
|
||||||
'''
|
def awaitterm(self, request):
|
||||||
Returns list of 'pending' migrations (migrations that are booked for today (maybe before timezone.now))
|
''' Returns migrations awaiting termination '''
|
||||||
'''
|
queryset = MigrationSerializer(Migration.objects.filter(
|
||||||
def get(self, request, format=None):
|
migration_status="Waiting Termination", term_date__lte=timezone.now()), many=True)
|
||||||
migrations = Migration.objects.filter(
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||||
migration_status="Booked", booked_time__lte=timezone.now() + datetime.timedelta(1),
|
|
||||||
booked_time__gte=(timezone.now() + datetime.timedelta(-1))
|
|
||||||
)
|
|
||||||
serializer = MigrationOverView(migrations, many=True)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
class MissedMigrations(APIView):
|
|
||||||
'''
|
|
||||||
Returns a list of missed migrations
|
|
||||||
'''
|
|
||||||
def get(self, request, format=None):
|
|
||||||
migrations = Migration.objects.filter(
|
|
||||||
booked_time__lte=timezone.now() + datetime.timedelta(-1),
|
|
||||||
migration_status="Booked"
|
|
||||||
)
|
|
||||||
serializer = MigrationOverView(migrations, many=True)
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
||||||
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):
|
|
||||||
migrations = Migration.objects.filter(
|
|
||||||
migration_status="Waiting Termination", term_date__lte=timezone.now() + datetime.timedelta(1)
|
|
||||||
)
|
|
||||||
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)
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ SECRET_KEY = 'cq3daur*kk2+*-)@s%wq1c+pc7xi-c1ig@-%wq)m7pn3+zxbre'
|
|||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['10.6.9.42', 'benjamyn.love', 'localhost']
|
ALLOWED_HOSTS = ['10.6.9.42']
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
@ -80,9 +80,9 @@ WSGI_APPLICATION = 'migratorapi.wsgi.application'
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'NAME': 'devmigs',
|
'NAME': 'migration',
|
||||||
'USER': 'devmig',
|
'USER': 'migration',
|
||||||
'PASSWORD': 'XXgDh1i6w8rqp4BG',
|
'PASSWORD': 'migration123',
|
||||||
'HOST': '127.0.0.1',
|
'HOST': '127.0.0.1',
|
||||||
'PORT': '3306',
|
'PORT': '3306',
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user