Revised the parameters of Period.

This commit is contained in:
依瑪貓 2020-07-14 07:43:47 +08:00
parent ea354ae101
commit 069cd9ca74
3 changed files with 11 additions and 10 deletions

View File

@ -34,7 +34,7 @@ class ReportUrl:
if "period" in kwargs: if "period" in kwargs:
self._period = kwargs["period"] self._period = kwargs["period"]
else: else:
self._period = Period(None, None, None, None) self._period = Period()
if "cash" in kwargs: if "cash" in kwargs:
self._cash_subject = kwargs["cash"] self._cash_subject = kwargs["cash"]
else: else:

View File

@ -74,8 +74,7 @@ def cash(request, subject_code, period_spec):
last_txn = Transaction.objects.order_by("-date").first() last_txn = Transaction.objects.order_by("-date").first()
data_end = last_txn.date if last_txn is not None else None data_end = last_txn.date if last_txn is not None else None
period = Period( period = Period(
get_language(), data_start, data_end, period_spec, data_start, data_end, get_language())
period_spec)
# The SQL query # The SQL query
if subject_code == "0": if subject_code == "0":
subject = Subject(code="0") subject = Subject(code="0")

View File

@ -33,10 +33,10 @@ class Period:
"""The template helper for the period chooser. """The template helper for the period chooser.
Args: Args:
language (str|None): The current language. spec (str): The current period specification
data_start (date|None): The available first day of the data. data_start (date): The available first day of the data.
data_end (date|None): The available last day of the data. data_end (date): The available last day of the data.
spec (str|None): The current period specification language (str): The current language.
Attributes: Attributes:
spec (date): The currently-working period specification. spec (date): The currently-working period specification.
@ -82,11 +82,13 @@ class Period:
_data_end = None _data_end = None
_period = None _period = None
def __init__(self, language, data_start, data_end, spec): def __init__(
self._language = language self, spec = None,
data_start = None, data_end = None, language = None):
self._period = self.Parser(spec)
self._data_start = data_start self._data_start = data_start
self._data_end = data_end self._data_end = data_end
self._period = self.Parser(spec) self._language = language
@property @property
def spec(self): def spec(self):