From 1192a6f9679d320630a312b87b844c5c2aebac1e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 3 Apr 2024 19:09:12 +0200 Subject: 🐛 JSON date: fix criteria search - sheet display localized version (refs #5883) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/utils.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index c30a5c5fc..dd21bec06 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (C) 2013-2016 Étienne Loks -import json # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -24,6 +23,7 @@ import datetime from functools import wraps from itertools import chain from inspect import currentframe, getframeinfo +import json import logging import hashlib from importlib import import_module @@ -72,6 +72,7 @@ from django.http import HttpResponseRedirect from django.urls import reverse, NoReverseMatch from django.utils.crypto import get_random_string from django.utils.datastructures import MultiValueDict as BaseMultiValueDict +from django.utils.formats import date_format from django.utils.safestring import mark_safe from django.template.defaultfilters import slugify @@ -2715,6 +2716,20 @@ def create_osm_town(rel_id, name, numero_insee=None): return town +def format_date(value, frmat="SHORT_DATE_FORMAT"): + formats = ["%Y-%m-%d", "%d/%m/%Y"] + date = None + for forma in formats: + try: + date = datetime.datetime.strptime(value, forma).date() + break + except ValueError: + continue + if not date: + return value + return date_format(date, format=frmat, use_l10n=True) + + def get_percent(current, total): return f"{(current + 1) / total * 100:.1f}".rjust(4, "0") + "%" -- cgit v1.2.3