diff --git a/refunding/templates/refunding/new_refund.html b/refunding/templates/refunding/edit_new_refund.html similarity index 88% rename from refunding/templates/refunding/new_refund.html rename to refunding/templates/refunding/edit_new_refund.html index 52e7164..5b1afad 100644 --- a/refunding/templates/refunding/new_refund.html +++ b/refunding/templates/refunding/edit_new_refund.html @@ -17,8 +17,8 @@ {% endblock %} {% block content %} -

{% block title %}New refund{% endblock %}

-
+

{% block title %}{{ title }}{% endblock %}

+ {% csrf_token %} {{ form.media }} {{ form|crispy }} diff --git a/refunding/templates/refunding/elements_list.html b/refunding/templates/refunding/elements_list.html index f8ef4f6..429d986 100644 --- a/refunding/templates/refunding/elements_list.html +++ b/refunding/templates/refunding/elements_list.html @@ -6,9 +6,17 @@ {% endif %}
{% for e in elements %} -
- {{ e.title }} le {{ e.date|date:"SHORT_DATE_FORMAT" }} : {{ e.eur_value }}€ -
+ {% if refunds %} + + {% else %} + + {% endif %} {% endfor %}
{% else %} diff --git a/refunding/urls.py b/refunding/urls.py index f16fe76..c3e66dc 100644 --- a/refunding/urls.py +++ b/refunding/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ url(r'^payments/$', views.not_refunded_payments, name='not_refunded_payments'), url(r'^refunds/$', views.latest_refunds, name='latest_refunds'), url(r'^refunds/new/$', views.new_refund, name='new_refund'), + url(r'^refunds/(?P[0-9]+)/edit/$', views.refund_edit, name='refund_edit'), ] diff --git a/refunding/views.py b/refunding/views.py index 4dbafa4..190b9e7 100644 --- a/refunding/views.py +++ b/refunding/views.py @@ -1,6 +1,6 @@ from django.contrib.auth.decorators import login_required from django.db.models import Sum -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect, get_object_or_404 from refunding.forms import RefundFormPublic from refunding.models import Payment, Refund @@ -45,6 +45,26 @@ def new_refund(request): form = RefundFormPublic() context = { - 'form': form + 'form': form, + 'title': 'New refund' } - return render(request, "refunding/new_refund.html", context) \ No newline at end of file + return render(request, "refunding/edit_new_refund.html", context) + + +@login_required +def refund_edit(request, pk): + refund = get_object_or_404(Refund, pk=pk) + if request.method == 'POST': + form = RefundFormPublic(request.POST, instance=refund) + if form.is_valid(): + refund = form.save() + refund.user = request.user + refund.save() + return redirect('latest_refunds') + else: + form = RefundFormPublic(instance=refund) + context = { + 'form': form, + 'title': 'Edit refund' + } + return render(request, 'refunding/edit_new_refund.html', context)