0001-general-add-a-new-manager-page-to-list-recent-transa.patch
lingo/manager_views.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
from django.core.urlresolvers import reverse_lazy |
18 |
from django.views.generic import CreateView, UpdateView, ListView, DeleteView |
|
18 |
from django.http import HttpResponseRedirect |
|
19 |
from django.views.generic import (CreateView, UpdateView, ListView, |
|
20 |
DeleteView, TemplateView) |
|
19 | 21 | |
20 |
from .models import Regie |
|
22 |
import eopayment |
|
23 | ||
24 |
from .models import Regie, Transaction |
|
21 | 25 | |
22 | 26 |
class RegieListView(ListView): |
23 | 27 |
model = Regie |
... | ... | |
25 | 29 | |
26 | 30 |
class RegieCreateView(CreateView): |
27 | 31 |
model = Regie |
28 |
success_url = reverse_lazy('lingo-manager-homepage')
|
|
32 |
success_url = reverse_lazy('lingo-manager-regie-list')
|
|
29 | 33 | |
30 | 34 | |
31 | 35 |
class RegieUpdateView(UpdateView): |
32 | 36 |
model = Regie |
33 |
success_url = reverse_lazy('lingo-manager-homepage')
|
|
37 |
success_url = reverse_lazy('lingo-manager-regie-list')
|
|
34 | 38 | |
35 | 39 | |
36 | 40 |
class RegieDeleteView(DeleteView): |
37 | 41 |
model = Regie |
38 |
success_url = reverse_lazy('lingo-manager-homepage') |
|
42 |
success_url = reverse_lazy('lingo-manager-regie-list') |
|
43 | ||
44 | ||
45 |
class TransactionListView(ListView): |
|
46 |
model = Transaction |
|
47 |
paginate_by = 10 |
|
48 | ||
49 |
def get_queryset(self): |
|
50 |
return Transaction.objects.filter(status=eopayment.PAID).order_by('-start_date') |
|
51 | ||
52 | ||
53 |
class ManagerHomeView(TemplateView): |
|
54 |
template_name = 'lingo/manager_home.html' |
lingo/models.py | ||
---|---|---|
219 | 219 |
eopayment.CANCELLED: _('Cancelled'), |
220 | 220 |
}.get(self.status) or _('Unknown') |
221 | 221 | |
222 |
def total_amount(self): |
|
223 |
if self.items: |
|
224 |
return sum([x.amount for x in self.items.all()]) |
|
225 | ||
222 | 226 | |
223 | 227 |
@register_cell_class |
224 | 228 |
class LingoBasketCell(CellBase): |
lingo/templates/lingo/manager_base.html | ||
---|---|---|
2 | 2 |
{% load i18n %} |
3 | 3 | |
4 | 4 |
{% block appbar %} |
5 |
<h2>{% trans 'Regies' %}</h2>
|
|
5 |
<h2>{% trans 'Online Payment' %}</h2>
|
|
6 | 6 |
{% endblock %} |
7 | 7 | |
8 | 8 |
{% block breadcrumb %} |
lingo/templates/lingo/manager_home.html | ||
---|---|---|
1 |
{% extends "lingo/manager_base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block content %} |
|
5 |
<ul class="apps"> |
|
6 |
<li><a class="button" href="{% url 'lingo-manager-transactions-list' %}">{% trans 'Transactions' %}</a></li> |
|
7 |
<li><a class="button" href="{% url 'lingo-manager-regie-list' %}">{% trans 'Regies' %}</a></li> |
|
8 |
</ul> |
|
9 |
{% endblock %} |
lingo/templates/lingo/regie_form.html | ||
---|---|---|
1 |
{% extends "lingo/manager_base.html" %}
|
|
1 |
{% extends "lingo/regie_list.html" %}
|
|
2 | 2 |
{% load i18n %} |
3 | 3 | |
4 | 4 |
{% block appbar %} |
lingo/templates/lingo/regie_list.html | ||
---|---|---|
6 | 6 |
<a rel="popup" href="{% url 'lingo-manager-regie-add' %}">{% trans 'New' %}</a> |
7 | 7 |
{% endblock %} |
8 | 8 | |
9 |
{% block breadcrumb %} |
|
10 |
{{ block.super }} |
|
11 |
<a href="{% url 'lingo-manager-regie-list' %}">{% trans 'Regies' %}</a> |
|
12 |
{% endblock %} |
|
13 | ||
9 | 14 |
{% block content %} |
10 | 15 | |
11 | 16 |
{% if object_list %} |
lingo/templates/lingo/transaction_list.html | ||
---|---|---|
1 |
{% extends "lingo/manager_base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar %} |
|
5 |
<h2>{% trans 'Transactions' %}</h2> |
|
6 |
{% endblock %} |
|
7 | ||
8 |
{% block breadcrumb %} |
|
9 |
{{ block.super }} |
|
10 |
<a href="{% url 'lingo-manager-transactions-list' %}">{% trans 'Transactions' %}</a> |
|
11 |
{% endblock %} |
|
12 | ||
13 |
{% block content %} |
|
14 | ||
15 |
{% if object_list %} |
|
16 |
<table class="main"> |
|
17 |
<thead> |
|
18 |
<tr> |
|
19 |
<th>{% trans 'Transaction Identifier' %}</th> |
|
20 |
<th>{% trans 'Date' %}</th> |
|
21 |
<th>{% trans 'User' %}</th> |
|
22 |
<th>{% trans 'Amount' %}</th> |
|
23 |
<th colspan="2">{% trans 'Items' %}</th> |
|
24 |
</tr> |
|
25 |
</thead> |
|
26 |
<tbody> |
|
27 |
{% for object in object_list %} |
|
28 |
<tr> |
|
29 |
<td rowspan="{{object.items.all.count}}">{{object.order_id}}</td> |
|
30 |
<td rowspan="{{object.items.all.count}}">{{object.start_date}}</td> |
|
31 |
<td rowspan="{{object.items.all.count}}">{{object.user.first_name}} {{object.user.last_name}}</td> |
|
32 |
<td rowspan="{{object.items.all.count}}">{{object.total_amount}} €</td> |
|
33 |
{% for item in object.items.all %} |
|
34 |
{% if not forloop.first %}<tr>{% endif %} |
|
35 |
<td style="font-size: smaller">{{item.subject}}</td> <td style="font-size: smaller" class="price">{{item.amount}} €</td></tr> |
|
36 |
{% endfor %}</td> |
|
37 |
</tr> |
|
38 |
{{transaction.order_id }} |
|
39 |
{% endfor %} |
|
40 |
</tbody> |
|
41 |
</table> |
|
42 | ||
43 |
{% if is_paginated %} |
|
44 |
<p class="paginator"> |
|
45 |
{% if page_obj.has_previous %} |
|
46 |
<a href="?page={{ page_obj.previous_page_number }}"><<</a> |
|
47 |
{% else %} |
|
48 |
<span><<</span> |
|
49 |
{% endif %} |
|
50 | ||
51 |
|
|
52 |
<span class="current"> |
|
53 |
{{ page_obj.number }} / {{ page_obj.paginator.num_pages }} |
|
54 |
</span> |
|
55 |
|
|
56 | ||
57 |
{% if page_obj.has_next %} |
|
58 |
<a href="?page={{ page_obj.next_page_number }}">>></a> |
|
59 |
{% else %} |
|
60 |
<span>>></span> |
|
61 |
{% endif %} |
|
62 |
</div> |
|
63 |
{% endif %} |
|
64 | ||
65 | ||
66 |
</div> |
|
67 |
{% else %} |
|
68 |
<div class="big-msg-info"> |
|
69 |
{% blocktrans %} |
|
70 |
This site doesn't have any transaction yet. |
|
71 |
{% endblocktrans %} |
|
72 |
</div> |
|
73 |
{% endif %} |
|
74 | ||
75 |
{% endblock %} |
lingo/urls.py | ||
---|---|---|
21 | 21 |
from .views import (RegiesApiView, AddBasketItemApiView, PayView, CallbackView, |
22 | 22 |
ReturnView, ItemDownloadView, ItemView) |
23 | 23 |
from .manager_views import (RegieListView, RegieCreateView, RegieUpdateView, |
24 |
RegieDeleteView) |
|
24 |
RegieDeleteView, TransactionListView, ManagerHomeView)
|
|
25 | 25 | |
26 | 26 |
lingo_manager_urls = patterns('lingo.manager_views', |
27 |
url('^$', RegieListView.as_view(), name='lingo-manager-homepage'), |
|
27 |
url('^$', ManagerHomeView.as_view(), name='lingo-manager-homepage'), |
|
28 |
url('^transactions/$', TransactionListView.as_view(), name='lingo-manager-transactions-list'), |
|
29 |
url('^regies/$', RegieListView.as_view(), name='lingo-manager-regie-list'), |
|
28 | 30 |
url('^regies/add/$', RegieCreateView.as_view(), name='lingo-manager-regie-add'), |
29 | 31 |
url('^regies/(?P<pk>\w+)/edit$', RegieUpdateView.as_view(), |
30 | 32 |
name='lingo-manager-regie-edit'), |
tests/test_manager.py | ||
---|---|---|
32 | 32 |
def test_add_regie(admin_user): |
33 | 33 |
Regie.objects.all().delete() |
34 | 34 |
app = login(TestApp(get_wsgi_application())) |
35 |
resp = app.get('/manage/lingo/', status=200) |
|
35 |
resp = app.get('/manage/lingo/regies/', status=200)
|
|
36 | 36 |
resp = resp.click('New') |
37 | 37 |
resp.forms[0]['label'] = 'Test' |
38 | 38 |
resp.forms[0]['slug'] = 'test' |
39 | 39 |
resp.forms[0]['description'] = 'description' |
40 | 40 |
resp.forms[0]['service'] = 'dummy' |
41 | 41 |
resp = resp.forms[0].submit() |
42 |
assert resp.location == 'http://localhost:80/manage/lingo/' |
|
42 |
assert resp.location == 'http://localhost:80/manage/lingo/regies/'
|
|
43 | 43 |
assert Regie.objects.count() == 1 |
44 | 44 |
regie = Regie.objects.all()[0] |
45 | 45 |
assert regie.label == 'Test' |
... | ... | |
47 | 47 |
def test_edit_regie(admin_user): |
48 | 48 |
test_add_regie(admin_user) |
49 | 49 |
app = login(TestApp(get_wsgi_application())) |
50 |
resp = app.get('/manage/lingo/', status=200) |
|
50 |
resp = app.get('/manage/lingo/regies/', status=200)
|
|
51 | 51 |
resp = resp.click('Test') |
52 | 52 |
resp.forms[0]['description'] = 'other description' |
53 | 53 |
resp = resp.forms[0].submit() |
54 |
assert resp.location == 'http://localhost:80/manage/lingo/' |
|
54 |
assert resp.location == 'http://localhost:80/manage/lingo/regies/'
|
|
55 | 55 |
assert Regie.objects.count() == 1 |
56 | 56 |
regie = Regie.objects.all()[0] |
57 | 57 |
assert regie.description == 'other description' |
... | ... | |
59 | 59 |
def test_delete_regie(admin_user): |
60 | 60 |
test_add_regie(admin_user) |
61 | 61 |
app = login(TestApp(get_wsgi_application())) |
62 |
resp = app.get('/manage/lingo/', status=200) |
|
62 |
resp = app.get('/manage/lingo/regies/', status=200)
|
|
63 | 63 |
resp = resp.click('Test') |
64 | 64 |
resp = resp.click('Delete') |
65 | 65 |
assert 'Are you sure you want to delete this?' in resp.body |
66 | 66 |
resp = resp.forms[0].submit() |
67 |
assert resp.location == 'http://localhost:80/manage/lingo/' |
|
67 |
assert resp.location == 'http://localhost:80/manage/lingo/regies/'
|
|
68 | 68 |
assert Regie.objects.count() == 0 |
69 |
- |