Compare commits

...

8 Commits

Author SHA1 Message Date
benjamyn
7b15bb75b1 Merge branch 'master' of ssh://ssh.git.lovelynet.net:9001/The_Bois/MigratorProject 2020-10-21 03:10:40 -04:00
benjamyn
c905ad8d5f Added missed function 2020-10-21 03:10:30 -04:00
benjamyn
f9c071aa43 Added ID/UUID to the serializer 2020-10-21 03:10:23 -04:00
benjamyn
8e521902f6 Added UUID PK field 2020-10-21 03:10:05 -04:00
benjamyn
619378c432 Added a test function for the API 2020-10-20 04:07:22 -04:00
benjamyn
b229c752a3 Updated model for allowing blanks 2020-10-20 03:57:41 -04:00
benjamyn
4b58bc833c Updated migrations for schema change 2020-10-20 03:57:29 -04:00
benjamyn
c49b5c169f Moved django over to rest_framework 2020-10-20 03:57:14 -04:00
10 changed files with 175 additions and 8 deletions

View File

@ -0,0 +1,28 @@
# Generated by Django 3.1.2 on 2020-10-20 07:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0003_auto_20201018_1259'),
]
operations = [
migrations.AlterField(
model_name='migration',
name='additional_domains',
field=models.CharField(max_length=500, null=True),
),
migrations.AlterField(
model_name='migration',
name='notes',
field=models.CharField(max_length=1024, null=True),
),
migrations.AlterField(
model_name='migration',
name='ticket_id',
field=models.CharField(max_length=64),
),
]

View File

@ -0,0 +1,28 @@
# Generated by Django 3.1.2 on 2020-10-20 08:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0004_auto_20201020_1855'),
]
operations = [
migrations.AlterField(
model_name='migration',
name='additional_domains',
field=models.CharField(blank=True, max_length=500, null=True),
),
migrations.AlterField(
model_name='migration',
name='notes',
field=models.CharField(blank=True, max_length=1024, null=True),
),
migrations.AlterField(
model_name='migration',
name='submit_time',
field=models.DateField(verbose_name='migrtation submitted on'),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.2 on 2020-10-21 06:59
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('api', '0005_auto_20201020_1915'),
]
operations = [
migrations.AddField(
model_name='migration',
name='uuid',
field=models.CharField(default=uuid.uuid4, max_length=200),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.2 on 2020-10-21 07:02
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('api', '0006_migration_uuid'),
]
operations = [
migrations.AlterField(
model_name='migration',
name='uuid',
field=models.CharField(default=uuid.uuid4, max_length=200, unique=True),
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 3.1.2 on 2020-10-21 07:05
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('api', '0007_auto_20201021_1802'),
]
operations = [
migrations.RemoveField(
model_name='migration',
name='uuid',
),
migrations.AlterField(
model_name='migration',
name='id',
field=models.CharField(default=uuid.uuid4, max_length=200, primary_key=True, serialize=False, unique=True),
),
]

View File

@ -1,27 +1,31 @@
import datetime
import uuid
from django.db import models
from django.utils import timezone
class Migration(models.Model):
submit_time = models.DateTimeField('migrtation submitted on')
id = models.CharField(max_length=200, unique=True,
default=uuid.uuid4, primary_key=True)
submit_time = models.DateField('migrtation submitted on')
domain = models.CharField(max_length=200)
booked_time = models.DateTimeField('Migration booked for')
original_server = models.CharField(max_length=200)
new_server = models.CharField(max_length=200)
username = models.CharField(max_length=200)
notes = models.CharField(max_length=1024)
notes = models.CharField(max_length=1024, null=True, blank=True)
brand = models.CharField(max_length=200)
ticket_id = models.CharField(max_length=200)
ticket_id = models.CharField(max_length=64)
migration_status = models.CharField(max_length=200, default='Booked')
agent_booked = models.CharField(max_length=10)
additional_domains = models.CharField(max_length=500)
additional_domains = models.CharField(
max_length=500, null=True, blank=True)
migration_type = models.CharField(max_length=200)
def print_missed_migrations(self):
now = timezone.now()
return now + datetime.timedelta(days=1) >= self.booked_time >= now
return now >= self.booked_time
print_missed_migrations.admin_order_field = 'booked_time'
print_missed_migrations.boolean = True
print_missed_migrations.short_description = "Was this migration missed?"

View File

@ -0,0 +1,21 @@
from rest_framework import serializers
from .models import Migration
class MigrationSerializer(serializers.ModelSerializer):
class Meta:
model = Migration
fields = ['id',
'submit_time',
'domain',
'booked_time',
'original_server',
'new_server',
'username',
'notes',
'brand',
'ticket_id',
'migration_status',
'agent_booked',
'additional_domains',
'migration_type']

View File

@ -1,7 +1,10 @@
from django.urls import path
from django.urls import include, path
from . import views
from rest_framework import routers
router = routers.DefaultRouter()
router.register('migrations', views.MigrationViewSet)
app_name = 'api'
urlpatterns = [
path('', views.IndexView.as_view(), name='index')
path('', include(router.urls))
]

View File

@ -3,10 +3,31 @@ from django.http import HttpResponseRedirect
from django.views import generic
from django.urls import reverse
from django.utils import timezone
from rest_framework import status, viewsets
from .serializers import MigrationSerializer
from rest_framework.response import Response
from rest_framework.decorators import action
from .models import Migration
class MigrationViewSet(viewsets.ModelViewSet):
queryset = Migration.objects.all()
serializer_class = MigrationSerializer
# permission_classes = (AllowAny,)
@action(detail=False, methods=['GET'])
def upcoming(self, request, *args, **kwargs):
response = {"message": "this will be upcoming migrations"}
return Response(response, status=status.HTTP_200_OK)
@action(detail=False, methods=['GET'])
def missed(self, request, *args, **kwargs):
response = {"message": str(Migration.objects.filter(
booked_time__gte=timezone.now()).order_by('-booked_time')[:5])}
return Response(response, status=status.HTTP_200_OK)
class IndexView(generic.ListView):
template_name = 'api/index.html'
context_object_name = 'latest_migrations'

View File

@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
]
MIDDLEWARE = [