From ad9cd818d6d3e25791e206be367f0bd620039934 Mon Sep 17 00:00:00 2001 From: relikd Date: Tue, 6 Jun 2023 19:30:54 +0200 Subject: [PATCH] feat: add build date to template context --- Dockerfile | 2 +- app/base/context.py | 7 +++++++ app/base/static/css/style.css | 6 ++++-- app/base/templates/base.html | 6 ++++++ config/settings.py | 8 ++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100755 app/base/context.py diff --git a/Dockerfile b/Dockerfile index 1ff9966..8a14233 100755 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,6 @@ COPY --chmod=700 ./scripts /scripts # finally copy app (likely will invalidate cache) COPY . . -RUN (date +'%Y-%m-%d %R') > build_date.txt +RUN (date -u +'%Y-%m-%d %H:%M:%S') > build_date.txt CMD ["on-deploy.sh"] diff --git a/app/base/context.py b/app/base/context.py new file mode 100755 index 0000000..b170b47 --- /dev/null +++ b/app/base/context.py @@ -0,0 +1,7 @@ +from django.conf import settings + + +def custom_context(request): + return { + 'BUILD_DATE': settings.BUILD_DATE, + } diff --git a/app/base/static/css/style.css b/app/base/static/css/style.css index 6331d5d..7c60c6a 100755 --- a/app/base/static/css/style.css +++ b/app/base/static/css/style.css @@ -282,8 +282,8 @@ table.clickable tbody>tr:hover { } #sidebar-wrapper { - font-family: 'Dosis', sans-serif; - font-size: 1.2rem; + display: flex; + flex-direction: column; -webkit-transition: margin .25s ease-out; -moz-transition: margin .25s ease-out; -o-transition: margin .25s ease-out; @@ -295,6 +295,8 @@ table.clickable tbody>tr:hover { #sidebar-wrapper .list-group { width: max-content; + font-family: 'Dosis', sans-serif; + font-size: 1.2rem; } .icon-list i { diff --git a/app/base/templates/base.html b/app/base/templates/base.html index 3ad6fcc..1b9d60a 100755 --- a/app/base/templates/base.html +++ b/app/base/templates/base.html @@ -51,6 +51,12 @@ Transaktionen Attribute + {% if BUILD_DATE %} + +

+ v{{ BUILD_DATE|date:'Y-m-d H:i' }} +

+ {% endif %}
{% breadcrumbs %} diff --git a/config/settings.py b/config/settings.py index 4739f31..a5e6919 100644 --- a/config/settings.py +++ b/config/settings.py @@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ import os from pathlib import Path +from datetime import datetime, timezone as TZ # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -26,6 +27,12 @@ SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'insecure-+3@1h+@wz%6m*dpx0e') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.environ.get('DEBUG', 'yes').lower() not in ['false', 'no', '0'] +try: + with open(BASE_DIR / 'build_date.txt', 'r') as fp: + BUILD_DATE = datetime.fromisoformat(fp.read()).replace(tzinfo=TZ.utc) +except FileNotFoundError: + BUILD_DATE = None + ALLOWED_HOSTS = [] ALLOWED_HOSTS.extend( @@ -70,6 +77,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'app.base.context.custom_context', ], }, },