diff --git a/matemat/db/primitives/ReceiptPreference.py b/matemat/db/primitives/ReceiptPreference.py
index 5e0b37e..3293f23 100644
--- a/matemat/db/primitives/ReceiptPreference.py
+++ b/matemat/db/primitives/ReceiptPreference.py
@@ -6,22 +6,37 @@ class ReceiptPreference(Enum):
A user's preference for the frequency of receiving receipts.
"""
+ def __new__(cls, *args, **kwargs):
+ e = object.__new__(cls)
+ # The enum's internal value
+ e._value_: int = args[0]
+ # The human-readable description
+ e._human_readable: str = args[1]
+ return e
+
+ @property
+ def human_readable(self) -> str:
+ """
+ A human-readable description of the receipt preference, to be displayed in the UI.
+ """
+ return self._human_readable
+
"""
No receipts should be generated.
"""
- NONE = 0
+ NONE = 0, 'No receipts'
"""
A receipt should be generated for each transaction.
"""
- EACH = 1
+ EACH = 1, 'Individual receipt per transaction'
"""
A receipt should be generated once a month.
"""
- MONTHLY = 2
+ MONTHLY = 2, 'Aggregated, monthly'
"""
A receipt should be generated once a year.
"""
- YEARLY = 3
+ YEARLY = 3, 'Aggregated, yearly'
diff --git a/matemat/webserver/pagelets/admin.py b/matemat/webserver/pagelets/admin.py
index b84db3c..1aec0c1 100644
--- a/matemat/webserver/pagelets/admin.py
+++ b/matemat/webserver/pagelets/admin.py
@@ -5,7 +5,7 @@ import magic
from matemat.webserver import pagelet, RequestArguments, PageletResponse, RedirectResponse, TemplateResponse
from matemat.db import MatematDatabase
-from matemat.db.primitives import User
+from matemat.db.primitives import User, ReceiptPreference
from matemat.exceptions import DatabaseConsistencyError, HttpException
@@ -47,6 +47,7 @@ def admin(method: str,
# Render the "Admin/Settings" page
return TemplateResponse('admin.html',
authuser=user, authlevel=authlevel, users=users, products=products,
+ receipt_preference_class=ReceiptPreference,
setupname=config['InstanceName'])
@@ -73,9 +74,13 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase, confi
# An empty e-mail field should be interpreted as NULL
if len(email) == 0:
email = None
- # Attempt to update username and e-mail
try:
- db.change_user(user, agent=None, name=username, email=email)
+ receipt_pref = ReceiptPreference(int(str(args.receipt_pref)))
+ except ValueError:
+ return
+ # Attempt to update username, e-mail and receipt preference
+ try:
+ db.change_user(user, agent=None, name=username, email=email, receipt_pref=receipt_pref)
except DatabaseConsistencyError:
return
diff --git a/matemat/webserver/pagelets/moduser.py b/matemat/webserver/pagelets/moduser.py
index 0b535f1..a2f135f 100644
--- a/matemat/webserver/pagelets/moduser.py
+++ b/matemat/webserver/pagelets/moduser.py
@@ -5,7 +5,7 @@ import magic
from matemat.webserver import pagelet, RequestArguments, PageletResponse, RedirectResponse, TemplateResponse
from matemat.db import MatematDatabase
-from matemat.db.primitives import User
+from matemat.db.primitives import User, ReceiptPreference
from matemat.exceptions import DatabaseConsistencyError, HttpException
from matemat.util.currency_format import parse_chf
@@ -56,6 +56,7 @@ def moduser(method: str,
# Render the "Modify User" page
return TemplateResponse('moduser.html',
authuser=authuser, user=user, authlevel=authlevel,
+ receipt_preference_class=ReceiptPreference,
setupname=config['InstanceName'])
@@ -87,11 +88,19 @@ def handle_change(args: RequestArguments, user: User, authuser: User, db: Matema
# Admin requested update of the user's details
elif change == 'update':
# Only write a change if all properties of the user are present in the request arguments
- if 'username' not in args or 'email' not in args or 'password' not in args or 'balance' not in args:
+ if 'username' not in args or \
+ 'email' not in args or \
+ 'password' not in args or \
+ 'balance' not in args or \
+ 'receipt_pref' not in args:
return
# Read the properties from the request arguments
username = str(args.username)
email = str(args.email)
+ try:
+ receipt_pref = ReceiptPreference(int(str(args.receipt_pref)))
+ except ValueError:
+ return
password = str(args.password)
balance = parse_chf(str(args.balance))
is_member = 'ismember' in args
@@ -106,7 +115,7 @@ def handle_change(args: RequestArguments, user: User, authuser: User, db: Matema
db.change_password(user, '', password, verify_password=False)
# Write the user detail changes
db.change_user(user, agent=authuser, name=username, email=email, is_member=is_member, is_admin=is_admin,
- balance=balance)
+ balance=balance, receipt_pref=receipt_pref)
except DatabaseConsistencyError:
return
# If a new avatar was uploaded, process it
diff --git a/templates/admin_all.html b/templates/admin_all.html
index 56dba36..616f255 100644
--- a/templates/admin_all.html
+++ b/templates/admin_all.html
@@ -8,6 +8,14 @@
+
+
+
+
diff --git a/templates/moduser.html b/templates/moduser.html
index 187f4f4..cede6b5 100644
--- a/templates/moduser.html
+++ b/templates/moduser.html
@@ -20,6 +20,14 @@
+
+
+
+