From 1a27d8740082d1a63a6daf220c839a8d94e0c3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 31 Jul 2020 00:14:12 +0800 Subject: [PATCH] Added the strip_form() utility to the Mia core application, and apply it to the transaction_store() view of the accounting application. --- accounting/views.py | 4 +++- mia_core/utils.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/accounting/views.py b/accounting/views.py index 5b92699..b84e68d 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -34,7 +34,8 @@ from django.views.generic import RedirectView from mia_core.digest_auth import login_required from mia_core.period import Period from mia_core.status import success_redirect, error_redirect -from mia_core.utils import Pagination, get_multi_lingual_search, UrlBuilder +from mia_core.utils import Pagination, get_multi_lingual_search, UrlBuilder, \ + strip_form from .models import Record, Transaction, Account, RecordSummary from .utils import ReportUrl, get_cash_accounts, get_ledger_accounts, \ find_imbalanced, find_order_holes, fill_transaction_from_form, \ @@ -848,6 +849,7 @@ def transaction_store(request, txn_type, transaction=None): if transaction is None: transaction = Transaction() form = request.POST.dict() + strip_form(form) sort_form_transaction_records(form) fill_transaction_from_form(transaction, form) errors = {} diff --git a/mia_core/utils.py b/mia_core/utils.py index 3551535..eaa32d5 100644 --- a/mia_core/utils.py +++ b/mia_core/utils.py @@ -43,6 +43,16 @@ def new_pk(cls): return id +def strip_form(form): + """Strips the values of a form. Empty strings are converted to None. + + Args: + form (dict[str]): The form. + """ + for key in form.keys(): + form[key] = form[key].strip() + + class Language: """A language.