From 6f2267e18aae96e398e9be55408fcbb9e97898bc Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 2 Oct 2023 10:59:15 +0200 Subject: [PATCH] add timestamp to blogpost --- gawa/blog/templates/blog/blogpost.html | 129 +++++++++++++++---------- gawa/start/templatetags/helper_tags.py | 4 + 2 files changed, 83 insertions(+), 50 deletions(-) diff --git a/gawa/blog/templates/blog/blogpost.html b/gawa/blog/templates/blog/blogpost.html index 94e40c4..8d973b8 100644 --- a/gawa/blog/templates/blog/blogpost.html +++ b/gawa/blog/templates/blog/blogpost.html @@ -1,69 +1,98 @@ {% extends 'base.html' %} {% load i18n %} +{% load helper_tags %} {% get_current_language as LANGUAGE_CODE %} -{% block languagecode %}{{ LANGUAGE_CODE }}{% endblock languagecode %} -{% block title %}{% translate "cscherr.de" %} - {% translate "Blog" %}{% endblock title %} +{% block languagecode %} + {{ LANGUAGE_CODE }} +{% endblock languagecode %} +{% block title %} + {% translate "cscherr.de" %} - {% translate "Blog" %} +{% endblock title %} {% block nav %} -{% include 'nav.html' %} + {% include 'nav.html' %} {% endblock nav %} {% block headscripts %} - + {% endblock headscripts %} {% block main %} -
-
-
-
-
- {% if LANGUAGE_CODE == "de" %} -

{{ post.title_de }}
- {{ post.subtitle_de }}


- {% elif LANGUAGE_CODE == "en" %} -

{{ post.title_en }}
- {{ post.subtitle_en }}


- {% else %} -

{{ post.title_en }}
- {{ post.subtitle_en }}


- {% endif %} -
-
-
-
- - thumbnail - -
-
+
+
+
+
{% if LANGUAGE_CODE == "de" %} -

{{ post.desc_de }}

+

+ {{ post.title_de }} +
+ {{ post.subtitle_de }} +

+
{% elif LANGUAGE_CODE == "en" %} -

{{ post.desc_en }}

+

+ {{ post.title_en }} +
+ {{ post.subtitle_en }} +

+
{% else %} -

{{ post.desc_en }}

+

+ {{ post.title_en }} +
+ {{ post.subtitle_en }} +

+
{% endif %}
+
+
-

{{ post.date }}

+ + thumbnail +
-
-

{{ post.category.name }}

+
+
+ {% if LANGUAGE_CODE == "de" %} +

{{ post.desc_de }}

+ {% elif LANGUAGE_CODE == "en" %} +

{{ post.desc_en }}

+ {% else %} +

{{ post.desc_en }}

+ {% endif %} +
+
+

+ {{ post.category.name }} +

+
+
-
+
+
+ {% if LANGUAGE_CODE == "de" %} + {{ post.body_de | safe }} + {% elif LANGUAGE_CODE == "en" %} + {{ post.body_en | safe }} + {% else %} + {{ post.body_en | safe }} + {% endif %} +
+
+
+
+ {% format_time post.date as date %} +

{% trans "published" %}: {{ date }}

+
+
+ {% format_time post.update as update %} +

{% trans "updated" %}: {{ update }}

+
+
+
-
-
- {% if LANGUAGE_CODE == "de" %} - {{ post.body_de | safe }} - {% elif LANGUAGE_CODE == "en" %} - {{ post.body_en | safe }} - {% else %} - {{ post.body_en | safe }} - {% endif %} -
-
-
-
-{% include 'blog/featured.html' %} -{% endblock main %} + {% include 'blog/featured.html' %} + {% endblock main %} diff --git a/gawa/start/templatetags/helper_tags.py b/gawa/start/templatetags/helper_tags.py index ce0157b..fe8780c 100644 --- a/gawa/start/templatetags/helper_tags.py +++ b/gawa/start/templatetags/helper_tags.py @@ -1,6 +1,7 @@ from django.template import Library from django.urls import resolve, reverse from django.utils.translation import activate, get_language +from datetime import datetime import re @@ -9,6 +10,9 @@ logger = logging.getLogger(__name__) register = Library() +@register.simple_tag +def format_time(timestamp: datetime) -> str: + return timestamp.strftime("%F %H:%M:%S") @register.simple_tag(takes_context=True) def change_lang(context, lang="de", *args, **kwargs):