Revised the way to import from the datetime package, to avoid name conflict with the common "date" and "time" names.

This commit is contained in:
2023-04-26 13:17:31 +08:00
parent c11ae23885
commit 359c335662
30 changed files with 156 additions and 152 deletions

View File

@ -17,7 +17,7 @@
"""The path converters for the journal entry management.
"""
from datetime import date
import datetime as dt
from flask import abort
from werkzeug.routing import BaseConverter
@ -82,18 +82,18 @@ class DateConverter(BaseConverter):
"""The date converter to convert the ISO date from and to the
corresponding date in the routes."""
def to_python(self, value: str) -> date:
def to_python(self, value: str) -> dt.date:
"""Converts an ISO date to a date.
:param value: The ISO date.
:return: The corresponding date.
"""
try:
return date.fromisoformat(value)
return dt.date.fromisoformat(value)
except ValueError:
abort(404)
def to_url(self, value: date) -> str:
def to_url(self, value: dt.date) -> str:
"""Converts a date to its ISO date.
:param value: The date.