From c243c6f12f11ad8b1019cec3b4ff4f2ef37b6dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 8 Dec 2015 22:43:20 +0100 Subject: [PATCH] general: add a new manager page to list recent transactions (#9252) --- lingo/manager_views.py | 26 ++++++++-- lingo/models.py | 4 ++ lingo/templates/lingo/manager_base.html | 2 +- lingo/templates/lingo/manager_home.html | 9 ++++ lingo/templates/lingo/regie_form.html | 2 +- lingo/templates/lingo/regie_list.html | 5 ++ lingo/templates/lingo/transaction_list.html | 75 +++++++++++++++++++++++++++++ lingo/urls.py | 6 ++- tests/test_manager.py | 12 ++--- 9 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 lingo/templates/lingo/manager_home.html create mode 100644 lingo/templates/lingo/transaction_list.html diff --git a/lingo/manager_views.py b/lingo/manager_views.py index baaefb8..984f794 100644 --- a/lingo/manager_views.py +++ b/lingo/manager_views.py @@ -15,9 +15,13 @@ # along with this program. If not, see . from django.core.urlresolvers import reverse_lazy -from django.views.generic import CreateView, UpdateView, ListView, DeleteView +from django.http import HttpResponseRedirect +from django.views.generic import (CreateView, UpdateView, ListView, + DeleteView, TemplateView) -from .models import Regie +import eopayment + +from .models import Regie, Transaction class RegieListView(ListView): model = Regie @@ -25,14 +29,26 @@ class RegieListView(ListView): class RegieCreateView(CreateView): model = Regie - success_url = reverse_lazy('lingo-manager-homepage') + success_url = reverse_lazy('lingo-manager-regie-list') class RegieUpdateView(UpdateView): model = Regie - success_url = reverse_lazy('lingo-manager-homepage') + success_url = reverse_lazy('lingo-manager-regie-list') class RegieDeleteView(DeleteView): model = Regie - success_url = reverse_lazy('lingo-manager-homepage') + success_url = reverse_lazy('lingo-manager-regie-list') + + +class TransactionListView(ListView): + model = Transaction + paginate_by = 10 + + def get_queryset(self): + return Transaction.objects.filter(status=eopayment.PAID).order_by('-start_date') + + +class ManagerHomeView(TemplateView): + template_name = 'lingo/manager_home.html' diff --git a/lingo/models.py b/lingo/models.py index 56a8dba..aeca24e 100644 --- a/lingo/models.py +++ b/lingo/models.py @@ -219,6 +219,10 @@ class Transaction(models.Model): eopayment.CANCELLED: _('Cancelled'), }.get(self.status) or _('Unknown') + def total_amount(self): + if self.items: + return sum([x.amount for x in self.items.all()]) + @register_cell_class class LingoBasketCell(CellBase): diff --git a/lingo/templates/lingo/manager_base.html b/lingo/templates/lingo/manager_base.html index 0792d47..c59e026 100644 --- a/lingo/templates/lingo/manager_base.html +++ b/lingo/templates/lingo/manager_base.html @@ -2,7 +2,7 @@ {% load i18n %} {% block appbar %} -

{% trans 'Regies' %}

+

{% trans 'Online Payment' %}

{% endblock %} {% block breadcrumb %} diff --git a/lingo/templates/lingo/manager_home.html b/lingo/templates/lingo/manager_home.html new file mode 100644 index 0000000..d467125 --- /dev/null +++ b/lingo/templates/lingo/manager_home.html @@ -0,0 +1,9 @@ +{% extends "lingo/manager_base.html" %} +{% load i18n %} + +{% block content %} + +{% endblock %} diff --git a/lingo/templates/lingo/regie_form.html b/lingo/templates/lingo/regie_form.html index 60b5fb2..5bb04c1 100644 --- a/lingo/templates/lingo/regie_form.html +++ b/lingo/templates/lingo/regie_form.html @@ -1,4 +1,4 @@ -{% extends "lingo/manager_base.html" %} +{% extends "lingo/regie_list.html" %} {% load i18n %} {% block appbar %} diff --git a/lingo/templates/lingo/regie_list.html b/lingo/templates/lingo/regie_list.html index 9a3e720..11f9f96 100644 --- a/lingo/templates/lingo/regie_list.html +++ b/lingo/templates/lingo/regie_list.html @@ -6,6 +6,11 @@ {% trans 'New' %} {% endblock %} +{% block breadcrumb %} +{{ block.super }} +{% trans 'Regies' %} +{% endblock %} + {% block content %} {% if object_list %} diff --git a/lingo/templates/lingo/transaction_list.html b/lingo/templates/lingo/transaction_list.html new file mode 100644 index 0000000..3879396 --- /dev/null +++ b/lingo/templates/lingo/transaction_list.html @@ -0,0 +1,75 @@ +{% extends "lingo/manager_base.html" %} +{% load i18n %} + +{% block appbar %} +

{% trans 'Transactions' %}

+{% endblock %} + +{% block breadcrumb %} +{{ block.super }} +{% trans 'Transactions' %} +{% endblock %} + +{% block content %} + +{% if object_list %} + + + + + + + + + + + +{% for object in object_list %} + + + + + + {% for item in object.items.all %} + {% if not forloop.first %}{% endif %} + + {% endfor %} + +{{transaction.order_id }} + {% endfor %} + +
{% trans 'Transaction Identifier' %}{% trans 'Date' %}{% trans 'User' %}{% trans 'Amount' %}{% trans 'Items' %}
{{object.order_id}}{{object.start_date}}{{object.user.first_name}} {{object.user.last_name}}{{object.total_amount}} €
{{item.subject}} {{item.amount}} €
+ +{% if is_paginated %} +

+ {% if page_obj.has_previous %} + << + {% else %} + << + {% endif %} + +   + + {{ page_obj.number }} / {{ page_obj.paginator.num_pages }} + +   + + {% if page_obj.has_next %} + >> + {% else %} + >> + {% endif %} + +{% endif %} + + + +{% else %} +

+ {% blocktrans %} + This site doesn't have any transaction yet. + {% endblocktrans %} +
+{% endif %} + +{% endblock %} diff --git a/lingo/urls.py b/lingo/urls.py index 82e89f6..877c042 100644 --- a/lingo/urls.py +++ b/lingo/urls.py @@ -21,10 +21,12 @@ from combo.urls_utils import decorated_includes, manager_required from .views import (RegiesApiView, AddBasketItemApiView, PayView, CallbackView, ReturnView, ItemDownloadView, ItemView) from .manager_views import (RegieListView, RegieCreateView, RegieUpdateView, - RegieDeleteView) + RegieDeleteView, TransactionListView, ManagerHomeView) lingo_manager_urls = patterns('lingo.manager_views', - url('^$', RegieListView.as_view(), name='lingo-manager-homepage'), + url('^$', ManagerHomeView.as_view(), name='lingo-manager-homepage'), + url('^transactions/$', TransactionListView.as_view(), name='lingo-manager-transactions-list'), + url('^regies/$', RegieListView.as_view(), name='lingo-manager-regie-list'), url('^regies/add/$', RegieCreateView.as_view(), name='lingo-manager-regie-add'), url('^regies/(?P\w+)/edit$', RegieUpdateView.as_view(), name='lingo-manager-regie-edit'), diff --git a/tests/test_manager.py b/tests/test_manager.py index cac634d..684d6d2 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -32,14 +32,14 @@ def test_access(admin_user): def test_add_regie(admin_user): Regie.objects.all().delete() app = login(TestApp(get_wsgi_application())) - resp = app.get('/manage/lingo/', status=200) + resp = app.get('/manage/lingo/regies/', status=200) resp = resp.click('New') resp.forms[0]['label'] = 'Test' resp.forms[0]['slug'] = 'test' resp.forms[0]['description'] = 'description' resp.forms[0]['service'] = 'dummy' resp = resp.forms[0].submit() - assert resp.location == 'http://localhost:80/manage/lingo/' + assert resp.location == 'http://localhost:80/manage/lingo/regies/' assert Regie.objects.count() == 1 regie = Regie.objects.all()[0] assert regie.label == 'Test' @@ -47,11 +47,11 @@ def test_add_regie(admin_user): def test_edit_regie(admin_user): test_add_regie(admin_user) app = login(TestApp(get_wsgi_application())) - resp = app.get('/manage/lingo/', status=200) + resp = app.get('/manage/lingo/regies/', status=200) resp = resp.click('Test') resp.forms[0]['description'] = 'other description' resp = resp.forms[0].submit() - assert resp.location == 'http://localhost:80/manage/lingo/' + assert resp.location == 'http://localhost:80/manage/lingo/regies/' assert Regie.objects.count() == 1 regie = Regie.objects.all()[0] assert regie.description == 'other description' @@ -59,10 +59,10 @@ def test_edit_regie(admin_user): def test_delete_regie(admin_user): test_add_regie(admin_user) app = login(TestApp(get_wsgi_application())) - resp = app.get('/manage/lingo/', status=200) + resp = app.get('/manage/lingo/regies/', status=200) resp = resp.click('Test') resp = resp.click('Delete') assert 'Are you sure you want to delete this?' in resp.body resp = resp.forms[0].submit() - assert resp.location == 'http://localhost:80/manage/lingo/' + assert resp.location == 'http://localhost:80/manage/lingo/regies/' assert Regie.objects.count() == 0 -- 2.6.2