Skip to content

Commit

Permalink
Merge pull request #621 from lingxiaoyang/fix_616
Browse files Browse the repository at this point in the history
Fixed #616: add route client on dashboard, with unit test
  • Loading branch information
manumilou authored Jan 13, 2017
2 parents fa7760a + f3f0c10 commit 5143dab
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/frontend/scss/admin/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ p.signup, p.dashboard {
display: flex;
flex-direction: column;
justify-content: center;
min-height: 171px;
height: 171px;
overflow-y: auto;
}

.ui.dashboard.statistic .value {
Expand Down
17 changes: 8 additions & 9 deletions src/page/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-16 22:14+0000\n"
"POT-Creation-Date: 2017-01-12 16:31+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -62,16 +62,15 @@ msgid ""
msgstr ""

#: page/templates/pages/home.html:64
msgid "Any Header"
msgid "Routes"
msgstr ""

#: page/templates/pages/home.html:72
msgid "Downloads"
msgstr ""

#: page/templates/pages/home.html:77
msgid "Footer"
msgstr ""
#: page/templates/pages/home.html:86
#, python-format
msgid "%(count)s route."
msgid_plural "%(count)s routes."
msgstr[0] ""
msgstr[1] ""

#: page/templates/registration/login.html:8
#: page/templates/registration/login.html:37
Expand Down
23 changes: 14 additions & 9 deletions src/page/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-16 22:14+0000\n"
"POT-Creation-Date: 2017-01-12 16:31+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: PascalPriori <[email protected]>, 2016\n"
"Language-Team: French (https://www.transifex.com/savoirfairelinux/"
Expand Down Expand Up @@ -64,16 +64,15 @@ msgid ""
msgstr ""

#: page/templates/pages/home.html:64
msgid "Any Header"
msgid "Routes"
msgstr ""

#: page/templates/pages/home.html:72
msgid "Downloads"
msgstr "Téléchargements"

#: page/templates/pages/home.html:77
msgid "Footer"
msgstr "Pied de page"
#: page/templates/pages/home.html:86
#, python-format
msgid "%(count)s route."
msgid_plural "%(count)s routes."
msgstr[0] ""
msgstr[1] ""

#: page/templates/registration/login.html:8
#: page/templates/registration/login.html:37
Expand All @@ -88,6 +87,12 @@ msgstr "Se connecter à son compte"
msgid "Connect"
msgstr "Connexion"

#~ msgid "Downloads"
#~ msgstr "Téléchargements"

#~ msgid "Footer"
#~ msgstr "Pied de page"

#~ msgid "Dashboard"
#~ msgstr "Tableau de bord"

Expand Down
30 changes: 20 additions & 10 deletions src/page/templates/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,30 @@ <h3 class="ui yellow header">{% trans "Delivered this month" %}</h3>
<div class="dashboard-stat column">
<div class="ui segments">
<div class="ui segment">
<h3 class="ui blue header">{% trans "Any Header" %}</h3>
<h3 class="ui blue header">{% trans "Routes" %}</h3>
</div>
<div class="ui secondary blue inverted dashboard center aligned segment">
<div class="ui dashboard statistic">
<div class="value">
5,550
</div>
<div class="label">
{% trans "Downloads" %}
</div>
<div class="ui secondary blue inverted dashboard left aligned segment" style="justify-content: flex-start">
<div style="padding-bottom:14px">
<table class="ui very compact table">
<tbody>
{% for route_name, num_clients in routes %}
<tr>
<td>
{{ route_name }}
</td>
<td>
<span class="ui blue basic label">{{ num_clients }}</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="ui segment">
<p>{% trans "Footer" %}</p>
<p>
{% blocktrans count count=routes|length %}{{ count }} route.{% plural %}{{ count }} routes.{% endblocktrans %}
</p>
</div>
</div>
</div>
Expand Down
37 changes: 37 additions & 0 deletions src/page/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from django.core.urlresolvers import reverse_lazy
from django.core.urlresolvers import reverse

from member.factories import RouteFactory, ClientFactory
from member.models import Client


class HomeViewTestCase(TestCase):

Expand Down Expand Up @@ -42,3 +45,37 @@ def test_as_anonymous(self):
reverse('page:login') + '?next=/p/home',
status_code=302
)

def test_route_client_counts(self):
"""
On dashboard, routes shouly only include active and paused clients.
"""
self.client.login(
username=self.admin.username,
password="test"
)
route = RouteFactory()
counts = (
(Client.PENDING, 1),
(Client.ACTIVE, 2),
(Client.PAUSED, 4),
(Client.STOPNOCONTACT, 8),
(Client.STOPCONTACT, 16),
(Client.DECEASED, 32),
)
for status, count in counts:
ClientFactory.create_batch(
count,
status=status,
route=route
)
response = self.client.get(
reverse_lazy(
'page:home'
),
follow=False
)
self.assertEqual(response.status_code, 200)
routes = response.context['routes']
self.assertEqual(routes[0][0], route.name)
self.assertEqual(routes[0][1], 2 + 4)
20 changes: 18 additions & 2 deletions src/page/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.urlresolvers import reverse_lazy
from django.db.models import Count, Case, When, IntegerField
from django.views.generic import TemplateView
from member.models import Client
from member.models import Client, Route
from order.models import Order
from datetime import datetime

Expand All @@ -28,11 +29,26 @@ def get_context_data(self, **kwargs):
billable_orders_year = Order.objects.filter(
status='D',
delivery_date__year=datetime.today().year).count()
routes = Route.objects.annotate(
num_clients=Count(
Case(
# Count only active and paused clients
When(client__status=Client.ACTIVE, then=1),
When(client__status=Client.PAUSED, then=1),
output_field=IntegerField()
)
)
)
context['active_clients'] = active_clients
context['pending_clients'] = pending_clients
context['birthday'] = clients
context['billable_orders_month'] = billable_orders,
context['billable_orders_month'] = billable_orders
context['billable_orders_year'] = billable_orders_year
context['routes'] = sorted(
map(lambda r: (r.name, r.num_clients), routes),
key=lambda t: t[1],
reverse=True
)

return context

Expand Down

0 comments on commit 5143dab

Please sign in to comment.