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

check template

parent 5f8a5108
No related merge requests found
from django.contrib.auth.models import User
import django_filters
from .models import Booking
from django.db.utils import ProgrammingError
def get_fibu_users():
""" Find all users who sends an AUB """
try:
fibu_users = Booking.objects.values_list('contact')
users = list(User.objects.filter(id__in=fibu_users))
# user_ids = [(str(user.id),user.username) for user in users]
user_ids = [(str(user.id), user.last_name + ', ' + user.first_name) for user in users]
user_ids_sorted = sorted(user_ids, key=lambda user: user[1])
return user_ids_sorted
except ProgrammingError:
return []
class BookingFilter(django_filters.FilterSet):
contact = django_filters.ChoiceFilter(label='Von', choices=get_fibu_users())
class Meta:
model = Booking
fields = ['contact', ]
......@@ -50,7 +50,7 @@ class Booking(models.Model):
description = models.CharField(max_length=50)
# amount = models.DecimalField(max_digits=10, decimal_places=2)
planned_amount = models.IntegerField()
# submission_date = models.DateField()
submission_date = models.DateField(default='2019-01-01')
# payout_number = models.IntegerField()
# booking_date = models.DateField()
# maturity = models.DateField()
......
{% include 'partials/header.html' %}
<main>
<h4>Anträge prüfen</h4>
<table class="highlight">
<thead>
<tr>
<th>Beschreibung</th>
<th class="flushright">Erwarteter Betrag</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for booking in filter.qs %}
<tr>
<td>{{ booking.description }}</td>
<td class="flushright">{{ booking.planned_amount }} €</td>
<td><span class="badge new {{ booking.getStatus.style_class }}">{{ booking.getStatus.name }}</span></td>
<td>
<form action="" method="POST" class="right">
{% csrf_token %}
<input type="hidden" value="{{ booking.id }}" name="aub-id">
{% if booking.status.id != 2 %}
<button type="submit" name="allow"
class="waves-effect waves-light btn-flat btn-flat-large" title="Annehmen">
<i class="material-icons center green-text">check_circle</i>
</button>
{% endif %}
{% if booking.status.id != 3 %}
<button type="submit" name="deny"
class="waves-effect waves-light btn-flat btn-flat-large" title="Ablehnen">
<i class="material-icons center red-text">not_interested</i>
</button>
{% endif %}
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</main>
{% include 'partials/footer.html' %}
......@@ -36,7 +36,6 @@
{% endfor %}
</tbody>
</table>
<ul class="collection">
{% endblock %}
</main>
{% include 'partials/footer.html' %}
......@@ -4,6 +4,7 @@ from . import views
urlpatterns = [
path('', views.index, name='fibu_index'),
path('check', views.check, name='booking_check'),
# 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.shortcuts import render, redirect, get_object_or_404
from .models import Booking
from .filters import BookingFilter
from .forms import MakeBookingForm
......@@ -38,3 +39,34 @@ def index(request):
return redirect('fibu_index')
context = {'bookings': items, 'form': form}
return render(request, 'fibu/index.html', context)
@login_required
# @permission_required('fibu.check_booking')
def check(request):
if request.method == 'POST':
if 'booking-id' in request.POST:
booking_id = request.POST['booking-id']
booking = Booking.objects.get(id=booking_id)
if 'allow' in request.POST:
Booking.objects.filter(id=booking_id).update(status=1)
elif 'deny' in request.POST:
Booking.objects.filter(id=booking_id).update(status=3)
# Notify user
# register_notification(title="Ihr Antrag auf Unterrichtsbefreiung wurde abgelehnt",
# description="Ihr Antrag auf Unterrichtsbefreiung vom {}, {} Uhr bis {}, {} Uhr wurde von der "
# "Schulleitung abgelehnt. Für weitere Informationen kontaktieren Sie "
# "bitte die Schulleitung."
# .format(formats.date_format(aub.from_date),
# formats.time_format(aub.from_time),
# formats.date_format(aub.to_date),
# formats.time_format(aub.to_time)),
# app=AubConfig.verbose_name, user=aub.created_by,
# link=request.build_absolute_uri(reverse('aub_details', args=[aub.id]))
# )
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})
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