Skip to content
Snippets Groups Projects
Commit 4e7ef221 authored by Frank Poetzsch-Heffter's avatar Frank Poetzsch-Heffter
Browse files

account view, ModelChoiceField of costcenter, modify form layout

parent ab334628
No related branches found
No related tags found
No related merge requests found
from django.contrib import admin
from .models import Booking
from .models import Costcenter, Account, Booking
admin.site.register(Costcenter)
admin.site.register(Account)
admin.site.register(Booking)
......@@ -3,17 +3,47 @@ from django.core.exceptions import ValidationError
from django.utils import timezone
from datetime import datetime
from material import Layout, Row, Fieldset
from .models import Booking, Costcenter, SCHOOLYEARLIST
from .models import YEARLIST, Booking, Costcenter, Account
class EditBookingForm(forms.ModelForm):
description = forms.CharField(label='Beschreibung - Was soll gekauft werden?')
planned_amount = forms.IntegerField(label='Erwarteter Betrag - Welcher Betrag ist erforderlich (in Euro ohne Komma)?')
justification = forms.CharField(label='Begründung - Begründe ggf. deinen Antrag.', required=False)
layout = Layout(Row('description', 'planned_amount'), Row('justification'))
class Meta:
model = Booking
fields = ('id', 'description', 'planned_amount', 'justification')
class EditCostcenterForm(forms.ModelForm):
costcenter = forms.CharField(max_length=30, label='Kostenstelle')
schoolyear = forms.ChoiceField(choices=SCHOOLYEARLIST)
name = forms.CharField(max_length=30, label='Kostenstelle')
year = forms.ChoiceField(choices=YEARLIST, label='Jahr')
layout = Layout(Row(Fieldset('Kostenstelle', 'costcenter'), Fieldset('Schuljahr', 'schoolyear')))
layout = Layout(Row('name','year'))
class Meta:
model = Costcenter
fields = ('id', 'costcenter', 'schoolyear')
fields = ('id', 'name', 'year')
class EditAccountForm(forms.ModelForm):
costcenterlist = Costcenter.objects.filter()
costcenter_choices = [(x, val.name) for x, val in enumerate(costcenterlist)]
# print('choices:', costcenter_choices)
name = forms.CharField(max_length=30, label='Buchungskonto')
costcenter = forms.ModelChoiceField(queryset=costcenterlist, label='Kostenstelle')
print('costcenter:', costcenter)
budget = forms.IntegerField(label='Budget')
layout = Layout(Row('name', 'costcenter', 'budget'))
class Meta:
model = Account
fields = ('id', 'name', 'costcenter', 'budget')
#
......@@ -54,16 +84,3 @@ class EditCostcenterForm(forms.ModelForm):
# fields = ('cost_center', 'description', 'planned_amount')
class EditBookingForm(forms.ModelForm):
description = forms.CharField(label='Was soll gekauft werden?')
planned_amount = forms.IntegerField(label='Welcher Betrag ist dafür erforderlich (Euro)?')
justification = forms.CharField(label='Begründe ggf. deinen Antrag.', required=False)
layout = Layout(Row(Fieldset('Beschreibung', 'description'),
Fieldset('Erwarteter Betrag', 'planned_amount')),
Row(Fieldset('Begründung (optional)', 'justification')))
class Meta:
model = Booking
fields = ('id', 'description', 'planned_amount', 'justification')
from django.db import models
from django.contrib.auth.models import User
SCHOOLYEARLIST = ['2019/2020','2020/2021','2021/2022','2022/2023','2023/2024']
YEARLIST = [(2019,'2019'),
(2020,'2020'),
(2021,'2021'),
(2022,'2022'),
(2023,'2023')]
class Status:
def __init__(self, name, style_class):
......@@ -27,7 +31,10 @@ status_choices = [(x, val.name) for x, val in enumerate(status_list)]
class Costcenter(models.Model):
# Kostenstellen z.B. Schoolträger-konsumtiv, Schulträger-investiv, Elternberein, ...
name = models.CharField(max_length=20)
schoolyear = models.CharField(max_length=20)
year = models.IntegerField(default=2019, choices=YEARLIST, verbose_name="Jahr")
def __str__(self):
return self.name
class Meta:
permissions = (
('edit_costcenter', 'Can edit cost center'),
......@@ -35,16 +42,16 @@ class Costcenter(models.Model):
class Account(models.Model):
# Buchungskonten, z.B. Fachschaften, Sekretariat, Schulleiter, Kopieren, Tafelnutzung
name = models.CharField(max_length=20)
costcenter = models.ForeignKey(to=Costcenter, on_delete=models.CASCADE)
budget = models.DecimalField(max_digits=9, decimal_places=2)
name = models.CharField(max_length=20, default='')
costcenter = models.ForeignKey(to=Costcenter, on_delete=models.CASCADE, default='')
budget = models.DecimalField(max_digits=9, decimal_places=2, default=0.00)
class Meta:
permissions = (
('edit_account', 'Can edit account'),
)
class Booking(models.Model):
account = models.ForeignKey(to=Account, on_delete=models.SET_NULL, blank=True, null=True)
# account = models.ForeignKey(to=Account, on_delete=models.SET_NULL, blank=True, null=True)
contact = models.ForeignKey(to=User, related_name='bookings', on_delete=models.SET_NULL
, verbose_name="Erstellt von", blank=True, null=True)
# invoice_date = models.DateField()
......
{% include 'partials/header.html' %}
{% load material_form %}
<main>
<h4>Buchungskonto bearbeiten</h4>
<form method="POST">
{% csrf_token %}
{% form form=form %}
{% endform %}
<button type="submit" class="waves-effect waves-light btn green">
<i class="material-icons left">send</i> Änderungen übernehmen
</button>
<a href="{% url 'account' %}">
<button type="button" class="waves-effect waves-light btn grey">
<i class="material-icons left">cancel</i> Abbrechen
</button>
</a>
</form>
</main>
{% include 'partials/footer.html' %}
{% include 'partials/header.html' %}
{% load material_form %}
<main>
{# <a href="{% url 'fibu_make_booking' %}" class="waves-effect waves-light btn green">Neuen Antrag stellen</a>#}
{% block content %}
<h4>Buchungskonten</h4>
<form method="POST" style="border-width: 5px; background: #eee;">
{% csrf_token %}
{% form form=form %}
{% endform %}
<button type="submit" class="waves-effect waves-light btn green right">
<i class="material-icons left">send</i> Buchungskonto anlegen
</button>
</form>
<h4>Bestehende Buchungskonten</h4>
<div class="collection">
{% for account in accounts %}
<div class="collection-item row">
<span class="col s12 m6">{{ account.name }}</span>
<span class="col s12 m2 right-align">{{ account.costcenter }}</span>
<span class="col s12 m2 right-align">{{ account.budget }}</span>
<span class="col s12 m2 right-align">
<form action="{% url 'account_edit' account.id %}" class="left">
{% csrf_token %}
<input type="hidden" value="{{ account.id }}" name="account-id">
<button type="submit" name="edit"
class="waves-effect waves-light btn-flat btn-flat-medium" title="Bearbeiten">
<i class="material-icons center green-text">create</i>
</button>
</form>
<form action="" method="POST" class="left">
{% csrf_token %}
<input type="hidden" value="{{ account.id }}" name="account-id">
<button type="submit" onclick="return confirm('Wollen Sie das Buchungskonto wirklich löschen?')" name="cancel" class="waves-effect waves-light btn-flat btn-flat-medium" title="Löschen">
<i class="material-icons center red-text">cancel</i>
</button>
</form>
</span>
</div>
{% endfor %}
</div>
{% endblock %}
</main>
{% include 'partials/footer.html' %}
{% include 'partials/header.html' %}
{% load material_form %}
<main>
<h4>Kostenstelle bearbeiten</h4>
<form method="POST">
{% csrf_token %}
{% form form=form %}
{% endform %}
<button type="submit" class="waves-effect waves-light btn green">
<i class="material-icons left">send</i> Änderungen übernehmen
</button>
<a href="{% url 'costcenter' %}">
<button type="button" class="waves-effect waves-light btn grey">
<i class="material-icons left">cancel</i> Abbrechen
</button>
</a>
</form>
</main>
{% include 'partials/footer.html' %}
......@@ -8,11 +8,11 @@
{% block content %}
<h4>Kostenstellen</h4>
<form method="POST" style="border-width: 5px;">
<form method="POST" style="border-width: 5px; background: #eee;">
{% csrf_token %}
{% form form=form %}
{% endform %}
<button type="submit" class="waves-effect waves-light btn green">
<button type="submit" class="waves-effect waves-light btn green right">
<i class="material-icons left">send</i> Kostenstelle anlegen
</button>
</form>
......@@ -22,7 +22,7 @@
{% for costcenter in costcenterlist %}
<div class="collection-item row">
<span class="col s12 m8">{{ costcenter.name }}</span>
<span class="col s12 m2 right-align">{{ costcenter.schoolyear }}</span>
<span class="col s12 m2 right-align">{{ costcenter.year }}</span>
<span class="col s12 m2 right-align">
<form action="{% url 'costcenter_edit' costcenter.id %}" class="left">
{% csrf_token %}
......
......@@ -8,11 +8,11 @@
{% block content %}
<h4>Beantragungen von {{ user }}</h4>
<form method="POST" style="border-width: 5px;">
<form method="POST" style="border-width: 5px; background: #eee">
{% csrf_token %}
{% form form=form %}
{% endform %}
<button type="submit" class="waves-effect waves-light btn green">
<button type="submit" class="waves-effect waves-light btn green right">
<i class="material-icons left">send</i> Antrag stellen
</button>
</form>
......
......@@ -5,8 +5,11 @@ from . import views
urlpatterns = [
path('', views.index, name='fibu_index'),
path('check', views.check, name='booking_check'),
path('costcenter', views.costcenter, name='costcenter'),
path('edit/<int:id>', views.edit, name='booking_edit'),
path('costcenter', views.costcenter, name='costcenter'),
path('costcenter/edit/<int:id>', views.costcenter_edit, name='costcenter_edit'),
path('account', views.account, name='account'),
path('account/edit/<int:id>', views.account_edit, name='account_edit'),
# path('make_booking', views.make_booking, name='fibu_make_booking'),
# path('edit/<int:id>', views.edit, name='booking_edit'),
]
from django.contrib.auth.decorators import login_required, permission_required
from django.urls import reverse
from django.shortcuts import render, redirect, get_object_or_404
from .models import Booking, Costcenter
from .models import Booking, Costcenter, Account
from .filters import BookingFilter
from .forms import EditBookingForm, EditCostcenterForm
from .forms import EditBookingForm, EditCostcenterForm, EditAccountForm
@login_required
......@@ -35,11 +35,10 @@ def index(request):
else:
form = EditBookingForm()
if form.is_valid():
account = ''
description = form.cleaned_data['description']
planned_amount = form.cleaned_data['planned_amount']
justification = form.cleaned_data['justification']
booking = Booking(account=account, description=description, planned_amount=planned_amount, contact=request.user, justification=justification)
booking = Booking(description=description, planned_amount=planned_amount, contact=request.user, justification=justification)
booking.save()
# a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt",
......@@ -102,7 +101,7 @@ def check(request):
booking_list = Booking.objects.filter(status=0).order_by('submission_date')
bookings = BookingFilter(request.GET, queryset=booking_list)
return render(request, 'fibu/check.html', {'filter': bookings})
return render(request, 'fibu/booking/check.html', {'filter': bookings})
@login_required
......@@ -129,8 +128,8 @@ def costcenter(request):
form = EditCostcenterForm()
if form.is_valid():
name = form.cleaned_data['name']
schoolyear = form.cleaned_data['schoolyear']
costcenter = Costcenter(name=name, schoolyear=schoolyear)
year = form.cleaned_data['year']
costcenter = Costcenter(name=name, year=year)
costcenter.save()
# a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt",
......@@ -140,6 +139,91 @@ def costcenter(request):
# a.save()
# return redirect('fibu_make_booking')
return redirect('costcenter')
costcenter = Costcenter.objects.filter()
context = {'costcenter': costcenter, 'form': form}
return render(request, 'fibu/costcenter.html', context)
costcenterlist = Costcenter.objects.filter()
context = {'costcenterlist': costcenterlist, 'form': form}
return render(request, 'fibu/costcenter/index.html', context)
@login_required
# @permission_required('aub.apply_for_aub')
def costcenter_edit(request, id):
costcenter = get_object_or_404(Costcenter, id=id)
form = EditCostcenterForm(instance=costcenter)
template = 'fibu/costcenter/edit.html'
if request.method == 'POST':
form = EditCostcenterForm(request.POST, instance=costcenter)
print('\n\n\nBLUBB', form)
if form.is_valid():
form.save()
# a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung verändert",
# description="Sie haben Ihren Antrag auf Unterrichtsbefreiung " +
# "für den Zeitraum von {} bis {} bearbeitet.".format(
# aub.from_date, aub.to_date), app=AubConfig.verbose_name)
# a.save()
return redirect(reverse('costcenter'))
context = {'form': form}
return render(request, template, context)
@login_required
#@permission_required('fibu.view_booking')
def account(request):
if request.method == 'POST':
if 'account-id' in request.POST:
account_id = request.POST['account-id']
account = Account.objects.get(id=account_id)
if 'cancel' in request.POST:
account.delete()
# a = Activity(user=aub_user, title="Antrag auf Unterrichtsbefreiung gelöscht",
# description="Sie haben Ihren Antrag auf Unterrichtsbefreiung " +
# "für den Zeitraum von {} bis {} gelöscht.".format(
# aub.from_date, aub.to_date), app=AubConfig.verbose_name)
# a.save()
print('Eintrag gelöscht')
return redirect('account')
print('Edit-Form erstellt ############# form.is_valid:', form.is_valid())
form = EditAccountForm(instance=account)
else:
form = EditAccountForm(request.POST or None)
else:
form = EditAccountForm()
if form.is_valid():
name = form.cleaned_data['name']
costcenter = form.cleaned_data['costcenter']
budget = form.cleaned_data['budget']
account = Account(name=name, costcenter=costcenter, budget=budget)
account.save()
# a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt",
# description="Sie haben einen Antrag auf Unterrichtsbefreiung " +
# "für den Zeitraum von {} bis {} gestellt.".format(
# aub.from_date, aub.to_date), app=AubConfig.verbose_name)
# a.save()
# return redirect('fibu_make_booking')
return redirect('account')
accounts = Account.objects.filter()
context = {'accounts': accounts, 'form': form}
return render(request, 'fibu/account/index.html', context)
@login_required
# @permission_required('aub.apply_for_aub')
def account_edit(request, id):
account = get_object_or_404(Account, id=id)
form = EditAccountForm(instance=account)
template = 'fibu/account/edit.html'
if request.method == 'POST':
form = EditAccountForm(request.POST, instance=account)
print('\n\n\nBLUBB', form)
if form.is_valid():
form.save()
# a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung verändert",
# description="Sie haben Ihren Antrag auf Unterrichtsbefreiung " +
# "für den Zeitraum von {} bis {} bearbeitet.".format(
# aub.from_date, aub.to_date), app=AubConfig.verbose_name)
# a.save()
return redirect(reverse('account'))
context = {'form': form}
return render(request, template, context)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment