Integration of ReceiptPreference into the UI.
This commit is contained in:
parent
0adba41c8d
commit
c26e0ffc21
5 changed files with 55 additions and 10 deletions
|
@ -6,22 +6,37 @@ class ReceiptPreference(Enum):
|
||||||
A user's preference for the frequency of receiving receipts.
|
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.
|
No receipts should be generated.
|
||||||
"""
|
"""
|
||||||
NONE = 0
|
NONE = 0, 'No receipts'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A receipt should be generated for each transaction.
|
A receipt should be generated for each transaction.
|
||||||
"""
|
"""
|
||||||
EACH = 1
|
EACH = 1, 'Individual receipt per transaction'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A receipt should be generated once a month.
|
A receipt should be generated once a month.
|
||||||
"""
|
"""
|
||||||
MONTHLY = 2
|
MONTHLY = 2, 'Aggregated, monthly'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A receipt should be generated once a year.
|
A receipt should be generated once a year.
|
||||||
"""
|
"""
|
||||||
YEARLY = 3
|
YEARLY = 3, 'Aggregated, yearly'
|
||||||
|
|
|
@ -5,7 +5,7 @@ import magic
|
||||||
|
|
||||||
from matemat.webserver import pagelet, RequestArguments, PageletResponse, RedirectResponse, TemplateResponse
|
from matemat.webserver import pagelet, RequestArguments, PageletResponse, RedirectResponse, TemplateResponse
|
||||||
from matemat.db import MatematDatabase
|
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.exceptions import DatabaseConsistencyError, HttpException
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ def admin(method: str,
|
||||||
# Render the "Admin/Settings" page
|
# Render the "Admin/Settings" page
|
||||||
return TemplateResponse('admin.html',
|
return TemplateResponse('admin.html',
|
||||||
authuser=user, authlevel=authlevel, users=users, products=products,
|
authuser=user, authlevel=authlevel, users=users, products=products,
|
||||||
|
receipt_preference_class=ReceiptPreference,
|
||||||
setupname=config['InstanceName'])
|
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
|
# An empty e-mail field should be interpreted as NULL
|
||||||
if len(email) == 0:
|
if len(email) == 0:
|
||||||
email = None
|
email = None
|
||||||
# Attempt to update username and e-mail
|
|
||||||
try:
|
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:
|
except DatabaseConsistencyError:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import magic
|
||||||
|
|
||||||
from matemat.webserver import pagelet, RequestArguments, PageletResponse, RedirectResponse, TemplateResponse
|
from matemat.webserver import pagelet, RequestArguments, PageletResponse, RedirectResponse, TemplateResponse
|
||||||
from matemat.db import MatematDatabase
|
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.exceptions import DatabaseConsistencyError, HttpException
|
||||||
from matemat.util.currency_format import parse_chf
|
from matemat.util.currency_format import parse_chf
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ def moduser(method: str,
|
||||||
# Render the "Modify User" page
|
# Render the "Modify User" page
|
||||||
return TemplateResponse('moduser.html',
|
return TemplateResponse('moduser.html',
|
||||||
authuser=authuser, user=user, authlevel=authlevel,
|
authuser=authuser, user=user, authlevel=authlevel,
|
||||||
|
receipt_preference_class=ReceiptPreference,
|
||||||
setupname=config['InstanceName'])
|
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
|
# Admin requested update of the user's details
|
||||||
elif change == 'update':
|
elif change == 'update':
|
||||||
# Only write a change if all properties of the user are present in the request arguments
|
# 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
|
return
|
||||||
# Read the properties from the request arguments
|
# Read the properties from the request arguments
|
||||||
username = str(args.username)
|
username = str(args.username)
|
||||||
email = str(args.email)
|
email = str(args.email)
|
||||||
|
try:
|
||||||
|
receipt_pref = ReceiptPreference(int(str(args.receipt_pref)))
|
||||||
|
except ValueError:
|
||||||
|
return
|
||||||
password = str(args.password)
|
password = str(args.password)
|
||||||
balance = parse_chf(str(args.balance))
|
balance = parse_chf(str(args.balance))
|
||||||
is_member = 'ismember' in args
|
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)
|
db.change_password(user, '', password, verify_password=False)
|
||||||
# Write the user detail changes
|
# Write the user detail changes
|
||||||
db.change_user(user, agent=authuser, name=username, email=email, is_member=is_member, is_admin=is_admin,
|
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:
|
except DatabaseConsistencyError:
|
||||||
return
|
return
|
||||||
# If a new avatar was uploaded, process it
|
# If a new avatar was uploaded, process it
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
<label for="admin-myaccount-email">E-Mail: </label>
|
<label for="admin-myaccount-email">E-Mail: </label>
|
||||||
<input id="admin-myaccount-email" type="text" name="email" value="{% if authuser.email is not none %}{{ authuser.email }}{% endif %}" /><br/>
|
<input id="admin-myaccount-email" type="text" name="email" value="{% if authuser.email is not none %}{{ authuser.email }}{% endif %}" /><br/>
|
||||||
|
|
||||||
|
<label for="admin-myaccount-receipt-pref">Receipts: </label>
|
||||||
|
<select id="admin-myaccount-receipt-pref" name="receipt_pref">
|
||||||
|
{% for pref in receipt_preference_class %}
|
||||||
|
<option value="{{ pref.value }}" {% if authuser.receipt_pref == pref %} selected="selected" {% endif %}>{{ pref.human_readable }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<br/>
|
||||||
|
|
||||||
<label for="admin-myaccount-ismember">Member: </label>
|
<label for="admin-myaccount-ismember">Member: </label>
|
||||||
<input id="admin-myaccount-ismember" type="checkbox" disabled="disabled" {% if authuser.is_member %} checked="checked" {% endif %}/><br/>
|
<input id="admin-myaccount-ismember" type="checkbox" disabled="disabled" {% if authuser.is_member %} checked="checked" {% endif %}/><br/>
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,14 @@
|
||||||
<label for="moduser-account-password">Password: </label>
|
<label for="moduser-account-password">Password: </label>
|
||||||
<input id="moduser-account-password" type="password" name="password" /><br/>
|
<input id="moduser-account-password" type="password" name="password" /><br/>
|
||||||
|
|
||||||
|
<label for="moduser-account-receipt-pref">Receipts: </label>
|
||||||
|
<select id="moduser-account-receipt-pref" name="receipt_pref">
|
||||||
|
{% for pref in receipt_preference_class %}
|
||||||
|
<option value="{{ pref.value }}" {% if user.receipt_pref == pref %} selected="selected" {% endif %}>{{ pref.human_readable }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<br/>
|
||||||
|
|
||||||
<label for="moduser-account-ismember">Member: </label>
|
<label for="moduser-account-ismember">Member: </label>
|
||||||
<input id="moduser-account-ismember" name="ismember" type="checkbox" {% if user.is_member %} checked="checked" {% endif %}/><br/>
|
<input id="moduser-account-ismember" name="ismember" type="checkbox" {% if user.is_member %} checked="checked" {% endif %}/><br/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue