Added two new statistics about all users: 'order sum' visible for users having the 'view_order' permission and 'deposit sum' visible for users having the 'view_registertransaction' permission, improved the layout of the statistics page, updated translations
This commit is contained in:
parent
4eb2911150
commit
e4acc5c101
5 changed files with 109 additions and 34 deletions
|
@ -16,7 +16,6 @@ def _db_select(sql_select:str):
|
|||
result = cursor.fetchall()
|
||||
return result
|
||||
|
||||
|
||||
def _combine_results(results:list) -> dict:
|
||||
'''
|
||||
e.g.
|
||||
|
@ -81,8 +80,7 @@ def select_history(user, language_code="en") -> list:
|
|||
result = [list(row) for row in result]
|
||||
return result
|
||||
|
||||
|
||||
def orders_per_month(user) -> list:
|
||||
def select_orders_per_month(user) -> dict:
|
||||
# number of orders per month (last 12 months)
|
||||
result_user = _db_select(f"""
|
||||
select
|
||||
|
@ -105,8 +103,7 @@ def orders_per_month(user) -> list:
|
|||
""")
|
||||
return _combine_results([result_all, result_user])
|
||||
|
||||
|
||||
def orders_per_weekday(user) -> list:
|
||||
def select_orders_per_weekday(user) -> list:
|
||||
# number of orders per weekday (all time)
|
||||
result = _db_select(f"""
|
||||
with q_all as (
|
||||
|
@ -132,8 +129,7 @@ def orders_per_weekday(user) -> list:
|
|||
result[i] = (day_name[int(day_)-1], all_, user_)
|
||||
return result
|
||||
|
||||
|
||||
def orders_per_drink(user) -> list:
|
||||
def select_orders_per_drink(user) -> dict:
|
||||
# number of orders per drink (all time)
|
||||
result_user = _db_select(f"""
|
||||
select
|
||||
|
@ -155,3 +151,30 @@ def orders_per_drink(user) -> list:
|
|||
order by "data" desc;
|
||||
""")
|
||||
return _combine_results([result_all, result_user])
|
||||
|
||||
def select_order_sum_per_user_all_users() -> list:
|
||||
# sum of all orders per user, for all users
|
||||
result = _db_select(f"""
|
||||
select
|
||||
app_user.username as user,
|
||||
sum(app_order.price_sum) as sum
|
||||
from app_user
|
||||
left outer join app_order on (app_user.id = app_order.user_id)
|
||||
group by app_user.id
|
||||
order by app_user asc;
|
||||
""")
|
||||
return result
|
||||
|
||||
def select_deposit_sum_per_user_all_users() -> list:
|
||||
# sum of all orders per user, for all users
|
||||
result = _db_select(f"""
|
||||
select
|
||||
app_user.username as user,
|
||||
sum(rt.transaction_sum) as sum
|
||||
from app_user
|
||||
left outer join app_registertransaction rt on (app_user.id = rt.user_id)
|
||||
where rt.is_user_deposit is true or rt.is_user_deposit is null
|
||||
group by app_user.id
|
||||
order by app_user asc;
|
||||
""")
|
||||
return result
|
||||
|
|
Binary file not shown.
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2023-04-14 23:37+0200\n"
|
||||
"POT-Creation-Date: 2023-11-01 18:52+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: Julian Müller (ChaoticByte)\n"
|
||||
"Language: DE\n"
|
||||
|
@ -55,7 +55,7 @@ msgstr "Bestätigen"
|
|||
msgid "Drinks - History"
|
||||
msgstr "Getränke - Verlauf"
|
||||
|
||||
#: app/templates/history.html:10 app/templates/userpanel.html:25
|
||||
#: app/templates/history.html:10 app/templates/userpanel.html:23
|
||||
msgid "History"
|
||||
msgstr "Verlauf"
|
||||
|
||||
|
@ -165,7 +165,7 @@ msgstr "Wähle deinen Account"
|
|||
msgid "Drinks - Statistics"
|
||||
msgstr "Getränke - Statistiken"
|
||||
|
||||
#: app/templates/statistics.html:10 app/templates/userpanel.html:26
|
||||
#: app/templates/statistics.html:10 app/templates/userpanel.html:24
|
||||
msgid "Statistics"
|
||||
msgstr "Statistiken"
|
||||
|
||||
|
@ -177,37 +177,45 @@ msgstr "Bestellungen / Getränk"
|
|||
msgid "drink"
|
||||
msgstr "Getränk"
|
||||
|
||||
#: app/templates/statistics.html:17 app/templates/statistics.html:34
|
||||
#: app/templates/statistics.html:51
|
||||
msgid "you"
|
||||
msgstr "Du"
|
||||
|
||||
#: app/templates/statistics.html:18 app/templates/statistics.html:35
|
||||
#: app/templates/statistics.html:52
|
||||
#: app/templates/statistics.html:17 app/templates/statistics.html:36
|
||||
#: app/templates/statistics.html:53
|
||||
msgid "all"
|
||||
msgstr "Alle"
|
||||
|
||||
#: app/templates/statistics.html:30
|
||||
#: app/templates/statistics.html:18 app/templates/statistics.html:37
|
||||
#: app/templates/statistics.html:54
|
||||
msgid "you"
|
||||
msgstr "Du"
|
||||
|
||||
#: app/templates/statistics.html:32
|
||||
msgid "orders / month"
|
||||
msgstr "Bestellungen / Monat"
|
||||
|
||||
#: app/templates/statistics.html:33
|
||||
#: app/templates/statistics.html:35
|
||||
msgid "month"
|
||||
msgstr "Monat"
|
||||
|
||||
#: app/templates/statistics.html:47
|
||||
#: app/templates/statistics.html:49
|
||||
msgid "orders / weekday"
|
||||
msgstr "Bestellungen / Wochentag"
|
||||
|
||||
#: app/templates/statistics.html:50
|
||||
#: app/templates/statistics.html:52
|
||||
msgid "day"
|
||||
msgstr "Tag"
|
||||
|
||||
#: app/templates/statistics.html:69
|
||||
msgid "order sum"
|
||||
msgstr "Bestellungen"
|
||||
|
||||
#: app/templates/statistics.html:86
|
||||
msgid "deposit sum"
|
||||
msgstr "Einzahlungen"
|
||||
|
||||
#: app/templates/supply.html:7
|
||||
msgid "Drinks - Supply"
|
||||
msgstr "Getränke - Beschaffung"
|
||||
|
||||
#: app/templates/supply.html:14 app/templates/userpanel.html:32
|
||||
#: app/templates/supply.html:14 app/templates/userpanel.html:30
|
||||
msgid "Supply"
|
||||
msgstr "Beschaffung"
|
||||
|
||||
|
@ -228,7 +236,6 @@ msgid "You are not allowed to view this site."
|
|||
msgstr "Dir fehlt die Berechtigung, diese Seite anzuzeigen."
|
||||
|
||||
#: app/templates/transfer.html:6
|
||||
#| msgid "Drinks - Order"
|
||||
msgid "Drinks - Transfer"
|
||||
msgstr "Getränke - Geld senden"
|
||||
|
||||
|
@ -248,11 +255,11 @@ msgstr "Saldo"
|
|||
msgid "Logout"
|
||||
msgstr "Abmelden"
|
||||
|
||||
#: app/templates/userpanel.html:30
|
||||
#: app/templates/userpanel.html:28
|
||||
msgid "Transfer"
|
||||
msgstr "Geld senden"
|
||||
|
||||
#: app/templates/userpanel.html:34
|
||||
#: app/templates/userpanel.html:32
|
||||
msgid "Change Password"
|
||||
msgstr "Passwort ändern"
|
||||
|
||||
|
|
|
@ -20,12 +20,14 @@
|
|||
{% for key, values in orders_per_drink.items %}
|
||||
<tr>
|
||||
<td>{{ key }}</td>
|
||||
<td>{{ values.a|default:"0" }}</td>
|
||||
<td>{{ values.b|default:"0" }}</td>
|
||||
<td>{{ values.a|default:0 }}</td>
|
||||
<td>{{ values.b|default:0 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="statistics-container">
|
||||
<div class="flex flex-column">
|
||||
<h3>{% translate "orders / month" %}</h3>
|
||||
<table>
|
||||
|
@ -37,8 +39,8 @@
|
|||
{% for key, values in orders_per_month.items %}
|
||||
<tr>
|
||||
<td>{{ key }}</td>
|
||||
<td>{{ values.a|default:"0" }}</td>
|
||||
<td>{{ values.b|default:"0" }}</td>
|
||||
<td>{{ values.a|default:0 }}</td>
|
||||
<td>{{ values.b|default:0 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
@ -54,11 +56,48 @@
|
|||
{% for values in orders_per_weekday %}
|
||||
<tr>
|
||||
<td>{{ values.0 }}</td>
|
||||
<td>{{ values.1|default:"0" }}</td>
|
||||
<td>{{ values.2|default:"0" }}</td>
|
||||
<td>{{ values.1|default:0 }}</td>
|
||||
<td>{{ values.2|default:0 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="statistics-container">
|
||||
{% if user.is_superuser or perms.app.view_order %}
|
||||
<div class="flex flex-column">
|
||||
<h3>{% translate "order sum" %}</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<th>{% translate "user" %}</th>
|
||||
<th>{% translate "sum" %}</th>
|
||||
</tr>
|
||||
{% for values in order_sum_per_user %}
|
||||
<tr>
|
||||
<td>{{ values.0 }}</td>
|
||||
<td>{{ values.1|default:0.0 }} {{ currency_suffix }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if user.is_superuser or perms.app.view_registertransaction %}
|
||||
<div class="flex flex-column">
|
||||
<h3>{% translate "deposit sum" %}</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<th>{% translate "user" %}</th>
|
||||
<th>{% translate "sum" %}</th>
|
||||
</tr>
|
||||
{% for values in deposit_sum_per_user %}
|
||||
<tr>
|
||||
<td>{{ values.0 }}</td>
|
||||
<td>{{ values.1|default:0.0 }} {{ currency_suffix }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<script src="/static/js/autoreload.js"></script>
|
||||
{% endblock %}
|
12
app/views.py
12
app/views.py
|
@ -80,11 +80,17 @@ def deposit(request):
|
|||
|
||||
@login_required
|
||||
def statistics(request):
|
||||
user = request.user
|
||||
context = {
|
||||
"orders_per_month": db_queries.orders_per_month(request.user),
|
||||
"orders_per_weekday": db_queries.orders_per_weekday(request.user),
|
||||
"orders_per_drink": db_queries.orders_per_drink(request.user),
|
||||
"orders_per_month": db_queries.select_orders_per_month(user),
|
||||
"orders_per_weekday": db_queries.select_orders_per_weekday(user),
|
||||
"orders_per_drink": db_queries.select_orders_per_drink(user),
|
||||
}
|
||||
# Advanced statistics
|
||||
if user.has_perm("app.view_order") or user.is_superuser:
|
||||
context["order_sum_per_user"] = db_queries.select_order_sum_per_user_all_users()
|
||||
if user.has_perm("app.view_registertransaction") or user.is_superuser:
|
||||
context["deposit_sum_per_user"] = db_queries.select_deposit_sum_per_user_all_users()
|
||||
return render(request, "statistics.html", context)
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue