Split the "accounting.transaction.template" module into the "accounting.transaction.template_filters" and "accounting.transaction.template_globals" modules.
This commit is contained in:
parent
9a41cb10a1
commit
9065686cc5
@ -26,7 +26,7 @@ from flask_wtf import FlaskForm
|
|||||||
from accounting.models import Transaction
|
from accounting.models import Transaction
|
||||||
from .forms import TransactionForm, IncomeTransactionForm, \
|
from .forms import TransactionForm, IncomeTransactionForm, \
|
||||||
ExpenseTransactionForm, TransferTransactionForm
|
ExpenseTransactionForm, TransferTransactionForm
|
||||||
from .template import default_currency_code
|
from .template_globals import default_currency_code
|
||||||
|
|
||||||
|
|
||||||
class TransactionType(ABC):
|
class TransactionType(ABC):
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""The template filters and globals for the transaction management.
|
"""The template filters for the transaction management.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
@ -23,11 +23,10 @@ from html import escape
|
|||||||
from urllib.parse import ParseResult, urlparse, parse_qsl, urlencode, \
|
from urllib.parse import ParseResult, urlparse, parse_qsl, urlencode, \
|
||||||
urlunparse
|
urlunparse
|
||||||
|
|
||||||
from flask import request, current_app
|
from flask import request
|
||||||
from flask_babel import get_locale
|
from flask_babel import get_locale
|
||||||
|
|
||||||
from accounting.locale import gettext
|
from accounting.locale import gettext
|
||||||
from accounting.models import Currency
|
|
||||||
|
|
||||||
|
|
||||||
def with_type(uri: str) -> str:
|
def with_type(uri: str) -> str:
|
||||||
@ -126,20 +125,3 @@ def text2html(value: str) -> str:
|
|||||||
s = s.replace("\n", "<br>")
|
s = s.replace("\n", "<br>")
|
||||||
s = s.replace(" ", " ")
|
s = s.replace(" ", " ")
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def currency_options() -> str:
|
|
||||||
"""Returns the currency options.
|
|
||||||
|
|
||||||
:return: The currency options.
|
|
||||||
"""
|
|
||||||
return Currency.query.order_by(Currency.code).all()
|
|
||||||
|
|
||||||
|
|
||||||
def default_currency_code() -> str:
|
|
||||||
"""Returns the default currency code.
|
|
||||||
|
|
||||||
:return: The default currency code.
|
|
||||||
"""
|
|
||||||
with current_app.app_context():
|
|
||||||
return current_app.config.get("DEFAULT_CURRENCY", "USD")
|
|
39
src/accounting/transaction/template_globals.py
Normal file
39
src/accounting/transaction/template_globals.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# The Mia! Accounting Flask Project.
|
||||||
|
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/3
|
||||||
|
|
||||||
|
# Copyright (c) 2023 imacat.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
"""The template globals for the transaction management.
|
||||||
|
|
||||||
|
"""
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
from accounting.models import Currency
|
||||||
|
|
||||||
|
|
||||||
|
def currency_options() -> str:
|
||||||
|
"""Returns the currency options.
|
||||||
|
|
||||||
|
:return: The currency options.
|
||||||
|
"""
|
||||||
|
return Currency.query.order_by(Currency.code).all()
|
||||||
|
|
||||||
|
|
||||||
|
def default_currency_code() -> str:
|
||||||
|
"""Returns the default currency code.
|
||||||
|
|
||||||
|
:return: The default currency code.
|
||||||
|
"""
|
||||||
|
with current_app.app_context():
|
||||||
|
return current_app.config.get("DEFAULT_CURRENCY", "USD")
|
@ -36,9 +36,9 @@ from accounting.utils.user import get_current_user_pk
|
|||||||
from .dispatcher import TransactionType, get_txn_type, TXN_TYPE_OBJ
|
from .dispatcher import TransactionType, get_txn_type, TXN_TYPE_OBJ
|
||||||
from .forms import sort_transactions_in, TransactionReorderForm
|
from .forms import sort_transactions_in, TransactionReorderForm
|
||||||
from .queries import get_transaction_query
|
from .queries import get_transaction_query
|
||||||
from .template import with_type, to_transfer, format_amount, \
|
from .template_filters import with_type, to_transfer, format_amount, \
|
||||||
format_amount_input, format_date, text2html, currency_options, \
|
format_amount_input, format_date, text2html
|
||||||
default_currency_code
|
from .template_globals import currency_options, default_currency_code
|
||||||
|
|
||||||
bp: Blueprint = Blueprint("transaction", __name__)
|
bp: Blueprint = Blueprint("transaction", __name__)
|
||||||
"""The view blueprint for the transaction management."""
|
"""The view blueprint for the transaction management."""
|
||||||
|
Loading…
Reference in New Issue
Block a user