Skip to content

Commit

Permalink
[#21] show version in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyBA committed Jun 5, 2024
1 parent b4ebbeb commit 1797a7f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/objects/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
1 change: 1 addition & 0 deletions src/objects/conf/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
8 changes: 8 additions & 0 deletions src/objects/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ <h1 id="site-name"><a href="{% url 'admin:index' %}">{{ settings.PROJECT_NAME }}

{% block footer %}
{{ block.super }}

{% url 'admin:login' as admin_login_url %}
{% if request.path != admin_login_url %}
<div class="version" title="Git SHA: {{ settings.GIT_SHA|default:'' }}">
{% blocktrans with version=settings.RELEASE %}version {{ version }}{% endblocktrans %}
</div>
{% endif %}

{# Load the custom JS #}
<script src="{% static 'bundles/objects-js.js' %}"></script>
{% endblock %}
2 changes: 2 additions & 0 deletions src/objects/utils/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def settings(request):
"GOOGLE_ANALYTICS_ID",
"ENVIRONMENT",
"SHOW_ALERT",
"ENVIRONMENT_SHOWN_IN_ADMIN",
"SITE_TITLE",
"RELEASE",
"PROJECT_NAME",
)

Expand Down

0 comments on commit 1797a7f

Please sign in to comment.