parent
6625813b71
commit
b3c3774f35
9 changed files with 257 additions and 28 deletions
@ -0,0 +1,34 @@ |
||||
class SaxMBSRouter: |
||||
route_app_labels = {"SaxMBS"} |
||||
|
||||
def db_for_read(self, model, **hints): |
||||
""" Liest Daten aus SaxMBS""" |
||||
if model._meta.app_label in self.route_app_labels: |
||||
return 'saxmbs' |
||||
return 'saxmbs' |
||||
|
||||
def db_for_write(self, model, **hints): |
||||
""" In SaxNBS darf nicht geschrieben werden""" |
||||
if model._meta.app_label in self.route_app_labels: |
||||
return None |
||||
return None |
||||
|
||||
def allow_relation(self, obj1, obj2, **hints): |
||||
""" |
||||
Allow relations if a model in the auth or contenttypes apps is |
||||
involved. |
||||
""" |
||||
if ( |
||||
obj1._meta.app_label in self.route_app_labels |
||||
or obj2._meta.app_label in self.route_app_labels |
||||
): |
||||
return True |
||||
return None |
||||
|
||||
def allow_migrate(self, db, app_label, model_name=None, **hints): |
||||
""" |
||||
SaxMBS darf nicht verändert werden |
||||
""" |
||||
if app_label in self.route_app_labels: |
||||
return None |
||||
return None |
||||
@ -0,0 +1,37 @@ |
||||
# Generated by Django 4.1.2 on 2024-04-30 07:21 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
initial = True |
||||
|
||||
dependencies = [ |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='Ansatz', |
||||
fields=[ |
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('Titel', models.TextField()), |
||||
('Betrag', models.TextField()), |
||||
('Grund', models.TextField()), |
||||
('Datum', models.TextField()), |
||||
('Art', models.TextField()), |
||||
], |
||||
options={ |
||||
'db_table': 'Ansatz_View', |
||||
'managed': False, |
||||
}, |
||||
), |
||||
migrations.CreateModel( |
||||
name='Test', |
||||
fields=[ |
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('Titel', models.TextField()), |
||||
('Betrag', models.DecimalField(decimal_places=2, max_digits=15)), |
||||
], |
||||
), |
||||
] |
||||
@ -1,3 +1,29 @@ |
||||
from django.db import models |
||||
|
||||
# Create your models here. |
||||
|
||||
class Ansatz(models.Model): |
||||
class Meta: |
||||
# app_label: str = models.CharField(max_length=200, default="HUEL") |
||||
managed = False |
||||
db_table = 'Ansatz_View' |
||||
id = models.BigAutoField(primary_key=True) |
||||
Kapitel = models.CharField(max_length=4) |
||||
Titel = models.CharField(max_length=5) |
||||
Betrag = models.DecimalField(max_digits=15, decimal_places=2,blank=True, null=True) |
||||
Grund = models.TextField(blank=True, null=True) |
||||
Datum = models.DateField(blank=True, null=True) |
||||
Art = models.TextField(blank=True, null=True) |
||||
HHJ = models.CharField(max_length=4,blank=True, null=True) |
||||
|
||||
def __str__(self): |
||||
return self.Titel |
||||
|
||||
|
||||
class Test(models.Model): |
||||
#class Meta: |
||||
# app_label: str = models.CharField(max_length=200, default="HUEL") |
||||
Titel = models.TextField() |
||||
Betrag = models.DecimalField(max_digits=15, decimal_places=2) |
||||
|
||||
def __str__(self): |
||||
return self.Titel |
||||
|
||||
@ -0,0 +1,98 @@ |
||||
{% extends 'structure.html' %} |
||||
{% block content %} |
||||
Momentan ist nur TG 99 sichtbar. Filter im View eingebaut |
||||
<form id="selections"> |
||||
<select class="form-select" aria-label="Jahrauswahl" name ="HHJ" id="HHJ"> |
||||
<option selected>Jahr auswählen</option> |
||||
{% for j in alle_jahre %} |
||||
<option> {{ j.HHJ }} </option> |
||||
{% endfor %} |
||||
</select> |
||||
<select class="form-select" aria-label="Kapitelauswahl" name ="Kapitel" id="Kapitel"> |
||||
<option selected>Kapitel auswählen</option> |
||||
{% for k in alle_kapitel %} |
||||
<option> {{ k.Kapitel }} </option> |
||||
{% endfor %} |
||||
</select> |
||||
</form> |
||||
<table class="table table-striped"> |
||||
<thead> |
||||
<tr> |
||||
<th scope="col">Kapitel</th> |
||||
<th scope="col">Titel</th> |
||||
<th scope="col">Datum</th> |
||||
<th scope="col">Grund</th> |
||||
<th scope="col" class="text-sm-end">Betrag</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody id="tablebody"> |
||||
{% for x in alle_ansatz %} |
||||
<tr> |
||||
<td>{{ x.Kapitel }} </td> |
||||
<td>{{ x.Titel }} </td> |
||||
<td>{{ x.Datum|date:"d.m.Y" }} </td> |
||||
<td>{{ x.Grund }} </td> |
||||
<td class="text-sm-end">{{ x.Betrag }} €</td> |
||||
</tr> |
||||
{% endfor %} |
||||
</tbody> |
||||
</table> |
||||
<script type="application/javascript"> |
||||
const form = document.getElementById("selections"); |
||||
console.log("Test"); |
||||
form.addEventListener("change", function (e) { |
||||
e.preventDefault() |
||||
const payload = new FormData(form); |
||||
let responseClone; |
||||
fetch('/ansatz_refresh/', { |
||||
method: "POST", |
||||
body: payload, |
||||
headers: { "X-CSRFToken": '{{csrf_token}}' } // "fetch" liefert den CSRF Token nicht automatisch |
||||
}).then(response=> { |
||||
responseClone = response.clone(); |
||||
return response.json(); |
||||
}).then(rows=> { |
||||
const tablebody = document.getElementById("tablebody"); |
||||
let innerHTML = "" |
||||
Object.keys(rows).forEach(key => { |
||||
console.log(`${key}: ${rows[key]}`); |
||||
if (rows[key] === null ) { |
||||
rows[key] = ""; |
||||
} |
||||
}); |
||||
rows.forEach((row) => { |
||||
innerHTML+= "<tr>" |
||||
innerHTML+= `<td> ${row.Kapitel} </td>` |
||||
innerHTML+= `<td> ${row.Titel} </td>` |
||||
innerHTML+= `<td> ` |
||||
if (row.Datum === null) |
||||
innerHTML+= `</td>` |
||||
else |
||||
innerHTML+= ` ${row.Datum} </td>` |
||||
innerHTML+= `<td> ` |
||||
if (row.Grund === null) |
||||
innerHTML+= `</td>` |
||||
else |
||||
innerHTML+= ` ${row.Grund} </td>` |
||||
innerHTML+= `<td class="text-sm-end"> ` |
||||
if (row.Betrag === null) |
||||
innerHTML+= `</td>` |
||||
else |
||||
innerHTML+= ` ${row.Betrag} €</td>` |
||||
innerHTML+= "</tr>" |
||||
|
||||
}); |
||||
tablebody.innerHTML=innerHTML; |
||||
|
||||
}).catch(rejectionReason=> { |
||||
console.log('Error parsing JSON from response:', rejectionReason, responseClone); |
||||
responseClone.text() |
||||
.then(bodyText=> { |
||||
console.log('Received the following instead of valid JSON:', bodyText); |
||||
}) |
||||
}) |
||||
} |
||||
) |
||||
</script> |
||||
|
||||
{% endblock content %} |
||||
@ -1,5 +1,36 @@ |
||||
import json |
||||
|
||||
from django.core.serializers import serialize |
||||
from django.core.serializers.json import DjangoJSONEncoder |
||||
from django.http import JsonResponse |
||||
from django.shortcuts import render |
||||
|
||||
from .models import Ansatz, Test |
||||
|
||||
|
||||
# Create your views here. |
||||
def index(request): |
||||
return render(request, 'home.html') |
||||
return render(request, 'home.html') |
||||
|
||||
|
||||
def ansatz_init(request): |
||||
alle_ansatz = Ansatz.objects.filter(Kapitel="") |
||||
alle_jahre = Ansatz.objects.order_by('HHJ').values('HHJ').distinct() |
||||
alle_kapitel = Ansatz.objects.order_by('Kapitel').values('Kapitel').distinct() |
||||
alle_titel = Ansatz.objects.order_by('Titel').values('Titel').distinct() |
||||
context = { |
||||
'alle_ansatz': alle_ansatz, |
||||
'alle_jahre': alle_jahre, |
||||
'alle_kapitel': alle_kapitel, |
||||
'alle_titel': alle_titel |
||||
} |
||||
return render(request, 'ansatz.html', context) |
||||
|
||||
|
||||
def ansatz_refresh(request): |
||||
kapitel = request.POST['Kapitel'] |
||||
hhj = request.POST['HHJ'] |
||||
alle_ansatz = Ansatz.objects.filter(Kapitel=kapitel,HHJ=hhj,Titel__endswith="99").values() |
||||
liste = list(alle_ansatz) |
||||
return JsonResponse(liste, DjangoJSONEncoder,safe=False) |
||||
|
||||
|
||||
Loading…
Reference in new issue