Ansätze werden angezeigt

master
Ulf Wagner 2 years ago
parent 6625813b71
commit b3c3774f35
  1. 34
      HaushaltDjangoProject/HaushaltDjangoProject/routers.py
  2. 29
      HaushaltDjangoProject/HaushaltDjangoProject/settings.py
  3. 37
      HaushaltDjangoProject/huel/migrations/0001_initial.py
  4. 28
      HaushaltDjangoProject/huel/models.py
  5. 98
      HaushaltDjangoProject/huel/templates/ansatz.html
  6. 18
      HaushaltDjangoProject/huel/templates/navigation.html
  7. 6
      HaushaltDjangoProject/huel/templates/structure.html
  8. 2
      HaushaltDjangoProject/huel/urls.py
  9. 33
      HaushaltDjangoProject/huel/views.py

@ -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

@ -15,7 +15,6 @@ from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
@ -27,7 +26,6 @@ DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
@ -71,17 +69,31 @@ TEMPLATES = [
WSGI_APPLICATION = 'HaushaltDjangoProject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
"""
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
"""
DATABASES = {
#"default": {},
"default": {
"NAME": "HUEL",
"ENGINE": "mssql",
"USER": "hhweb",
"PASSWORD": "1J5ZadE8Z1Y0jnoocXVw",
"HOST": "smwk-sql-2.smwk.sachsen.de",
"PORT": "1433",
"OPTIONS": {"driver": "ODBC Driver 18 for SQL Server",
'extra_params': "Encrypt=no;TrustServerCertificate=yes"
},
},
}
#DATABASE_ROUTERS = ["HaushaltDjangoProject.routers.SaxMBSRouter"]
# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
@ -101,11 +113,10 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'de-de'
TIME_ZONE = 'UTC'
@ -113,7 +124,6 @@ USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
@ -124,4 +134,5 @@ STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

@ -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 %}

@ -11,22 +11,12 @@
<a class="nav-link active" aria-current="page" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/planungsparameter/">Planungsparameter</a>
<a class="nav-link" href="/planungsparameter/">Übersicht</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Auswertung
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/mockup/tables/">Tabellen</a></li>
<li><a class="dropdown-item" href="#">Diagramme</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Export</a></li>
</ul>
<li class="nav-item">
<a class="nav-link" href="/ansatz_init/">Ansatz</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Pro Version Button</a>
</li>

@ -1,13 +1,13 @@
{% load i18n l10n static %}
<script src="{% static 'bootstrap/js/bootstrap.bundle.js' %}"></script>
{% csrf_token %}
<script src="{% static 'bootstrap/js/bootstrap.bundle.js' %}"></script>
<!DOCTYPE html>
<html lang="de">
<head>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, intial-scale=1.0">
<title>{% block title %}UGS Online{% endblock %}</title>
<title>{% block title %}Haushalt{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
</head>

@ -3,6 +3,8 @@ from . import views
urlpatterns = [
path('', views.index, name='huel_index'),
path('ansatz_init/', views.ansatz_init, name='huel_ansatz'),
path('ansatz_refresh/', views.ansatz_refresh, name='huel_ansatz'),
#path('planungsparameter/', views.planungsparameter, name='ugs_planungsparameter'),
# path('tables/',views.tables, name='ugstables'),
]

@ -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…
Cancel
Save