diff --git a/config/context_processors.py b/config/context_processors.py new file mode 100644 index 0000000..5e1d06b --- /dev/null +++ b/config/context_processors.py @@ -0,0 +1,21 @@ +import subprocess + + +def git_tag(): + try: + return subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8') + except: + return "v0.0.0" + + +def commit_hash(): + try: + hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip().decode('utf-8') + return hash, hash[:7] + except: + return "", "" + + +def version_processor(request): + commit, short_commit = commit_hash() + return {'git_tag': git_tag(), 'commit': commit, 'short_commit': short_commit} diff --git a/config/settings.py b/config/settings.py index 5798dd2..2f4f112 100644 --- a/config/settings.py +++ b/config/settings.py @@ -69,6 +69,7 @@ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'config.context_processors.version_processor', ], }, }, diff --git a/templates/footer.html b/templates/footer.html index 44e0eea..f734836 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -6,6 +6,8 @@