From 25383a3ae66057669cdc0850017c6aa7ebafa449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 23 Jul 2020 22:13:17 +0800 Subject: [PATCH] Employed a regular expression pattern in the PeriodConverter to check the period format first. --- accounting/converters.py | 4 +++- mia_core/static/mia_core/js/period-chooser.js | 6 +++--- mia_core/templates/mia_core/include/period-chooser.html | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/accounting/converters.py b/accounting/converters.py index 6521429..17d1ccf 100644 --- a/accounting/converters.py +++ b/accounting/converters.py @@ -38,7 +38,9 @@ class TransactionTypeConverter: class PeriodConverter: """The path converter for the period.""" - regex = ".+" + regex = ("([0-9]{4}(-[0-9]{2}(-[0-9]{2})?)?)|" + "([0-9]{4}(-[0-9]{2}(-[0-9]{2})?)?)?-" + "([0-9]{4}(-[0-9]{2}(-[0-9]{2})?)?)?") def to_python(self, value): """Returns the period by the period specification. diff --git a/mia_core/static/mia_core/js/period-chooser.js b/mia_core/static/mia_core/js/period-chooser.js index ab680ab..ddbe566 100644 --- a/mia_core/static/mia_core/js/period-chooser.js +++ b/mia_core/static/mia_core/js/period-chooser.js @@ -30,7 +30,7 @@ $(function () { $("#button-period-day") .on("click", function () { window.location = $("#period-url").val() - .replace("period-spec", $("#day-picker").val()); + .replace("0000-00-00", $("#day-picker").val()); }); $("#period-start") .on("change", function () { @@ -43,7 +43,7 @@ $(function () { $("#button-period-custom") .on("click", function () { window.location = $("#period-url").val().replace( - "period-spec", + "0000-00-00", $("#period-start").val() + "-" + $("#period-end").val()); }); @@ -80,7 +80,7 @@ function monthPickerChanged(newDate) { periodSpec = year + "-" + month; } window.location = $("#period-url").val() - .replace("period-spec", periodSpec); + .replace("0000-00-00", periodSpec); } /** diff --git a/mia_core/templates/mia_core/include/period-chooser.html b/mia_core/templates/mia_core/include/period-chooser.html index 9a2b0e1..91fd4a0 100644 --- a/mia_core/templates/mia_core/include/period-chooser.html +++ b/mia_core/templates/mia_core/include/period-chooser.html @@ -24,7 +24,7 @@ First written: 2020/7/10 - +