Compare commits
4 Commits
b2b1d15bc2
...
33140dde73
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33140dde73 | ||
|
|
e24d274cfd | ||
|
|
ee69baf7de | ||
|
|
5370395143 |
18
migratorapi/api/migrations/0009_migration_is_urgent.py
Normal file
18
migratorapi/api/migrations/0009_migration_is_urgent.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.2 on 2020-10-22 01:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0008_auto_20201021_1805'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='migration',
|
||||||
|
name='is_urgent',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -6,6 +6,7 @@ from django.utils import timezone
|
|||||||
|
|
||||||
|
|
||||||
class Migration(models.Model):
|
class Migration(models.Model):
|
||||||
|
"""This is the migration class"""
|
||||||
id = models.CharField(max_length=200, unique=True,
|
id = models.CharField(max_length=200, unique=True,
|
||||||
default=uuid.uuid4, primary_key=True)
|
default=uuid.uuid4, primary_key=True)
|
||||||
submit_time = models.DateField('migrtation submitted on')
|
submit_time = models.DateField('migrtation submitted on')
|
||||||
@ -22,6 +23,7 @@ class Migration(models.Model):
|
|||||||
additional_domains = models.CharField(
|
additional_domains = models.CharField(
|
||||||
max_length=500, null=True, blank=True)
|
max_length=500, null=True, blank=True)
|
||||||
migration_type = models.CharField(max_length=200)
|
migration_type = models.CharField(max_length=200)
|
||||||
|
is_urgent = models.BooleanField(default=False)
|
||||||
|
|
||||||
def print_missed_migrations(self):
|
def print_missed_migrations(self):
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
|
|||||||
@ -1,3 +1,25 @@
|
|||||||
|
import datetime
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.utils import timezone
|
||||||
|
# from django.urls import reverse
|
||||||
|
|
||||||
# Create your tests here.
|
from .models import Migration
|
||||||
|
|
||||||
|
|
||||||
|
def create_migration(submit_time, domain, booked_time, original_server,
|
||||||
|
new_server, username, notes, brand, ticket_id, migration_status,
|
||||||
|
agent_booked, additional_domains, migration_type, is_urgent):
|
||||||
|
|
||||||
|
return Migration.objects.create(submit_time=submit_time, domain=domain, booked_time=booked_time, original_server=original_server,
|
||||||
|
new_server=new_server, username=username, notes=notes, brand=brand, ticket_id=ticket_id,
|
||||||
|
migration_status=migration_status, agent_booked=agent_booked, additional_domains=additional_domains,
|
||||||
|
migration_type=migration_type, is_urgent=is_urgent)
|
||||||
|
|
||||||
|
|
||||||
|
class MigrationModelTests(TestCase):
|
||||||
|
def test_migration_is_booked(self):
|
||||||
|
migration = create_migration(submit_time=timezone.now(), domain="test.com", booked_time=timezone.now() + datetime.timedelta(1),
|
||||||
|
original_server='1.2.3.4', new_server="4.3.2.1", username="ben", notes="", brand="VentraIP", ticket_id="VIP-1234567", migration_status="Booked",
|
||||||
|
agent_booked="BL", additional_domains="", migration_type="cPanel", is_urgent=False)
|
||||||
|
print(migration.migration_status)
|
||||||
|
self.assertTrue(migration.migration_status == "Booked")
|
||||||
|
|||||||
@ -1,45 +1,42 @@
|
|||||||
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
|
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 .serializers import MigrationSerializer
|
|
||||||
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 .models import Migration
|
from .models import Migration
|
||||||
|
|
||||||
|
|
||||||
class MigrationViewSet(viewsets.ModelViewSet):
|
class MigrationViewSet(viewsets.ModelViewSet):
|
||||||
|
''' Class for defining the migration views '''
|
||||||
queryset = Migration.objects.all()
|
queryset = Migration.objects.all()
|
||||||
serializer_class = MigrationSerializer
|
serializer_class = MigrationSerializer
|
||||||
# permission_classes = (AllowAny,)
|
# permission_classes = (AllowAny,)
|
||||||
|
|
||||||
@action(detail=False, methods=['GET'])
|
@action(detail=False, methods=['GET'])
|
||||||
def upcoming(self, request, *args, **kwargs):
|
def upcoming(self, request, *args, **kwargs):
|
||||||
|
''' Returns a list of the migrations due today '''
|
||||||
queryset = MigrationSerializer(
|
queryset = MigrationSerializer(
|
||||||
Migration.objects.filter(booked_time=timezone.now(), migration_status="Booked"), many=True)
|
Migration.objects.filter(booked_time=timezone.now(), migration_status="Booked"), many=True)
|
||||||
return Response(queryset.data, status=status.HTTP_200_OK)
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
@action(detail=False, methods=['GET'])
|
@action(detail=False, methods=['GET'])
|
||||||
def missed(self, request, *args, **kwargs):
|
def missed(self, request, *args, **kwargs):
|
||||||
|
''' Returns a list of the missed migrations (Still have the status booked and date is greater then today) '''
|
||||||
queryset = MigrationSerializer(
|
queryset = MigrationSerializer(
|
||||||
Migration.objects.filter(booked_time__gte=timezone.now() + datetime.timedelta(1), migration_status="Booked"), many=True)
|
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)
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
@action(detail=False, methods=['GET'])
|
@action(detail=False, methods=['GET'])
|
||||||
def booked(self, request, *args, **kwargs):
|
def booked(self, request, *args, **kwargs):
|
||||||
|
''' Returns a list of the booked migrations '''
|
||||||
queryset = MigrationSerializer(Migration.objects.filter(
|
queryset = MigrationSerializer(Migration.objects.filter(
|
||||||
migration_status="booked",), many=True)
|
migration_status="booked",), many=True)
|
||||||
return Response(queryset.data, status=status.HTTP_200_OK)
|
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class IndexView(generic.ListView):
|
|
||||||
template_name = 'api/index.html'
|
|
||||||
context_object_name = 'latest_migrations'
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""Return the last five published questions (not including those set in the future)."""
|
|
||||||
return Migration.objects.filter(booked_time__gte=timezone.now()).order_by('-booked_time')[:5]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user