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.

This commit is contained in:
依瑪貓 2023-03-08 17:27:19 +08:00
parent 11ab4a4ba6
commit cb89f34455
8 changed files with 65 additions and 71 deletions

View File

@ -30,7 +30,7 @@ from accounting.report.period import Period
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.option_link import OptionLink 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.period_choosers import BalanceSheetPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
@ -297,8 +297,8 @@ class CSVRow(BaseCSVRow):
self.liability_title, self.liability_amount] self.liability_title, self.liability_amount]
class BalanceSheetPageParams(PageParams): class PageParams(BasePageParams):
"""The HTML parameters of the balance sheet.""" """The HTML page parameters."""
def __init__(self, currency: Currency, def __init__(self, currency: Currency,
period: Period, period: Period,
@ -306,7 +306,7 @@ class BalanceSheetPageParams(PageParams):
assets: BalanceSheetSection, assets: BalanceSheetSection,
liabilities: BalanceSheetSection, liabilities: BalanceSheetSection,
owner_s_equity: BalanceSheetSection): owner_s_equity: BalanceSheetSection):
"""Constructs the HTML parameters of the balance sheet. """Constructs the HTML page parameters.
:param currency: The currency. :param currency: The currency.
:param period: The period. :param period: The period.
@ -485,12 +485,11 @@ class BalanceSheet(BaseReport):
:return: The report as HTML. :return: The report as HTML.
""" """
params: BalanceSheetPageParams = BalanceSheetPageParams( params: PageParams = PageParams(currency=self.__currency,
currency=self.__currency, period=self.__period,
period=self.__period, has_data=self.__has_data,
has_data=self.__has_data, assets=self.__assets,
assets=self.__assets, liabilities=self.__liabilities,
liabilities=self.__liabilities, owner_s_equity=self.__owner_s_equity)
owner_s_equity=self.__owner_s_equity)
return render_template("accounting/report/balance-sheet.html", return render_template("accounting/report/balance-sheet.html",
report=params) report=params)

View File

@ -32,7 +32,7 @@ from accounting.utils.pagination import Pagination
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.option_link import OptionLink 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.period_choosers import IncomeExpensesPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
@ -246,8 +246,8 @@ class CSVRow(BaseCSVRow):
self.income, self.expense, self.balance, self.note] self.income, self.expense, self.balance, self.note]
class IncomeExpensesPageParams(PageParams): class PageParams(BasePageParams):
"""The HTML parameters of the income and expenses log.""" """The HTML page parameters."""
def __init__(self, currency: Currency, def __init__(self, currency: Currency,
account: IncomeExpensesAccount, account: IncomeExpensesAccount,
@ -257,7 +257,7 @@ class IncomeExpensesPageParams(PageParams):
brought_forward: Entry | None, brought_forward: Entry | None,
entries: list[Entry], entries: list[Entry],
total: Entry | None): total: Entry | None):
"""Constructs the HTML parameters of the income and expenses log. """Constructs the HTML page parameters.
:param currency: The currency. :param currency: The currency.
:param account: The account. :param account: The account.
@ -474,14 +474,13 @@ class IncomeExpenses(BaseReport):
if len(page_entries) > 0 and page_entries[-1].is_total: if len(page_entries) > 0 and page_entries[-1].is_total:
total = page_entries[-1] total = page_entries[-1]
page_entries = page_entries[:-1] page_entries = page_entries[:-1]
params: IncomeExpensesPageParams = IncomeExpensesPageParams( params: PageParams = PageParams(currency=self.__currency,
currency=self.__currency, account=self.__account,
account=self.__account, period=self.__period,
period=self.__period, has_data=has_data,
has_data=has_data, pagination=pagination,
pagination=pagination, brought_forward=brought_forward,
brought_forward=brought_forward, entries=page_entries,
entries=page_entries, total=total)
total=total)
return render_template("accounting/report/income-expenses.html", return render_template("accounting/report/income-expenses.html",
report=params) report=params)

View File

