From ffe834bedd4876a085146870b4d4ce24d6264b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 8 Mar 2023 19:34:23 +0800 Subject: [PATCH] Added the DATE_REQUIRED constant to the "accounting.transaction.forms" module as the common date field validator. --- src/accounting/transaction/forms.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/accounting/transaction/forms.py b/src/accounting/transaction/forms.py index 904ab6c..671163a 100644 --- a/src/accounting/transaction/forms.py +++ b/src/accounting/transaction/forms.py @@ -46,6 +46,9 @@ MISSING_CURRENCY: LazyString = lazy_gettext("Please select the currency.") """The error message when the currency code is empty.""" MISSING_ACCOUNT: LazyString = lazy_gettext("Please select the account.") """The error message when the account code is empty.""" +DATE_REQUIRED: DataRequired = DataRequired( + lazy_gettext("Please fill in the date.")) +"""The validator to check if the date is empty.""" class NeedSomeCurrencies: @@ -574,8 +577,7 @@ class IncomeCurrencyForm(CurrencyForm): class IncomeTransactionForm(TransactionForm): """The form to create or edit a cash income transaction.""" - date = DateField( - validators=[DataRequired(lazy_gettext("Please fill in the date."))]) + date = DateField(validators=[DATE_REQUIRED]) """The date.""" currencies = FieldList(FormField(IncomeCurrencyForm), name="currency", validators=[NeedSomeCurrencies()]) @@ -648,8 +650,7 @@ class ExpenseCurrencyForm(CurrencyForm): class ExpenseTransactionForm(TransactionForm): """The form to create or edit a cash expense transaction.""" - date = DateField( - validators=[DataRequired(lazy_gettext("Please fill in the date."))]) + date = DateField(validators=[DATE_REQUIRED]) """The date.""" currencies = FieldList(FormField(ExpenseCurrencyForm), name="currency", validators=[NeedSomeCurrencies()]) @@ -758,8 +759,7 @@ class TransferCurrencyForm(CurrencyForm): class TransferTransactionForm(TransactionForm): """The form to create or edit a transfer transaction.""" - date = DateField( - validators=[DataRequired(lazy_gettext("Please fill in the date."))]) + date = DateField(validators=[DATE_REQUIRED]) """The date.""" currencies = FieldList(FormField(TransferCurrencyForm), name="currency", validators=[NeedSomeCurrencies()])