From 250189d89579951b996afd5a356a91c94806c6e6 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Tue, 12 Apr 2022 09:05:33 +0200 Subject: [PATCH] #142 Localized date improved * fixes bug where created timestamp has been displayed on modified attribute on detail views * enhances localized date and datetime rendering * reorders sub menus in user's profile hub --- .../compensation/detail/compensation/view.html | 12 +++++++++--- .../compensation/detail/eco_account/view.html | 12 +++++++++--- ema/templates/ema/detail/view.html | 5 ++--- .../templates/intervention/detail/view.html | 14 ++++++++++---- konova/sub_settings/django_settings.py | 7 +++++++ user/models/user_action.py | 2 +- user/templates/user/index.html | 16 ++++++++-------- 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/compensation/templates/compensation/detail/compensation/view.html b/compensation/templates/compensation/detail/compensation/view.html index e3871510..80b5c0f0 100644 --- a/compensation/templates/compensation/detail/compensation/view.html +++ b/compensation/templates/compensation/detail/compensation/view.html @@ -90,9 +90,15 @@ {% trans 'Last modified' %} - {{obj.modified.timestamp|default_if_none:""|naturalday}} -
- {{obj.modified.user.username}} + {% if obj.modified %} + {{obj.modified.timestamp|default_if_none:""}} +
+ {{obj.modified.user.username}} + {% else %} + {{obj.created.timestamp|default_if_none:""}} +
+ {{obj.created.user.username}} + {% endif %} diff --git a/compensation/templates/compensation/detail/eco_account/view.html b/compensation/templates/compensation/detail/eco_account/view.html index ee4a0f73..116b6670 100644 --- a/compensation/templates/compensation/detail/eco_account/view.html +++ b/compensation/templates/compensation/detail/eco_account/view.html @@ -73,9 +73,15 @@ {% trans 'Last modified' %} - {{obj.modified.timestamp|default_if_none:""|naturalday}} -
- {{obj.modified.user.username}} + {% if obj.modified %} + {{obj.modified.timestamp|default_if_none:""}} +
+ {{obj.modified.user.username}} + {% else %} + {{obj.created.timestamp|default_if_none:""}} +
+ {{obj.created.user.username}} + {% endif %} diff --git a/ema/templates/ema/detail/view.html b/ema/templates/ema/detail/view.html index 7b567038..020b7d4b 100644 --- a/ema/templates/ema/detail/view.html +++ b/ema/templates/ema/detail/view.html @@ -60,14 +60,13 @@ {% trans 'Last modified' %} {% if obj.modified %} - {{obj.modified.timestamp|default_if_none:""|naturalday}} + {{obj.modified.timestamp|default_if_none:""}}
{{obj.modified.user.username}} {% else %} - {{obj.created.timestamp|default_if_none:""|naturalday}} + {{obj.created.timestamp|default_if_none:""}}
{{obj.created.user.username}} - {% endif %} diff --git a/intervention/templates/intervention/detail/view.html b/intervention/templates/intervention/detail/view.html index f5680cc3..c5f9b9c1 100644 --- a/intervention/templates/intervention/detail/view.html +++ b/intervention/templates/intervention/detail/view.html @@ -1,5 +1,5 @@ {% extends 'base.html' %} -{% load i18n l10n static fontawesome_5 humanize %} +{% load i18n l10n static fontawesome_5 %} {% block head %} {% comment %} @@ -106,9 +106,15 @@ {% trans 'Last modified' %} - {{obj.created.timestamp|default_if_none:""|naturalday}} -
- {{obj.created.user.username}} + {% if obj.modified %} + {{obj.modified.timestamp|default_if_none:""}} +
+ {{obj.modified.user.username}} + {% else %} + {{obj.created.timestamp|default_if_none:""}} +
+ {{obj.created.user.username}} + {% endif %} diff --git a/konova/sub_settings/django_settings.py b/konova/sub_settings/django_settings.py index b0d6ff8a..0626f599 100644 --- a/konova/sub_settings/django_settings.py +++ b/konova/sub_settings/django_settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/ """ import os from django.utils.translation import gettext_lazy as _ +from django.conf.locale.de import formats as de_formats # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = os.path.dirname( @@ -162,9 +163,15 @@ LANGUAGES = [ USE_THOUSAND_SEPARATOR = True +# Regular python relevant date/datetime formatting DEFAULT_DATE_TIME_FORMAT = '%d.%m.%Y %H:%M:%S' DEFAULT_DATE_FORMAT = '%d.%m.%Y' +# Template relevant date/datetime formatting +# See the Note on here: https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#date +de_formats.DATETIME_FORMAT = "d.m.Y, H:i" +de_formats.DATE_FORMAT = "d.m.Y" + TIME_ZONE = 'Europe/Berlin' USE_I18N = True diff --git a/user/models/user_action.py b/user/models/user_action.py index 14d8f41c..d797bb2c 100644 --- a/user/models/user_action.py +++ b/user/models/user_action.py @@ -10,7 +10,7 @@ import uuid from django.db import models from django.utils.translation import gettext_lazy as _ -from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT +from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT class UserAction(models.TextChoices): diff --git a/user/templates/user/index.html b/user/templates/user/index.html index c31de94f..f8fd616d 100644 --- a/user/templates/user/index.html +++ b/user/templates/user/index.html @@ -54,14 +54,6 @@ -
- - - -
+
+ + + +