This commit is contained in:
Peter Kotyczka 2024-04-04 09:10:54 +02:00
parent 6b14ddcd0a
commit df108da80b
20 changed files with 21 additions and 109 deletions

View File

@ -8,9 +8,9 @@ source virtualenv/bin/activate
#### Install django
python3 -m pip install django
## Start the project
django-admin startproject demo
django-admin startproject pyapp
## install an app
python3 manage.py startapp migration
python3 manage.py startapp pyapp
python3 manage.py createsuperuser
python3 manage.py migrate

View File

@ -1,6 +1,6 @@
from django.apps import AppConfig
class MigrationConfig(AppConfig):
class PyappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'pyapp'

View File

@ -37,7 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'migration',
'pyapp',
]
MIDDLEWARE = [

View File

@ -1,28 +0,0 @@
version: "2.4"
services:
artemis:
image: docker.kotyczka.ch/artemis-adoptopenjdk-11 ##apache/activemq-artemis
platform: linux/amd64
container_name: amq-arte
restart: unless-stopped
environment:
- ARTEMIS_USER=smx
- ARTEMIS_PASSWORD=smx
- ARTEMIS_MIN_MEMORY=1512M
- ARTEMIS_MAX_MEMORY=3024M
volumes:
- "./artemis-data:/var/lib/artemis-instance/data:rw"
ports:
- 8161:8161
- 61613:61616
- 5672:5672
mem_limit: 512m
mem_reservation: 256m
networks:
- ametiq
volumes:
artemis-data:
networks:
ametiq:
external: true

View File

@ -37,7 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'migration',
'pyapp',
]
MIDDLEWARE = [

View File

@ -16,12 +16,12 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path,include
from migration.views import migration_home
from migration.views import api_home
from pyapp.views import pyapp_home
from pyapp.views import api_home
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("migration.urls")),
path('migration/', migration_home),
path('', include("pyapp.urls")),
path('pyapp/', pyapp_home),
path('api/', api_home),
]

View File

@ -1,5 +1,5 @@
from django.contrib import admin
from migration.models import ShoppingItem
from pyapp.models import ShoppingItem
# Register your models here.
admin.site.register(ShoppingItem)

View File

@ -1,6 +1,6 @@
from django.apps import AppConfig
class MigrationConfig(AppConfig):
class PyappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'migration'
name = 'pyapp'

View File

@ -1,60 +0,0 @@
<html>
<head>
<title>Migration</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" rel="stylesheet">
<style>
header {
background-color: green;
display: flex;
padding-left: 20px;
}
body {
font-family: 'Open Sans', sans-serif;
background-color: white;
}
button {
height: 40px;
width: 40 px;
border-radius: 50%;
}
.list-item {
font-size: 32 px;
background-color: white;
height: 30px;
box-shadow: 2px 2px 2px rgba(0,0,0,0.01);
display: flex;
align-items: center;
}
</style>
</head>
<body>
<header>
<h1>Migration Apis</h1>
</header>
{% for item in all_items %}
<div class="list-item">
<input type="checkbox"> {{item.name}}
</div>
{% endfor %}
<button onclick="addItem()">+</button>
<script>
function addItem() {
let itemName = prompt('Neues Element hinzufügen');
let token = '{{csrf_token}}';
let formData = new FormData();
formData.append('itemName',itemName);
formData.append('csrfmiddlewaretoken',token);
fetch('/migration/', {
method: 'POST',
body: formData
});
window.location.reload();
}
</script>
</body>
</html>

View File

@ -1,8 +1,8 @@
from django.urls import path
from migration import views
from pyapp import views
urlpatterns = [
path("", views.index, name= "index"),
path("", views.migration_home, name= "migration"),
path("", views.pyapp_home, name= "pyapp"),
path("", views.api_home, name= "api"),
]

View File

@ -1,22 +1,22 @@
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from migration.models import ShoppingItem
from pyapp.models import ShoppingItem
from rest_framework import viewsets
from migration.serializers import ShoppingItemSerializer
from pyapp.serializers import ShoppingItemSerializer
class ShoppingItemViewSet(viewsets.ModelViewSet):
queryset = ShoppingItem.objects.all()
serializer_class = ShoppingItemSerializer
def index(response):
return HttpResponse("Welcome to siMed Migration")
return HttpResponse("Welcome to PyApp")
def migration_home(request):
def pyapp_home(request):
if request.method == 'POST':
print('Received Data',request.POST['itemName'])
ShoppingItem.objects.create(name= request.POST['itemName'])
all_items = ShoppingItem.objects.all()
return render(request,'migration.html',{'all_items': all_items})
return render(request,'pyapp.html',{'all_items': all_items})
def api_home(request,endpoint, params={"message": "Your JSON Repsonse"}):
body = request.body

View File

@ -13,8 +13,8 @@ services:
# HTTP management UI
- '15672:15672'
volumes:
- ./demo/migration/queue/data/:/var/lib/rabbitmq/
- ./demo/migration/queue/log/:/var/log/rabbitmq/
- ./demo/pyapp/queue/data/:/var/lib/rabbitmq/
- ./demo/pyapp/queue/log/:/var/log/rabbitmq/
networks:
- ametiq
networks: