From 7f21fcc75dc2b0956763adb7db62829c38e5215c Mon Sep 17 00:00:00 2001 From: Fabian Krueger <fabian.krueger@fau.de> Date: Fri, 20 Sep 2019 08:47:11 +0200 Subject: [PATCH] update backend: now supporting getLastChargesList --- store/backend.py | 17 +++++++++++++++++ store/store_config.py | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/store/backend.py b/store/backend.py index f048b23..356e940 100644 --- a/store/backend.py +++ b/store/backend.py @@ -194,3 +194,20 @@ class PurchaseLogic: user.updateMoney(purchase.price) print("user_id:", user.id, "purchase_id:", purchase.id, "user.money:", user.money) + +class ChargeLogic: + + """ + Returns a list of the last charges of a specified user: [{'id': ..., 'amount': ...}, Decimal(...,...)] + @param user_id: the id of the specified user + @config-param max_charges: Number of charges to be shown. Depends on N_LAST_CHARGES + """ + def getLastChargesList(user_id): + max_charges = config['N_LAST_CHARGES'] + charges = Charge.objects.filter(user=user_id).values('id', 'amount') + if max_charges < 0: + charges = list(charges.order_by('time_stamp').reverse()) + else: + charges = list(charges.order_by('time_stamp').reverse())[:max_charges] + return charges + diff --git a/store/store_config.py b/store/store_config.py index a45ffa2..ac0b92c 100644 --- a/store/store_config.py +++ b/store/store_config.py @@ -5,8 +5,10 @@ T_ANNULLABLE_PURCHASE_M: time of minutes a user has for a purchase to undo it N_MOST_BOUGHT_PRODUCTS: number of products to be shown in 'Häufig gekauft' T_MOST_BOUGHT_PRODUCTS_D: number of days in the past that are used as time intervall limit to search for 'Häufig gekauft' N_USERS_LOGIN: number of users that should be shown in the users list in the login-screen. A negative number means - 'all users are selected' + 'all users are selected' T_USERS_LOGIN_D: number of days in the past that are used as time intervall limit to search for users +N_LAST_CHARGES: number of charges that should be shown in 'Letzte Aufladungen'. A negative number means 'all users are + selected' """ KAFFEEKASSE = {'N_LAST_BOUGHT_PRODUCTS': 5, 'T_LAST_BOUGHT_PRODUCTS_D': 30, @@ -15,4 +17,5 @@ KAFFEEKASSE = {'N_LAST_BOUGHT_PRODUCTS': 5, 'T_MOST_BOUGHT_PRODUCTS_D': 30, 'N_USERS_LOGIN': -1, 'T_USERS_LOGIN_D': 356, + 'N_LAST_CHARGES': -1, } -- GitLab