From cb89f34455ae7a319dec9021c69abbad0864538a 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 17:27:19 +0800 Subject: [PATCH] Renamed the "PageParams" class to "BasePageParams", and renamed its module from "accounting.report.reports.utils.page_params" to "accounting.report.reports.utils.base_page_params". Renamed all its subclasses to PageParams, to shorten their names and make code more readable. --- .../report/reports/balance_sheet.py | 21 ++++++++-------- .../report/reports/income_expenses.py | 25 +++++++++---------- .../report/reports/income_statement.py | 17 ++++++------- src/accounting/report/reports/journal.py | 15 ++++++----- src/accounting/report/reports/ledger.py | 25 +++++++++---------- src/accounting/report/reports/search.py | 12 ++++----- .../report/reports/trial_balance.py | 17 ++++++------- .../{page_params.py => base_page_params.py} | 4 +-- 8 files changed, 65 insertions(+), 71 deletions(-) rename src/accounting/report/reports/utils/{page_params.py => base_page_params.py} (96%) diff --git a/src/accounting/report/reports/balance_sheet.py b/src/accounting/report/reports/balance_sheet.py index f795ce6..e34c20c 100644 --- a/src/accounting/report/reports/balance_sheet.py +++ b/src/accounting/report/reports/balance_sheet.py @@ -30,7 +30,7 @@ from accounting.report.period import Period from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.option_link import OptionLink -from .utils.page_params import PageParams +from .utils.base_page_params import BasePageParams from .utils.period_choosers import BalanceSheetPeriodChooser from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType @@ -297,8 +297,8 @@ class CSVRow(BaseCSVRow): self.liability_title, self.liability_amount] -class BalanceSheetPageParams(PageParams): - """The HTML parameters of the balance sheet.""" +class PageParams(BasePageParams): + """The HTML page parameters.""" def __init__(self, currency: Currency, period: Period, @@ -306,7 +306,7 @@ class BalanceSheetPageParams(PageParams): assets: BalanceSheetSection, liabilities: BalanceSheetSection, owner_s_equity: BalanceSheetSection): - """Constructs the HTML parameters of the balance sheet. + """Constructs the HTML page parameters. :param currency: The currency. :param period: The period. @@ -485,12 +485,11 @@ class BalanceSheet(BaseReport): :return: The report as HTML. """ - params: BalanceSheetPageParams = BalanceSheetPageParams( - currency=self.__currency, - period=self.__period, - has_data=self.__has_data, - assets=self.__assets, - liabilities=self.__liabilities, - owner_s_equity=self.__owner_s_equity) + params: PageParams = PageParams(currency=self.__currency, + period=self.__period, + has_data=self.__has_data, + assets=self.__assets, + liabilities=self.__liabilities, + owner_s_equity=self.__owner_s_equity) return render_template("accounting/report/balance-sheet.html", report=params) diff --git a/src/accounting/report/reports/income_expenses.py b/src/accounting/report/reports/income_expenses.py index 8d3b7a6..b6ff367 100644 --- a/src/accounting/report/reports/income_expenses.py +++ b/src/accounting/report/reports/income_expenses.py @@ -32,7 +32,7 @@ from accounting.utils.pagination import Pagination from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.option_link import OptionLink -from .utils.page_params import PageParams +from .utils.base_page_params import BasePageParams from .utils.period_choosers import IncomeExpensesPeriodChooser from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType @@ -246,8 +246,8 @@ class CSVRow(BaseCSVRow): self.income, self.expense, self.balance, self.note] -class IncomeExpensesPageParams(PageParams): - """The HTML parameters of the income and expenses log.""" +class PageParams(BasePageParams): + """The HTML page parameters.""" def __init__(self, currency: Currency, account: IncomeExpensesAccount, @@ -257,7 +257,7 @@ class IncomeExpensesPageParams(PageParams): brought_forward: Entry | None, entries: list[Entry], total: Entry | None): - """Constructs the HTML parameters of the income and expenses log. + """Constructs the HTML page parameters. :param currency: The currency. :param account: The account. @@ -474,14 +474,13 @@ class IncomeExpenses(BaseReport): if len(page_entries) > 0 and page_entries[-1].is_total: total = page_entries[-1] page_entries = page_entries[:-1] - params: IncomeExpensesPageParams = IncomeExpensesPageParams( - currency=self.__currency, - account=self.__account, - period=self.__period, - has_data=has_data, - pagination=pagination, - brought_forward=brought_forward, - entries=page_entries, - total=total) + params: PageParams = PageParams(currency=self.__currency, + account=self.__account, + period=self.__period, + has_data=has_data, + pagination=pagination, + brought_forward=brought_forward, + entries=page_entries, + total=total) return render_template("accounting/report/income-expenses.html", report=params) diff --git a/src/accounting/report/reports/income_statement.py b/src/accounting/report/reports/income_statement.py index d7524a3..e0a898c 100644 --- a/src/accounting/report/reports/income_statement.py +++ b/src/accounting/report/reports/income_statement.py @@ -30,7 +30,7 @@ from accounting.report.period import Period from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.option_link import OptionLink -from .utils.page_params import PageParams +from .utils.base_page_params import BasePageParams from .utils.period_choosers import IncomeStatementPeriodChooser from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType @@ -138,14 +138,14 @@ class CSVRow(BaseCSVRow): return [self.text, self.amount] -class IncomeStatementPageParams(PageParams): - """The HTML parameters of the income statement.""" +class PageParams(BasePageParams): + """The HTML page parameters.""" def __init__(self, currency: Currency, period: Period, has_data: bool, sections: list[IncomeStatementSection],): - """Constructs the HTML parameters of the income statement. + """Constructs the HTML page parameters. :param currency: The currency. :param period: The period. @@ -340,10 +340,9 @@ class IncomeStatement(BaseReport): :return: The report as HTML. """ - params: IncomeStatementPageParams = IncomeStatementPageParams( - currency=self.__currency, - period=self.__period, - has_data=self.__has_data, - sections=self.__sections) + params: PageParams = PageParams(currency=self.__currency, + period=self.__period, + has_data=self.__has_data, + sections=self.__sections) return render_template("accounting/report/income-statement.html", report=params) diff --git a/src/accounting/report/reports/journal.py b/src/accounting/report/reports/journal.py index bcafcc3..f5ae8dc 100644 --- a/src/accounting/report/reports/journal.py +++ b/src/accounting/report/reports/journal.py @@ -30,7 +30,7 @@ from accounting.report.period import Period from accounting.utils.pagination import Pagination from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download, period_spec -from .utils.page_params import PageParams +from .utils.base_page_params import BasePageParams from .utils.period_choosers import JournalPeriodChooser from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType @@ -113,13 +113,13 @@ class CSVRow(BaseCSVRow): self.debit, self.credit, self.note] -class JournalPageParams(PageParams): - """The HTML parameters of the journal.""" +class PageParams(BasePageParams): + """The HTML page parameters.""" def __init__(self, period: Period, pagination: Pagination[Entry], entries: list[Entry]): - """Constructs the HTML parameters of the journal. + """Constructs the HTML page parameters. :param period: The period. :param entries: The journal entries. @@ -235,9 +235,8 @@ class Journal(BaseReport): pagination: Pagination[Entry] = Pagination[Entry](self.__entries) page_entries: list[Entry] = pagination.list _populate_entries(page_entries) - params: JournalPageParams = JournalPageParams( - period=self.__period, - pagination=pagination, - entries=page_entries) + params: PageParams = PageParams(period=self.__period, + pagination=pagination, + entries=page_entries) return render_template("accounting/report/journal.html", report=params) diff --git a/src/accounting/report/reports/ledger.py b/src/accounting/report/reports/ledger.py index 2dc9bfe..f6fef16 100644 --- a/src/accounting/report/reports/ledger.py +++ b/src/accounting/report/reports/ledger.py @@ -31,7 +31,7 @@ from accounting.utils.pagination import Pagination from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.option_link import OptionLink -from .utils.page_params import PageParams +from .utils.base_page_params import BasePageParams from .utils.period_choosers import LedgerPeriodChooser from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType @@ -223,8 +223,8 @@ class CSVRow(BaseCSVRow): self.debit, self.credit, self.balance, self.note] -class LedgerPageParams(PageParams): - """The HTML parameters of the ledger.""" +class PageParams(BasePageParams): + """The HTML page parameters.""" def __init__(self, currency: Currency, account: Account, @@ -234,7 +234,7 @@ class LedgerPageParams(PageParams): brought_forward: Entry | None, entries: list[Entry], total: Entry | None): - """Constructs the HTML parameters of the ledger. + """Constructs the HTML page parameters. :param currency: The currency. :param account: The account. @@ -426,14 +426,13 @@ class Ledger(BaseReport): if len(page_entries) > 0 and page_entries[-1].is_total: total = page_entries[-1] page_entries = page_entries[:-1] - params: LedgerPageParams = LedgerPageParams( - currency=self.__currency, - account=self.__account, - period=self.__period, - has_data=has_data, - pagination=pagination, - brought_forward=brought_forward, - entries=page_entries, - total=total) + params: PageParams = PageParams(currency=self.__currency, + account=self.__account, + period=self.__period, + has_data=has_data, + pagination=pagination, + brought_forward=brought_forward, + entries=page_entries, + total=total) return render_template("accounting/report/ledger.html", report=params) diff --git a/src/accounting/report/reports/search.py b/src/accounting/report/reports/search.py index 94b387c..c046fcb 100644 --- a/src/accounting/report/reports/search.py +++ b/src/accounting/report/reports/search.py @@ -30,7 +30,7 @@ from accounting.utils.pagination import Pagination from accounting.utils.query import parse_query_keywords from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download -from .utils.page_params import PageParams +from .utils.base_page_params import BasePageParams from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType @@ -112,12 +112,12 @@ class CSVRow(BaseCSVRow): self.debit, self.credit, self.note] -class SearchPageParams(PageParams): - """The HTML parameters of the search result.""" +class PageParams(BasePageParams): + """The HTML page parameters.""" def __init__(self, pagination: Pagination[Entry], entries: list[Entry]): - """Constructs the HTML parameters of the search result. + """Constructs the HTML page parameters. :param entries: The search result entries. """ @@ -297,7 +297,7 @@ class Search(BaseReport): pagination: Pagination[Entry] = Pagination[Entry](self.__entries) page_entries: list[Entry] = pagination.list _populate_entries(page_entries) - params: SearchPageParams = SearchPageParams(pagination=pagination, - entries=page_entries) + params: PageParams = PageParams(pagination=pagination, + entries=page_entries) return render_template("accounting/report/search.html", report=params) diff --git a/src/accounting/report/reports/trial_balance.py b/src/accounting/report/reports/trial_balance.py index 0b086e9..4f5a8ec 100644 --- a/src/accounting/report/reports/trial_balance.py +++ b/src/accounting/report/reports/trial_balance.py @@ -29,7 +29,7 @@ from accounting.report.period import Period from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.option_link import OptionLink -from .utils.page_params import PageParams +from .utils.base_page_params import BasePageParams from .utils.period_choosers import TrialBalancePeriodChooser from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType @@ -98,14 +98,14 @@ class CSVRow(BaseCSVRow): return [self.text, self.debit, self.credit] -class TrialBalancePageParams(PageParams): - """The HTML parameters of the trial balance.""" +class PageParams(BasePageParams): + """The HTML page parameters.""" def __init__(self, currency: Currency, period: Period, accounts: list[TrialBalanceAccount], total: TrialBalanceTotal): - """Constructs the HTML parameters of the trial balance. + """Constructs the HTML page parameters. :param currency: The currency. :param period: The period. @@ -256,10 +256,9 @@ class TrialBalance(BaseReport): :return: The report as HTML. """ - params: TrialBalancePageParams = TrialBalancePageParams( - currency=self.__currency, - period=self.__period, - accounts=self.__accounts, - total=self.__total) + params: PageParams = PageParams(currency=self.__currency, + period=self.__period, + accounts=self.__accounts, + total=self.__total) return render_template("accounting/report/trial-balance.html", report=params) diff --git a/src/accounting/report/reports/utils/page_params.py b/src/accounting/report/reports/utils/base_page_params.py similarity index 96% rename from src/accounting/report/reports/utils/page_params.py rename to src/accounting/report/reports/utils/base_page_params.py index baf7044..60b27df 100644 --- a/src/accounting/report/reports/utils/page_params.py +++ b/src/accounting/report/reports/utils/base_page_params.py @@ -28,8 +28,8 @@ from accounting.utils.txn_types import TransactionType from .report_chooser import ReportChooser -class PageParams(ABC): - """The page parameters of a report.""" +class BasePageParams(ABC): + """The base HTML page parameters class.""" @property @abstractmethod