diff options
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 17 |
1 files changed, 16 insertions, 1 deletions
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 <etienne.loks_AT_peacefrogsDOTnet> -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") + "%" |