From f79621876e4328a2be7d8c6fae45584f1796684b Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 31 Mar 2018 17:44:35 +0200 Subject: [PATCH] Add git version to page footer --- Pipfile | 1 + Pipfile.lock | 24 +++++++++++++++++++++++- gym/context_processors.py | 23 +++++++++++++++++++++++ gym/static/gym/style.css | 8 ++++++++ gym/templates/gym/base.html | 12 +++++++++++- workout/settings.py | 3 ++- 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 gym/context_processors.py create mode 100644 gym/static/gym/style.css diff --git a/Pipfile b/Pipfile index ea5a8e1..3495716 100644 --- a/Pipfile +++ b/Pipfile @@ -16,6 +16,7 @@ dj-database-url = "*" django-dotenv = "*" plotly = "*" django-mailgun = "*" +gitpython = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 252b68b..a09ca9a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6f892c3bf84ae9490e88b9a4b56b258544c23872374a800b2abf9b7bf35c584d" + "sha256": "32be3f9fe9f6e66fc10caa61b74eb88f6a183ddf5c6ed65607024838f2af6ee6" }, "pipfile-spec": 6, "requires": {}, @@ -81,6 +81,21 @@ "index": "pypi", "version": "==3.7.7" }, + "gitdb2": { + "hashes": [ + "sha256:b60e29d4533e5e25bb50b7678bbc187c8f6bcff1344b4f293b2ba55c85795f09", + "sha256:cf9a4b68e8c4da8d42e48728c944ff7af2d8c9db303ac1ab32eac37aa4194b0e" + ], + "version": "==2.0.3" + }, + "gitpython": { + "hashes": [ + "sha256:05069e26177c650b3cb945dd543a7ef7ca449f8db5b73038b465105673c1ef61", + "sha256:c47cc31af6e88979c57a33962cbc30a7c25508d74a1b3a19ec5aa7ed64b03129" + ], + "index": "pypi", + "version": "==2.1.9" + }, "gunicorn": { "hashes": [ "sha256:75af03c99389535f218cc596c7de74df4763803f7b63eb09d77e92b3956b36c6", @@ -192,6 +207,13 @@ ], "version": "==1.11.0" }, + "smmap2": { + "hashes": [ + "sha256:b78ee0f1f5772d69ff50b1cbdb01b8c6647a8354f02f23b488cf4b2cfc923956", + "sha256:c7530db63f15f09f8251094b22091298e82bf6c699a6b8344aaaef3f2e1276c3" + ], + "version": "==2.0.3" + }, "traitlets": { "hashes": [ "sha256:9c4bd2d267b7153df9152698efb1050a5d84982d3384a37b2c1f7723ba3e7835", diff --git a/gym/context_processors.py b/gym/context_processors.py new file mode 100644 index 0000000..ae06ad4 --- /dev/null +++ b/gym/context_processors.py @@ -0,0 +1,23 @@ +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()} diff --git a/gym/static/gym/style.css b/gym/static/gym/style.css new file mode 100644 index 0000000..30a9f7e --- /dev/null +++ b/gym/static/gym/style.css @@ -0,0 +1,8 @@ +.footer { + position: absolute; + bottom: 0; + width: 100%; + height: 60px; + line-height: 60px; + background-color: #f5f5f5; +} diff --git a/gym/templates/gym/base.html b/gym/templates/gym/base.html index 835db0d..728dbca 100644 --- a/gym/templates/gym/base.html +++ b/gym/templates/gym/base.html @@ -1,3 +1,5 @@ +{% load static %} + @@ -5,10 +7,11 @@ + {% block add-head %} {% endblock %} - Gym · {% block title %}Home{% endblock %} + Workout · {% block title %}Home{% endblock %} {% include 'gym/navbar.html' %} @@ -48,6 +51,13 @@ {% endblock %} + + + diff --git a/workout/settings.py b/workout/settings.py index a5662f1..3e33480 100644 --- a/workout/settings.py +++ b/workout/settings.py @@ -68,7 +68,7 @@ TEMPLATES = [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + 'gym.context_processors.git_version', ], }, }, @@ -126,3 +126,4 @@ EMAIL_BACKEND = 'django_mailgun.MailgunBackend' MAILGUN_ACCESS_KEY = os.getenv('MAILGUN_ACCESS_KEY', '') MAILGUN_SERVER_NAME = os.getenv('MAILGUN_SERVER_NAME', '') +REPO_URL = 'https://github.com/Crocmagnon/workout'