init repo

This commit is contained in:
2023-09-16 10:48:47 +02:00
commit bf365b1204
30 changed files with 697 additions and 0 deletions
View File
+3
View File
@@ -0,0 +1,3 @@
# from django.contrib import admin
# Register your models here.
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class DeploymentConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "deployment"
+11
View File
@@ -0,0 +1,11 @@
from django import forms
from deployment.models import Type
class DeploymentForm(forms.Form):
name = forms.CharField()
type = forms.ChoiceField(
required=True,
choices=Type.into_choices(),
)
+46
View File
@@ -0,0 +1,46 @@
# Generated by Django 4.2 on 2023-09-15 08:14
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="Deployment",
fields=[
(
"id",
models.UUIDField(
default=uuid.UUID("d7e9833f-e912-4640-8bf0-19e114a1136f"),
primary_key=True,
serialize=False,
),
),
("name", models.TextField()),
(
"type",
models.CharField(
choices=[("S", "Light"), ("M", "Medium"), ("L", "Heavy")],
default="S",
max_length=1,
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
@@ -0,0 +1,36 @@
# Generated by Django 4.2 on 2023-09-15 08:31
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
("deployment", "0001_initial"),
]
operations = [
migrations.AddField(
model_name="deployment",
name="status",
field=models.CharField(
choices=[
("PENDING", "Pending"),
("RUNNING", "Running"),
("SUCCESS", "Success"),
("FAILED", "Failed"),
],
default="PENDING",
max_length=7,
),
),
migrations.AlterField(
model_name="deployment",
name="id",
field=models.UUIDField(
default=uuid.UUID("7909f7f2-0ee4-45f6-b8d4-beb5df8efc73"),
primary_key=True,
serialize=False,
),
),
]
@@ -0,0 +1,24 @@
# Generated by Django 4.2.5 on 2023-09-16 08:16
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('deployment', '0002_deployment_status_alter_deployment_id'),
]
operations = [
migrations.AlterField(
model_name='deployment',
name='id',
field=models.UUIDField(default=uuid.UUID('8584555b-51ea-46a4-aebc-f7a8ab8670a4'), primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='deployment',
name='status',
field=models.CharField(choices=[('READY', 'Ready'), ('PENDING', 'Pending'), ('RUNNING', 'Running'), ('SUCCESS', 'Success'), ('FAILED', 'Failed')], default='READY', max_length=7),
),
]
@@ -0,0 +1,47 @@
# Generated by Django 4.2.5 on 2023-09-16 08:43
import deployment.models
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
("deployment", "0003_alter_deployment_id_alter_deployment_status"),
]
operations = [
migrations.AlterField(
model_name="deployment",
name="id",
field=models.UUIDField(
default=uuid.UUID("d29e958f-7b3d-43a8-bc17-a40ab4184dc6"),
primary_key=True,
serialize=False,
),
),
migrations.AlterField(
model_name="deployment",
name="status",
field=models.CharField(
choices=[
("READY", "Ready"),
("PENDING", "Pending"),
("RUNNING", "Running"),
("SUCCESS", "Success"),
("FAILED", "Failed"),
],
default=deployment.models.Status["READY"],
max_length=7,
),
),
migrations.AlterField(
model_name="deployment",
name="type",
field=models.CharField(
choices=[("SLIM", "Slim"), ("MEDIUM", "Medium"), ("LARGE", "Large")],
default=deployment.models.Type["SLIM"],
max_length=6,
),
),
]
@@ -0,0 +1,22 @@
# Generated by Django 4.2.5 on 2023-09-16 08:43
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
("deployment", "0004_alter_deployment_id_alter_deployment_status_and_more"),
]
operations = [
migrations.AlterField(
model_name="deployment",
name="id",
field=models.UUIDField(
default=uuid.UUID("ec7ebcb5-420a-47c3-ba07-e8c340895865"),
primary_key=True,
serialize=False,
),
),
]
@@ -0,0 +1,46 @@
# Generated by Django 4.2.5 on 2023-09-16 08:45
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
("deployment", "0005_alter_deployment_id"),
]
operations = [
migrations.AlterField(
model_name="deployment",
name="id",
field=models.UUIDField(
default=uuid.UUID("b8feb7aa-9c79-478b-ba91-df2e03f4145b"),
primary_key=True,
serialize=False,
),
),
migrations.AlterField(
model_name="deployment",
name="status",
field=models.CharField(
choices=[
("READY", "Ready"),
("PENDING", "Pending"),
("RUNNING", "Running"),
("SUCCESS", "Success"),
("FAILED", "Failed"),
],
default="Ready",
max_length=7,
),
),
migrations.AlterField(
model_name="deployment",
name="type",
field=models.CharField(
choices=[("SLIM", "Slim"), ("MEDIUM", "Medium"), ("LARGE", "Large")],
default="Slim",
max_length=6,
),
),
]
View File
+43
View File
@@ -0,0 +1,43 @@
from enum import Enum
from uuid import uuid4
from django.contrib.auth.models import User
from django.db import models
class Type(Enum):
SLIM = "Slim"
MEDIUM = "Medium"
LARGE = "Large"
@classmethod
def into_choices(cls):
return [(s.name, s.value) for s in cls]
class Status(Enum):
READY = "Ready"
PENDING = "Pending"
RUNNING = "Running"
SUCCESS = "Success"
FAILED = "Failed"
@classmethod
def into_choices(cls):
return [(s.name, s.value) for s in cls]
class Deployment(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4())
name = models.TextField(null=False, blank=False)
type = models.CharField(
max_length=6, choices=Type.into_choices(), default=Type.SLIM.value
)
status = models.CharField(
max_length=7, choices=Status.into_choices(), default=Status.READY.value
)
user = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return f"{self.name} | {self.type} | {self.status}"
+3
View File
@@ -0,0 +1,3 @@
# from django.test import TestCase
# Create your tests here.
+8
View File
@@ -0,0 +1,8 @@
from django.urls import path
from deployment.views import index, create, details
urlpatterns = [
path("", index, name="deployment"),
path("create", create, name="deployment-create"),
path("<uuid:deployment_id>", details, name="deployment-details"),
]
+55
View File
@@ -0,0 +1,55 @@
from uuid import uuid4
from django.core.paginator import Paginator
from django.http import (
HttpResponseRedirect,
HttpResponseServerError,
HttpResponseBadRequest,
)
from django.shortcuts import render, get_object_or_404
from deployment.forms import DeploymentForm
from deployment.models import Deployment
def index(request):
deployments = Deployment.objects.filter(user=request.user.id)
paginator = Paginator(deployments, 5)
page_number = request.GET.get("page")
page_obj = paginator.get_page(page_number)
return render(request, "deployment/board.html", {"page_obj": page_obj})
def details(request, deployment_id):
deployment = get_object_or_404(Deployment, id=deployment_id)
if request.method == "POST":
if deployment.status == deployment.RUNNING:
return HttpResponseBadRequest("deployment is running")
try:
deployment.delete()
except Exception as e:
return HttpResponseServerError(e)
return HttpResponseRedirect("/deployment")
deployment = get_object_or_404(Deployment, id=deployment_id)
return render(request, "deployment/details.html", {"deployment": deployment})
def create(request):
if request.method == "POST":
form = DeploymentForm(request.POST)
if form.is_valid():
try:
Deployment.objects.create(
user=request.user, id=uuid4(), **form.cleaned_data
)
except Exception as e:
return HttpResponseServerError(e)
return HttpResponseRedirect("/deployment")
else:
form = DeploymentForm
return render(request, "deployment/create.html", {"form": form})