workout/gym/context_processors.py

24 lines
624 B
Python
Raw Normal View History

2018-03-31 17:44:35 +02:00
from django.conf import settings
from git import Repo
def get_git_version():
"""
Get the git version of the site.
"""
try:
repo = Repo(settings.BASE_DIR)
branch = repo.active_branch
commit = repo.head.commit.hexsha
name = u'{0}/{1}'.format(branch, commit[:7])
return {'name': name, 'url': u'{}/tree/{}'.format(settings.REPO_URL, commit)}
except (KeyError, TypeError):
return {'name': '', 'url': ''}
def git_version(request):
"""
A context processor to include the git version on all pages.
"""
return {'git_version': get_git_version()}