From 2691df360f199a03932770fe75b4264edbcfd184 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Tue, 16 Jul 2024 10:11:56 +0200 Subject: [PATCH] Show date in tag --- dateutils.py | 9 ++++++++- db.py | 3 +++ templates/base.html | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dateutils.py b/dateutils.py index e84bef6..cb611cc 100644 --- a/dateutils.py +++ b/dateutils.py @@ -1,5 +1,5 @@ from datetime import datetime - +from typing import Optional def format_month(month: int) -> str: if month == 1: @@ -32,3 +32,10 @@ def format_month(month: int) -> str: def format(date: datetime) -> str: return f'{date.day} {format_month(date.month)} {date.year} à {date.hour:02}h{date.minute:02}' + + +def format_short(date: Optional[datetime]) -> str: + if date is None: + return 'XX/XX/XXXX' + + return f'{date.day:02}/{date.month:02}/{date.year}' diff --git a/db.py b/db.py index 63d69cd..a3f3bdd 100755 --- a/db.py +++ b/db.py @@ -118,6 +118,9 @@ class Calibration: def get_pretty_date(self) -> str: return dateutils.format(self.validated_date) + def get_pretty_short_date(self) -> str: + return dateutils.format_short(self.validated_date) + Calibration.Dummy = Calibration(-1, CalibrationState.Empty, None) diff --git a/templates/base.html b/templates/base.html index b5c7cd9..8bbfad6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -43,7 +43,7 @@ étalonnage - validé + validé le {{ calibration.get_pretty_short_date() }}