From 047d8dbae57746857f83dd223e7481fb97e7d5c9 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Wed, 5 Jun 2024 14:53:39 +0200 Subject: [PATCH] [#21] show version in admin --- src/objects/conf/base.py | 17 +++++++++++++++++ src/objects/conf/dev.py | 1 + src/objects/templates/admin/base_site.html | 8 ++++++++ src/objects/utils/context_processors.py | 2 ++ 4 files changed, 28 insertions(+) diff --git a/src/objects/conf/base.py b/src/objects/conf/base.py index e9fecf5f..c8be2db0 100644 --- a/src/objects/conf/base.py +++ b/src/objects/conf/base.py @@ -367,8 +367,25 @@ PROJECT_NAME = "Objects" SITE_TITLE = "Starting point" ENVIRONMENT = config("ENVIRONMENT", "") +ENVIRONMENT_SHOWN_IN_ADMIN = True SHOW_ALERT = True +if "GIT_SHA" in os.environ: + GIT_SHA = config("GIT_SHA", "") + # in docker (build) context, there is no .git directory +elif os.path.exists(os.path.join(BASE_DIR, ".git")): + try: + import git + except ImportError: + GIT_SHA = None + else: + repo = git.Repo(search_parent_directories=True) + GIT_SHA = repo.head.object.hexsha +else: + GIT_SHA = None + +RELEASE = config("RELEASE", GIT_SHA) + # # Library settings # diff --git a/src/objects/conf/dev.py b/src/objects/conf/dev.py index 0c77b1b7..7baf93a0 100644 --- a/src/objects/conf/dev.py +++ b/src/objects/conf/dev.py @@ -8,6 +8,7 @@ "SECRET_KEY", "2(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg" ) os.environ.setdefault("IS_HTTPS", "no") +os.environ.setdefault("RELEASE", "dev") os.environ.setdefault("ENVIRONMENT", "development") os.environ.setdefault("DB_NAME", "objects"), diff --git a/src/objects/templates/admin/base_site.html b/src/objects/templates/admin/base_site.html index 1352afce..e92829e1 100644 --- a/src/objects/templates/admin/base_site.html +++ b/src/objects/templates/admin/base_site.html @@ -44,6 +44,14 @@

{{ settings.PROJECT_NAME }} {% block footer %} {{ block.super }} + + {% url 'admin:login' as admin_login_url %} + {% if request.path != admin_login_url %} +
+ {% blocktrans with version=settings.RELEASE %}version {{ version }}{% endblocktrans %} +
+ {% endif %} + {# Load the custom JS #} {% endblock %} diff --git a/src/objects/utils/context_processors.py b/src/objects/utils/context_processors.py index eb7bfd03..01064687 100644 --- a/src/objects/utils/context_processors.py +++ b/src/objects/utils/context_processors.py @@ -6,7 +6,9 @@ def settings(request): "GOOGLE_ANALYTICS_ID", "ENVIRONMENT", "SHOW_ALERT", + "ENVIRONMENT_SHOWN_IN_ADMIN", "SITE_TITLE", + "RELEASE", "PROJECT_NAME", )