Added the is_check_as parameter to the get_txn_op function so that the "as" query parameter is not checked when showing the transaction detail.

This commit is contained in:
依瑪貓 2023-03-09 22:04:21 +08:00
parent be46d8aa14
commit 3fa8818a27
2 changed files with 7 additions and 5 deletions

View File

@ -304,15 +304,17 @@ TXN_TYPE_TO_OP: dict[TransactionType, TransactionOperator] \
"""The map from the transaction types to their operators."""
def get_txn_op(txn: Transaction) -> TransactionOperator:
def get_txn_op(txn: Transaction, is_check_as: bool = False) \
-> TransactionOperator:
"""Returns the transaction operator that may be specified in the "as" query
parameter. If it is not specified, check the transaction type from the
transaction.
transaction.
:param txn: The transaction.
:param is_check_as: True to check the "as" parameter, or False otherwise.
:return: None.
"""
if "as" in request.args:
if is_check_as and "as" in request.args:
type_dict: dict[str, TransactionType] \
= {x.value: x for x in TransactionType}
if request.args["as"] not in type_dict:

View File

@ -111,7 +111,7 @@ def show_transaction_edit_form(txn: Transaction) -> str:
:param txn: The transaction.
:return: The form to edit the transaction.
"""
txn_op: TransactionOperator = get_txn_op(txn)
txn_op: TransactionOperator = get_txn_op(txn, is_check_as=True)
form: txn_op.form
if "form" in session:
form = txn_op.form(ImmutableMultiDict(parse_qsl(session["form"])))
@ -131,7 +131,7 @@ def update_transaction(txn: Transaction) -> redirect:
:return: The redirection to the transaction detail on success, or the
transaction edit form on error.
"""
txn_op: TransactionOperator = get_txn_op(txn)
txn_op: TransactionOperator = get_txn_op(txn, is_check_as=True)
form: txn_op.form = txn_op.form(request.form)
if not form.validate():
flash_form_errors(form)