diff --git a/biscuit/apps/fibu/forms.py b/biscuit/apps/fibu/forms.py index 75568d857326798a79c55bb24d10e0d8e846d01f..63c0ef34f1b7ed42d8c1977eb91564b6ddbde182 100644 --- a/biscuit/apps/fibu/forms.py +++ b/biscuit/apps/fibu/forms.py @@ -45,13 +45,16 @@ from .models import Booking, CostCenter # fields = ('cost_center', 'description', 'planned_amount') -class MakeBookingForm(forms.ModelForm): +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'))) + 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') + fields = ('id', 'description', 'planned_amount', 'justification') diff --git a/biscuit/apps/fibu/models.py b/biscuit/apps/fibu/models.py index f58ddaf26dde851a80525da2a2e023aedb41af8b..788e4c2732077800b225daa5d8aa75140f06d06c 100644 --- a/biscuit/apps/fibu/models.py +++ b/biscuit/apps/fibu/models.py @@ -51,6 +51,7 @@ class Booking(models.Model): # amount = models.DecimalField(max_digits=10, decimal_places=2) planned_amount = models.IntegerField() submission_date = models.DateField(default='2019-01-01') + justification = models.CharField(max_length=2000, blank=True, null=True) # payout_number = models.IntegerField() # booking_date = models.DateField() # maturity = models.DateField() diff --git a/biscuit/apps/fibu/templates/fibu/booking.html b/biscuit/apps/fibu/templates/fibu/edit.html similarity index 55% rename from biscuit/apps/fibu/templates/fibu/booking.html rename to biscuit/apps/fibu/templates/fibu/edit.html index 4d6f4a67edf8beb95df08204da145b70c4f8344e..d8a856d744847c3dd7e66db11da3a1519610db13 100644 --- a/biscuit/apps/fibu/templates/fibu/booking.html +++ b/biscuit/apps/fibu/templates/fibu/edit.html @@ -10,8 +10,13 @@ {% form form=form %} {% endform %} <button type="submit" class="waves-effect waves-light btn green"> - <i class="material-icons left">send</i> Antrag stellen + <i class="material-icons left">send</i> Änderungen übernehmen </button> + <a href="{% url 'fibu_index' %}"> + <button type="button" class="waves-effect waves-light btn grey"> + <i class="material-icons left">cancel</i> Abbrechen + </button> + </a> </form> </main> diff --git a/biscuit/apps/fibu/templates/fibu/index.html b/biscuit/apps/fibu/templates/fibu/index.html index 734dab3aedcfabd47b45374b10c40ba89551652c..764fd73be39c55256ffc39b2d6c2a1cbf763b5e5 100755 --- a/biscuit/apps/fibu/templates/fibu/index.html +++ b/biscuit/apps/fibu/templates/fibu/index.html @@ -18,24 +18,23 @@ </form> <h5>Laufende Anträge</h5> - <table class="highlight"> - <thead> - <tr> - <th>Beschreibung</th> - <th class="flushright">Erwarteter Betrag</th> - <th>Status</th> - </tr> - </thead> - <tbody> - {% for item in bookings %} - <tr> - <td>{{ item.description }}</td> - <td class="flushright">{{ item.planned_amount }} €</td> - <td><span class="badge new {{ item.getStatus.style_class }}">{{ item.getStatus.name }}</span></td> - </tr> - {% endfor %} - </tbody> - </table> + <div class="collection"> + {% for booking in bookings %} +{# <div class="collection-item row">#} + <a href="{% url 'booking_edit' booking.id %}" class="collection-item row"> + <span class="col s12 m8">{{ booking.description }}</span> + <span class="col s12 m3 flushright">{{ booking.planned_amount }} €</span> + <span class="col s12 m1 badge new {{ booking.getStatus.style_class }}">{{ booking.getStatus.name }}</span> +{# <form action="{% url 'booking_edit' booking.id %}" class="col s12 m2">#} +{# {% csrf_token %}#} +{# <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>#} + </a> +{# </div>#} + {% endfor %} + </div> {% endblock %} </main> {% include 'partials/footer.html' %} diff --git a/biscuit/apps/fibu/urls.py b/biscuit/apps/fibu/urls.py index a6e71761e11db4852ff6daba2fe85bd61cac9e01..5e6809b7d74862054298905a2d9665f3c2d2fa86 100755 --- a/biscuit/apps/fibu/urls.py +++ b/biscuit/apps/fibu/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path('check', views.check, name='booking_check'), path('check', views.check, name='booking_check1'), path('check', views.check, name='booking_check2'), + path('edit/<int:id>', views.edit, name='booking_edit'), # path('make_booking', views.make_booking, name='fibu_make_booking'), # path('edit/<int:id>', views.edit, name='booking_edit'), ] diff --git a/biscuit/apps/fibu/views.py b/biscuit/apps/fibu/views.py index a7e4c3483508de21a8521bd4e7a11511138fa234..0ab60cf3b55662dad5b2a3e848a5c11e5326ab55 100644 --- a/biscuit/apps/fibu/views.py +++ b/biscuit/apps/fibu/views.py @@ -1,15 +1,16 @@ 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 from .filters import BookingFilter -from .forms import MakeBookingForm +from .forms import EditBookingForm @login_required #@permission_required('fibu.view_booking') def index(request): - items = Booking.objects.filter() - print(items) + bookings = Booking.objects.filter() + print(bookings) # @login_required # @permission_required('fibu.make_booking') @@ -18,16 +19,17 @@ def index(request): if 'booking-id' in request.POST: booking_id = request.POST['booking-id'] booking = Booking.objects.get(id=booking_id) - form = MakeBookingForm(instance=booking) + form = EditBookingForm(instance=booking) print('Edit-Form erstellt ############# form.is_valid:', form.is_valid()) else: - form = MakeBookingForm(request.POST or None) + form = EditBookingForm(request.POST or None) else: - form = MakeBookingForm() + form = EditBookingForm() if form.is_valid(): description = form.cleaned_data['description'] planned_amount = form.cleaned_data['planned_amount'] - booking = Booking(description=description, planned_amount=planned_amount, contact=request.user) + justification = form.cleaned_data['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", @@ -37,10 +39,30 @@ def index(request): # a.save() # return redirect('fibu_make_booking') return redirect('fibu_index') - context = {'bookings': items, 'form': form} + context = {'bookings': bookings, 'form': form} return render(request, 'fibu/index.html', context) +@login_required +# @permission_required('aub.apply_for_aub') +def edit(request, id): + booking = get_object_or_404(Booking, id=id) + form = EditBookingForm(instance=booking) + template = 'fibu/edit.html' + if request.method == 'POST': + form = EditBookingForm(request.POST, instance=booking) + 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('fibu_index')) + context = {'form': form} + return render(request, template, context) + + @login_required