Merged the "accounting.database" module into the "accounting" module. It has only one member as "db", the database instance, and does not need to be separated into another file.
This commit is contained in:
parent
e24ed61b99
commit
d99f592cff
@ -15,14 +15,6 @@ Subpackages
|
|||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
accounting.database module
|
|
||||||
--------------------------
|
|
||||||
|
|
||||||
.. automodule:: accounting.database
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
accounting.locale module
|
accounting.locale module
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
@ -21,9 +21,12 @@ import typing as t
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from flask import Flask, Blueprint
|
from flask import Flask, Blueprint
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
from accounting.utils.user import AbstractUserUtils
|
from accounting.utils.user import AbstractUserUtils
|
||||||
|
|
||||||
|
db: SQLAlchemy = SQLAlchemy()
|
||||||
|
"""The database instance."""
|
||||||
data_dir: Path = Path(__file__).parent / "data"
|
data_dir: Path = Path(__file__).parent / "data"
|
||||||
"""The data directory."""
|
"""The data directory."""
|
||||||
|
|
||||||
@ -45,8 +48,8 @@ def init_app(app: Flask, user_utils: AbstractUserUtils,
|
|||||||
"""
|
"""
|
||||||
# The database instance must be set before loading everything
|
# The database instance must be set before loading everything
|
||||||
# in the application.
|
# in the application.
|
||||||
from .database import set_db
|
global db
|
||||||
set_db(app.extensions["sqlalchemy"])
|
db = app.extensions["sqlalchemy"]
|
||||||
from .utils.user import init_user_utils
|
from .utils.user import init_user_utils
|
||||||
init_user_utils(user_utils)
|
init_user_utils(user_utils)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ from secrets import randbelow
|
|||||||
import click
|
import click
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import BaseAccount, Account, AccountL10n
|
from accounting.models import BaseAccount, Account, AccountL10n
|
||||||
from accounting.utils.user import has_user, get_user_pk
|
from accounting.utils.user import has_user, get_user_pk
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from flask_wtf import FlaskForm
|
|||||||
from wtforms import StringField, BooleanField
|
from wtforms import StringField, BooleanField
|
||||||
from wtforms.validators import DataRequired, ValidationError
|
from wtforms.validators import DataRequired, ValidationError
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.locale import lazy_gettext
|
from accounting.locale import lazy_gettext
|
||||||
from accounting.models import BaseAccount, Account
|
from accounting.models import BaseAccount, Account
|
||||||
from accounting.utils.random_id import new_id
|
from accounting.utils.random_id import new_id
|
||||||
|
@ -23,7 +23,7 @@ from flask import Blueprint, render_template, session, redirect, flash, \
|
|||||||
url_for, request
|
url_for, request
|
||||||
from werkzeug.datastructures import ImmutableMultiDict
|
from werkzeug.datastructures import ImmutableMultiDict
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.locale import lazy_gettext
|
from accounting.locale import lazy_gettext
|
||||||
from accounting.models import Account, BaseAccount
|
from accounting.models import Account, BaseAccount
|
||||||
from accounting.utils.next_url import inherit_next, or_next
|
from accounting.utils.next_url import inherit_next, or_next
|
||||||
|
@ -23,7 +23,7 @@ import click
|
|||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
from accounting import data_dir
|
from accounting import data_dir
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import BaseAccount, BaseAccountL10n
|
from accounting.models import BaseAccount, BaseAccountL10n
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
from flask import abort
|
from flask import abort
|
||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import BaseAccount
|
from accounting.models import BaseAccount
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ import typing as t
|
|||||||
import click
|
import click
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
from accounting import data_dir
|
from accounting import db, data_dir
|
||||||
from accounting.database import db
|
|
||||||
from accounting.models import Currency, CurrencyL10n
|
from accounting.models import Currency, CurrencyL10n
|
||||||
from accounting.utils.user import has_user, get_user_pk
|
from accounting.utils.user import has_user, get_user_pk
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
from flask import abort
|
from flask import abort
|
||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ from flask_wtf import FlaskForm
|
|||||||
from wtforms import StringField, ValidationError
|
from wtforms import StringField, ValidationError
|
||||||
from wtforms.validators import DataRequired, Regexp, NoneOf
|
from wtforms.validators import DataRequired, Regexp, NoneOf
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.locale import lazy_gettext
|
from accounting.locale import lazy_gettext
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
from accounting.utils.strip_text import strip_text
|
from accounting.utils.strip_text import strip_text
|
||||||
|
@ -23,7 +23,7 @@ from flask import Blueprint, render_template, redirect, session, request, \
|
|||||||
flash, url_for
|
flash, url_for
|
||||||
from werkzeug.datastructures import ImmutableMultiDict
|
from werkzeug.datastructures import ImmutableMultiDict
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.locale import lazy_gettext
|
from accounting.locale import lazy_gettext
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
from accounting.utils.next_url import inherit_next, or_next
|
from accounting.utils.next_url import inherit_next, or_next
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
# The Mia! Accounting Flask Project.
|
|
||||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/1/25
|
|
||||||
|
|
||||||
# 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 database instance factory for the base account management.
|
|
||||||
|
|
||||||
This is to overcome the problem that the database instance needs to be
|
|
||||||
initialized at compile time, but as a submodule it is only available at run
|
|
||||||
time.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
|
|
||||||
db: SQLAlchemy = SQLAlchemy()
|
|
||||||
"""The database instance."""
|
|
||||||
|
|
||||||
|
|
||||||
def set_db(new_db: SQLAlchemy) -> None:
|
|
||||||
"""Sets the database instance.
|
|
||||||
|
|
||||||
:param new_db: The database instance.
|
|
||||||
:return: None.
|
|
||||||
"""
|
|
||||||
global db
|
|
||||||
db = new_db
|
|
@ -25,7 +25,7 @@ from flask import current_app
|
|||||||
from flask_babel import get_locale
|
from flask_babel import get_locale
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.utils.user import user_cls, user_pk_column
|
from accounting.utils.user import user_cls, user_pk_column
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ This module should not import any other module from the application.
|
|||||||
import typing as t
|
import typing as t
|
||||||
from secrets import randbelow
|
from secrets import randbelow
|
||||||
|
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
|
|
||||||
|
|
||||||
def new_id(cls: t.Type):
|
def new_id(cls: t.Type):
|
||||||
|
@ -75,7 +75,7 @@ class AccountCommandTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
runner: FlaskCliRunner = self.app.test_cli_runner()
|
runner: FlaskCliRunner = self.app.test_cli_runner()
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import BaseAccount, Account, AccountL10n
|
from accounting.models import BaseAccount, Account, AccountL10n
|
||||||
result: Result
|
result: Result
|
||||||
result = runner.invoke(args="init-db")
|
result = runner.invoke(args="init-db")
|
||||||
@ -129,7 +129,7 @@ class AccountTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
runner: FlaskCliRunner = self.app.test_cli_runner()
|
runner: FlaskCliRunner = self.app.test_cli_runner()
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import BaseAccount, Account, AccountL10n
|
from accounting.models import BaseAccount, Account, AccountL10n
|
||||||
result: Result
|
result: Result
|
||||||
result = runner.invoke(args="init-db")
|
result = runner.invoke(args="init-db")
|
||||||
@ -316,7 +316,7 @@ class AccountTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
:return: None.
|
:return: None.
|
||||||
"""
|
"""
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import Account
|
from accounting.models import Account
|
||||||
create_uri: str = f"{PREFIX}/create"
|
create_uri: str = f"{PREFIX}/create"
|
||||||
store_uri: str = f"{PREFIX}/store"
|
store_uri: str = f"{PREFIX}/store"
|
||||||
@ -648,7 +648,7 @@ class AccountTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
:return: None.
|
:return: None.
|
||||||
"""
|
"""
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import Account
|
from accounting.models import Account
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class CurrencyCommandTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
runner: FlaskCliRunner = self.app.test_cli_runner()
|
runner: FlaskCliRunner = self.app.test_cli_runner()
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import Currency, CurrencyL10n
|
from accounting.models import Currency, CurrencyL10n
|
||||||
result: Result
|
result: Result
|
||||||
result = runner.invoke(args="init-db")
|
result = runner.invoke(args="init-db")
|
||||||
@ -128,7 +128,7 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
runner: FlaskCliRunner = self.app.test_cli_runner()
|
runner: FlaskCliRunner = self.app.test_cli_runner()
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
from accounting.database import db
|
from accounting import db
|
||||||
from accounting.models import Currency, CurrencyL10n
|
from accounting.models import Currency, CurrencyL10n
|
||||||
result: Result
|
result: Result
|
||||||
result = runner.invoke(args="init-db")
|
result = runner.invoke(args="init-db")
|
||||||
|
Loading…
Reference in New Issue
Block a user