@ -30,7 +30,7 @@ from accounting.report.period import Period
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.option_link import OptionLink 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.period_choosers import IncomeStatementPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
@ -138,14 +138,14 @@ class CSVRow(BaseCSVRow):
return [self.text, self.amount] return [self.text, self.amount]
class IncomeStatementPageParams(PageParams): class PageParams(BasePageParams):
"""The HTML parameters of the income statement.""" """The HTML page parameters."""
def __init__(self, currency: Currency, def __init__(self, currency: Currency,
period: Period, period: Period,
has_data: bool, has_data: bool,
sections: list[IncomeStatementSection],): sections: list[IncomeStatementSection],):
"""Constructs the HTML parameters of the income statement. """Constructs the HTML page parameters.
:param currency: The currency. :param currency: The currency.
:param period: The period. :param period: The period.
@ -340,10 +340,9 @@ class IncomeStatement(BaseReport):
:return: The report as HTML. :return: The report as HTML.
""" """
params: IncomeStatementPageParams = IncomeStatementPageParams( params: PageParams = PageParams(currency=self.__currency,
currency=self.__currency, period=self.__period,
period=self.__period, has_data=self.__has_data,
has_data=self.__has_data, sections=self.__sections)
sections=self.__sections)
return render_template("accounting/report/income-statement.html", return render_template("accounting/report/income-statement.html",
report=params) report=params)

View File

@ -30,7 +30,7 @@ from accounting.report.period import Period
from accounting.utils.pagination import Pagination from accounting.utils.pagination import Pagination
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec 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.period_choosers import JournalPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
@ -113,13 +113,13 @@ class CSVRow(BaseCSVRow):
self.debit, self.credit, self.note] self.debit, self.credit, self.note]
class JournalPageParams(PageParams): class PageParams(BasePageParams):
"""The HTML parameters of the journal.""" """The HTML page parameters."""
def __init__(self, period: Period, def __init__(self, period: Period,
pagination: Pagination[Entry], pagination: Pagination[Entry],
entries: list[Entry]): entries: list[Entry]):
"""Constructs the HTML parameters of the journal. """Constructs the HTML page parameters.
:param period: The period. :param period: The period.
:param entries: The journal entries. :param entries: The journal entries.
@ -235,9 +235,8 @@ class Journal(BaseReport):
pagination: Pagination[Entry] = Pagination[Entry](self.__entries) pagination: Pagination[Entry] = Pagination[Entry](self.__entries)
page_entries: list[Entry] = pagination.list page_entries: list[Entry] = pagination.list
_populate_entries(page_entries) _populate_entries(page_entries)
params: JournalPageParams = JournalPageParams( params: PageParams = PageParams(period=self.__period,
period=self.__period, pagination=pagination,
pagination=pagination, entries=page_entries)
entries=page_entries)
return render_template("accounting/report/journal.html", return render_template("accounting/report/journal.html",
report=params) report=params)

View File

@ -31,7 +31,7 @@ from accounting.utils.pagination import Pagination
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.option_link import OptionLink 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.period_choosers import LedgerPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
@ -223,8 +223,8 @@ class CSVRow(BaseCSVRow):
self.debit, self.credit, self.balance, self.note] self.debit, self.credit, self.balance, self.note]
class LedgerPageParams(PageParams): class PageParams(BasePageParams):
"""The HTML parameters of the ledger.""" """The HTML page parameters."""
def __init__(self, currency: Currency, def __init__(self, currency: Currency,
account: Account, account: Account,
@ -234,7 +234,7 @@ class LedgerPageParams(PageParams):
brought_forward: Entry | None, brought_forward: Entry | None,
entries: list[Entry], entries: list[Entry],
total: Entry | None): total: Entry | None):
"""Constructs the HTML parameters of the ledger. """Constructs the HTML page parameters.
:param currency: The currency. :param currency: The currency.
:param account: The account. :param account: The account.
@ -426,14 +426,13 @@ class Ledger(BaseReport):
if len(page_entries) > 0 and page_entries[-1].is_total: if len(page_entries) > 0 and page_entries[-1].is_total:
total = page_entries[-1] total = page_entries[-1]
page_entries = page_entries[:-1] page_entries = page_entries[:-1]
params: LedgerPageParams = LedgerPageParams( params: PageParams = PageParams(currency=self.__currency,
currency=self.__currency, account=self.__account,
account=self.__account, period=self.__period,
period=self.__period, has_data=has_data,
has_data=has_data, pagination=pagination,
pagination=pagination, brought_forward=brought_forward,
brought_forward=brought_forward, entries=page_entries,
entries=page_entries, total=total)
total=total)
return render_template("accounting/report/ledger.html", return render_template("accounting/report/ledger.html",
report=params) report=params)

