Employed a regular expression pattern in the PeriodConverter to check the period format first.

This commit is contained in:
依瑪貓 2020-07-23 22:13:17 +08:00
parent d88d3942d2
commit 25383a3ae6
3 changed files with 7 additions and 5 deletions

View File

@ -38,7 +38,9 @@ class TransactionTypeConverter:
class PeriodConverter: class PeriodConverter:
"""The path converter for the period.""" """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): def to_python(self, value):
"""Returns the period by the period specification. """Returns the period by the period specification.

View File

@ -30,7 +30,7 @@ $(function () {
$("#button-period-day") $("#button-period-day")
.on("click", function () { .on("click", function () {
window.location = $("#period-url").val() window.location = $("#period-url").val()
.replace("period-spec", $("#day-picker").val()); .replace("0000-00-00", $("#day-picker").val());
}); });
$("#period-start") $("#period-start")
.on("change", function () { .on("change", function () {
@ -43,7 +43,7 @@ $(function () {
$("#button-period-custom") $("#button-period-custom")
.on("click", function () { .on("click", function () {
window.location = $("#period-url").val().replace( window.location = $("#period-url").val().replace(
"period-spec", "0000-00-00",
$("#period-start").val() + "-" + $("#period-end").val()); $("#period-start").val() + "-" + $("#period-end").val());
}); });
@ -80,7 +80,7 @@ function monthPickerChanged(newDate) {
periodSpec = year + "-" + month; periodSpec = year + "-" + month;
} }
window.location = $("#period-url").val() window.location = $("#period-url").val()
.replace("period-spec", periodSpec); .replace("0000-00-00", periodSpec);
} }
/** /**

View File

@ -24,7 +24,7 @@ First written: 2020/7/10
<!-- the period chooser dialog --> <!-- the period chooser dialog -->
<!-- The Modal --> <!-- The Modal -->
<input id="period-url" type="hidden" value="{% url_period "period-spec" %}" /> <input id="period-url" type="hidden" value="{% url_period "0000-00-00" %}" />
<input id="period-month-picker-params" type="hidden" value="{{ period.month_picker_params }}" /> <input id="period-month-picker-params" type="hidden" value="{{ period.month_picker_params }}" />
<div class="modal" id="period-modal"> <div class="modal" id="period-modal">
<div class="modal-dialog"> <div class="modal-dialog">