From f58a95a094693f7bb38ff4e6a54537a74632fc9f Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Dec 2024 04:04:59 +0100 Subject: [PATCH] feat: add users balance to admin interface --- CHANGELOG.md | 13 +++++++++++++ matemat/__init__.py | 2 +- matemat/db/facade.py | 11 +++++++---- matemat/webserver/pagelets/admin.py | 3 ++- templates/admin.html | 12 ++++++++++-- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d40d0..4a34a3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Matemat Changelog + +## Version 0.4.7 + +Feature release + +### Changes + + +- feat: add users balance to admin interface + + + + ## Version 0.4.6 diff --git a/matemat/__init__.py b/matemat/__init__.py index 62c068b..3f29551 100644 --- a/matemat/__init__.py +++ b/matemat/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.4.6' +__version__ = '0.4.7' diff --git a/matemat/db/facade.py b/matemat/db/facade.py index d48051a..4479418 100644 --- a/matemat/db/facade.py +++ b/matemat/db/facade.py @@ -130,7 +130,8 @@ class MatematDatabase(object): email: Optional[str] = None, admin: bool = False, member: bool = True, - logout_after_purchase: bool = False) -> User: + logout_after_purchase: bool = False, + balance: int = 0) -> User: """ Create a new user. :param username: The name of the new user. @@ -139,6 +140,7 @@ class MatematDatabase(object): :param admin: Whether the user is an administrator, defaults to False. :param member: Whether the user is a member, defaults to True. :param logout_after_purchase: Whether the user should be logged out after completing a purchase. + :param balance: Initial account balance of the user. :return: A User object representing the created user. :raises ValueError: If a user with the same name already exists. """ @@ -154,12 +156,13 @@ class MatematDatabase(object): c.execute(''' INSERT INTO users (username, email, password, balance, is_admin, is_member, lastchange, created, logout_after_purchase) - VALUES (:username, :email, :pwhash, 0, :admin, :member, STRFTIME('%s', 'now'), STRFTIME('%s', 'now'), - :logout_after_purchase) + VALUES (:username, :email, :pwhash, :balance, :admin, :member, STRFTIME('%s', 'now'), + STRFTIME('%s', 'now'), :logout_after_purchase) ''', { 'username': username, 'email': email, 'pwhash': pwhash, + 'balance': balance, 'admin': admin, 'member': member, 'logout_after_purchase': logout_after_purchase @@ -167,7 +170,7 @@ class MatematDatabase(object): # Fetch the new user's rowid. c.execute('SELECT last_insert_rowid()') user_id = int(c.fetchone()[0]) - return User(user_id, username, 0, email, admin, member) + return User(user_id, username, balance, email, admin, member) def login(self, username: str, password: Optional[str] = None, touchkey: Optional[str] = None) -> User: """ diff --git a/matemat/webserver/pagelets/admin.py b/matemat/webserver/pagelets/admin.py index 14c7e8e..e4de6e1 100644 --- a/matemat/webserver/pagelets/admin.py +++ b/matemat/webserver/pagelets/admin.py @@ -77,9 +77,10 @@ def handle_change(args: FormsDict, files: FormsDict, db: MatematDatabase): is_member = 'ismember' in args is_admin = 'isadmin' in args logout_after_purchase = 'logout_after_purchase' in args + balance = parse_chf(str(args.balance)) # Create the user in the database newuser: User = db.create_user(username, password, email, member=is_member, admin=is_admin, - logout_after_purchase=logout_after_purchase) + logout_after_purchase=logout_after_purchase, balance=balance) # The user requested to create a new product elif change == 'newproduct': diff --git a/templates/admin.html b/templates/admin.html index 6f53815..4909392 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -30,6 +30,7 @@ Member Admin Logout after purchase + Balance Actions @@ -39,6 +40,12 @@ + +
+ CHF + +
+ {% for user in users %} @@ -49,6 +56,7 @@ {{ '✓' if user.is_member else '✗' }} {{ '✓' if user.is_admin else '✗' }} {{ '✓' if user.logout_after_purchase else '✗' }} + {{ user.balance | chf }}
Edit @@ -82,13 +90,13 @@
CHF - +
CHF - +