View File

@ -30,7 +30,7 @@ from accounting.utils.pagination import Pagination
from accounting.utils.query import parse_query_keywords from accounting.utils.query import parse_query_keywords
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download 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_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
@ -112,12 +112,12 @@ class CSVRow(BaseCSVRow):
self.debit, self.credit, self.note] self.debit, self.credit, self.note]
class SearchPageParams(PageParams): class PageParams(BasePageParams):
"""The HTML parameters of the search result.""" """The HTML page parameters."""
def __init__(self, pagination: Pagination[Entry], def __init__(self, pagination: Pagination[Entry],
entries: list[Entry]): entries: list[Entry]):
"""Constructs the HTML parameters of the search result. """Constructs the HTML page parameters.
:param entries: The search result entries. :param entries: The search result entries.
""" """
@ -297,7 +297,7 @@ class Search(BaseReport):
pagination: Pagination[Entry] = Pagination[Entry](self.__entries) pagination: Pagination[Entry] = Pagination[Entry](self.__entries)
page_entries: list[Entry] = pagination.list page_entries: list[Entry] = pagination.list
_populate_entries(page_entries) _populate_entries(page_entries)
params: SearchPageParams = SearchPageParams(pagination=pagination, params: PageParams = PageParams(pagination=pagination,
entries=page_entries) entries=page_entries)
return render_template("accounting/report/search.html", return render_template("accounting/report/search.html",
report=params) report=params)

View File

@ -29,7 +29,7 @@ from accounting.report.period import Period
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.option_link import OptionLink 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.period_choosers import TrialBalancePeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
@ -98,14 +98,14 @@ class CSVRow(BaseCSVRow):
return [self.text, self.debit, self.credit] return [self.text, self.debit, self.credit]
class TrialBalancePageParams(PageParams): class PageParams(BasePageParams):
"""The HTML parameters of the trial balance.""" """The HTML page parameters."""
def __init__(self, currency: Currency, def __init__(self, currency: Currency,
period: Period, period: Period,
accounts: list[TrialBalanceAccount], accounts: list[TrialBalanceAccount],
total: TrialBalanceTotal): total: TrialBalanceTotal):
"""Constructs the HTML parameters of the trial balance. """Constructs the HTML page parameters.
:param currency: The currency. :param currency: The currency.
:param period: The period. :param period: The period.
@ -256,10 +256,9 @@ class TrialBalance(BaseReport):
:return: The report as HTML. :return: The report as HTML.
""" """
params: TrialBalancePageParams = TrialBalancePageParams( params: PageParams = PageParams(currency=self.__currency,
currency=self.__currency, period=self.__period,
period=self.__period, accounts=self.__accounts,
accounts=self.__accounts, total=self.__total)
total=self.__total)
return render_template("accounting/report/trial-balance.html", return render_template("accounting/report/trial-balance.html",
report=params) report=params)

View File

@ -28,8 +28,8 @@ from accounting.utils.txn_types import TransactionType
from .report_chooser import ReportChooser from .report_chooser import ReportChooser
class PageParams(ABC): class BasePageParams(ABC):
"""The page parameters of a report.""" """The base HTML page parameters class."""
@property @property
@abstractmethod @abstractmethod