Skip to content
Snippets Groups Projects
Commit a118c55a authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

- Redesign and refactor in FIBU

- Fix menu
- Add django's message system
parent 3414c471
No related branches found
No related tags found
No related merge requests found
......@@ -5,10 +5,10 @@ from material import Layout, Row, Fieldset
from .models import YEARLIST, Booking, Costcenter, Account, status_choices
class EditBookingForm(forms.ModelForm):
class BookingForm(forms.ModelForm):
description = forms.CharField(label='Beschreibung – Was soll angeschafft werden?')
planned_amount = forms.IntegerField(
label='Erwarteter Betrag – Welcher Betrag ist erforderlich (in Euro, ohne Komma)?')
label='Erwarteter Betrag – Welcher Betrag ist erforderlich?', help_text="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'))
......
......@@ -2,37 +2,46 @@
{% load material_form %}
<main>
{% block content %}
<h4>Anträge prüfen</h4>
{% for booking in filter.qs %}
<div class="row">
<form method="POST">
{% csrf_token %}
<input type="hidden" value="{{ booking.id }}" name="booking-id">
{% if booking.status < 2 %}
<span class="col s12 m1">{{ booking.contact }}</span>
<span class="col s12 m5">{{ booking.description }}</span>
<span class="col s12 m1">{{ booking.planned_amount }}</span>
<span class="col s12 m3">{{ form.account }}</span>
<span class="col s12 m1">
<button type="submit" name="allow"
class="waves-effect waves-light btn-flat btn-flat-medium" title="Annehmen">
<i class="material-icons right green-text">check_circle</i>
</button>
</span>
{% endif %}
{% if booking.status < 3 %}
<span class="col s12 m1">
<button type="submit" name="deny"
class="waves-effect waves-light btn-flat btn-flat-medium" title="Ablehnen">
<i class="material-icons right red-text">not_interested</i>
</button>
</span>
{% endif %}
</form>
</div>
{% endfor %}
{% endblock %}
</main>
{% for booking in filter.qs %}
<table>
<thead>
<tr>
<th>Antragsteller</th>
<th>Anschaffungswunsch</th>
<th>Geplante Kosten</th>
<th>Zugeordnete Kostenstelle</th>
<th>Aktionen</th>
</tr>
</thead>
<tr>
<form method="POST">
{% csrf_token %}
<input type="hidden" value="{{ booking.id }}" name="booking-id">
{% if booking.status < 2 %}
<td>{{ booking.contact }}</td>
<td>{{ booking.description }}</td>
<td>{{ booking.planned_amount }} €</td>
<td>{{ form.account }}</td>
{% endif %}
<td>
{% if booking.status < 2 %}
<button type="submit" name="allow"
class="waves-effect waves-light btn-flat btn-flat-medium" title="Annehmen">
<i class="material-icons center green-text">check_circle</i>
</button>
{% endif %}
{% if booking.status < 3 %}
<button type="submit" name="deny"
class="waves-effect waves-light btn-flat btn-flat-medium" title="Ablehnen">
<i class="material-icons center red-text">not_interested</i>
</button>
</td>
{% endif %}
</form>
</tr>
</table>
{% endfor %}
</main>
{% include 'partials/footer.html' %}
......@@ -2,66 +2,99 @@
{% load material_form %}
<main>
<a class="waves-effect waves-light btn green modal-trigger right" href="#new-modal">
<i class="material-icons left">add</i> Antrag stellen
</a>
<h4>Anträge von {{ user.get_fullname }}</h4>
{% block content %}
<h4>Beantragungen von {{ user }}</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> Antrag stellen
</button>
{% if form.errors %}
<script>
var onFinish = function () {
$("#new-modal").modal("open");
};
</script>
{% endif %}
<form method="POST">
<div id="new-modal" class="modal">
<div class="modal-content">
<h5>Neuen Antrag stellen</h5>
{% csrf_token %}
{% form form=form %}
{% part form.planned_amount prefix %}<i class="material-icons prefix">euro_symbol</i>
{% endpart %}
{% endform %} </div>
<div class="modal-footer">
<button type="submit" class="waves-effect waves-light btn green">
<i class="material-icons left">send</i> Antrag stellen
</button>
</div>
</div>
</form>
<h4>Laufende Anträge</h4>
<div class="collection">
{% for booking in bookings %}
<div class="collection-item row">
<span class="col s12 m7">{{ booking.description }}</span>
<span class="col s12 m1 right-align">{{ booking.planned_amount }} €</span>
<span class="col s12 m1 badge new center-align {{ booking.get_status.style_class }}">{{ booking.get_status.name }}</span>
<span class="col s12 m3">
{% if booking.status == 0 %}
<form action="{% url 'booking_edit' booking.id %}" class="left">
{% csrf_token %}
<input type="hidden" value="{{ booking.id }}" name="booking-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>
{% endif %}
<div class="collection">
{% for booking in bookings %}
<div class="collection-item row">
<div class="col s12 m7">{{ booking.description }}</div>
<span class="col s12 m1 right-align">{{ booking.planned_amount }} €</span>
<div class="col s12 m1">
<span class="badge new {{ booking.get_status.style_class }}">{{ booking.get_status.name }}</span>
</div>
<span class="col s12 m3">
{# Delete #}
{% if booking.status == 0 or booking.status == 1 %}
<form action="" method="POST" class="left">
<form action="" method="POST" class="right">
{% csrf_token %}
<input type="hidden" value="{{ booking.id }}" name="booking-id">
<button type="submit"
onclick="return confirm('Wollen Sie den Antrag wirklich zurücknehmen?')"
name="cancel" class="waves-effect waves-light btn-flat btn-flat-medium"
title="Antrag zurücknehmen">
<i class="material-icons center red-text">cancel</i>
</button>
</form>
{% endif %}
{# Edit #}
{% if booking.status == 0 %}
<form action="{% url 'booking_edit' booking.id %}" class="right">
{% csrf_token %}
<input type="hidden" value="{{ booking.id }}" name="booking-id">
<button type="submit" onclick="return confirm('Wollen Sie den Antrag 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>
<input type="hidden" value="{{ booking.id }}" name="booking-id">
<button type="submit" name="edit"
class="waves-effect waves-light btn-flat btn-flat-medium right"
title="Bearbeiten">
<i class="material-icons center green-text">create</i>
</button>
</form>
{% endif %}
<form action="" method="POST">
<form action="" method="POST" class="right">
{% csrf_token %}
<input type="hidden" value="{{ booking.id }}" name="booking-id">
<input type="hidden" value="{{ booking.status }}" name="booking-status">
{% if booking.status == 1 %}
<button type="submit" name="ordered"
class="waves-effect waves-light btn-flat btn-flat-medium left" title="Status auf 'bestellt' ändern">
<i class="material-icons center red-text">shopping_cart</i>
class="waves-effect waves-light btn-flat btn-flat-medium left"
title="Status auf 'bestellt' ändern">
<i class="material-icons center green-text">shopping_cart</i>
</button>
{% elif booking.status == 3 %}
<button type="submit" name="submit-invoice"
class="waves-effect waves-light btn-flat btn-flat-medium left" title="Status auf 'Rechnung eingereicht' ändern">
<i class="material-icons center red-text">description</i>
class="waves-effect waves-light btn-flat btn-flat-medium left"
title="Status auf 'Rechnung eingereicht' ändern">
<i class="material-icons center green-text">description</i>
</button>
{% endif %}
</form>
</span>
</div>
{% endfor %}
</div>
{% endblock %}
</span>
</div>
{% endfor %}
</div>
</main>
{% include 'partials/footer.html' %}
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import Sum
from django.urls import reverse
from django.shortcuts import render, redirect, get_object_or_404
from .models import Booking, Costcenter, Account
from .filters import BookingFilter
from .forms import EditBookingForm, CheckBookingForm, BookBookingForm, EditCostcenterForm, EditAccountForm
from .forms import BookingForm, CheckBookingForm, BookBookingForm, EditCostcenterForm, EditAccountForm
@login_required
@permission_required('fibu.request_booking')
def index(request):
fibu_user = request.user
if request.method == 'POST':
if 'booking-id' in request.POST:
booking_id = request.POST['booking-id']
booking = Booking.objects.get(id=booking_id)
booking = get_object_or_404(Booking, pk=booking_id)
if 'cancel' in request.POST:
booking.delete()
print('Eintrag gelöscht')
return redirect('fibu_index')
elif 'ordered' in request.POST:
Booking.objects.filter(id=booking_id).update(status=3)
return redirect('fibu_index')
elif 'submit-invoice' in request.POST:
Booking.objects.filter(id=booking_id).update(status=4)
return redirect('fibu_index')
print('Edit-Form erstellt ############# form.is_valid:', form.is_valid())
form = EditBookingForm(instance=booking)
form = BookingForm(instance=booking)
else:
form = EditBookingForm(request.POST or None)
form = BookingForm(request.POST)
else:
form = EditBookingForm()
form = BookingForm()
if form.is_valid():
description = form.cleaned_data['description']
planned_amount = form.cleaned_data['planned_amount']
......@@ -40,8 +43,11 @@ def index(request):
justification=justification)
booking.save()
messages.success(request, "Der Antrag wurde erfolgreich übermittelt.")
return redirect('fibu_index')
bookings = Booking.objects.filter(contact=fibu_user).order_by('status')
bookings = Booking.objects.filter(contact=request.user).order_by('status')
context = {'bookings': bookings, 'form': form}
return render(request, 'fibu/index.html', context)
......@@ -51,10 +57,10 @@ def index(request):
@permission_required('fibu.request_booking')
def edit(request, id):
booking = get_object_or_404(Booking, id=id)
form = EditBookingForm(instance=booking)
form = BookingForm(instance=booking)
template = 'fibu/booking/edit.html'
if request.method == 'POST':
form = EditBookingForm(request.POST, instance=booking)
form = BookingForm(request.POST, instance=booking)
if form.is_valid():
form.save()
......
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