From c128e5b524ca3324cae59c3b090a4769c8e1d385 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 4 Jun 2016 01:49:24 +0200 Subject: [PATCH] Add view for not refunded payments --- .../templates/refunding/payments_list.html | 22 +++++++++++++++++++ refunding/urls.py | 6 +++++ refunding/views.py | 15 ++++++++++++- .../templates/{blog => refunds}/about.html | 0 refunds/templates/{blog => refunds}/home.html | 0 refunds/urls.py | 1 + refunds/views.py | 4 ++-- 7 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 refunding/templates/refunding/payments_list.html create mode 100644 refunding/urls.py rename refunds/templates/{blog => refunds}/about.html (100%) rename refunds/templates/{blog => refunds}/home.html (100%) diff --git a/refunding/templates/refunding/payments_list.html b/refunding/templates/refunding/payments_list.html new file mode 100644 index 0000000..1aeafff --- /dev/null +++ b/refunding/templates/refunding/payments_list.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} +{% load l10n %} + +{% block content %} +

{% block title %}Payments to refund{% endblock %}

+ {% if payments %} +

+ Total : {{ sum }}€ +

+
+ {% for payment in payments %} +
+ {{ payment.title }} le {{ payment.date|date:"SHORT_DATE_FORMAT" }} : {{ payment.eur_value }}€ +
+ {% endfor %} +
+ {% else %} +

+ {% firstof default_nothing "Nothing here..." %} +

+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/refunding/urls.py b/refunding/urls.py new file mode 100644 index 0000000..4bf37d9 --- /dev/null +++ b/refunding/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from refunding.views import not_refunded_payments + +urlpatterns = [ + url(r'^payments/$', not_refunded_payments, name='not_refunded_payments'), +] diff --git a/refunding/views.py b/refunding/views.py index 91ea44a..c5e7b63 100644 --- a/refunding/views.py +++ b/refunding/views.py @@ -1,3 +1,16 @@ +from django.contrib.auth.decorators import login_required +from django.db.models import Sum from django.shortcuts import render +from refunding.models import Payment -# Create your views here. + +@login_required +def not_refunded_payments(request): + payments = Payment.objects.filter(refund=None) + sum = payments.aggregate(Sum('value')).get('value__sum') / 100 + context = { + 'payments': payments, + 'sum': sum, + 'default_nothing': 'No payment to be refunded.' + } + return render(request, "refunding/payments_list.html", context) diff --git a/refunds/templates/blog/about.html b/refunds/templates/refunds/about.html similarity index 100% rename from refunds/templates/blog/about.html rename to refunds/templates/refunds/about.html diff --git a/refunds/templates/blog/home.html b/refunds/templates/refunds/home.html similarity index 100% rename from refunds/templates/blog/home.html rename to refunds/templates/refunds/home.html diff --git a/refunds/urls.py b/refunds/urls.py index ced4b23..38c776f 100644 --- a/refunds/urls.py +++ b/refunds/urls.py @@ -22,4 +22,5 @@ urlpatterns = [ url(r'^auth/', include('authentication.urls')), url(r'^$', home, name='home'), url(r'^about/$', about, name='about'), + url(r'^', include('refunding.urls')) ] diff --git a/refunds/views.py b/refunds/views.py index 745672c..0629c2f 100644 --- a/refunds/views.py +++ b/refunds/views.py @@ -2,8 +2,8 @@ from django.shortcuts import render def home(request): - return render(request, "blog/home.html") + return render(request, "refunds/home.html") def about(request): - return render(request, "blog/about.html") + return render(request, "refunds/about.html")