Add some context processors for site variables and git version
This commit is contained in:
parent
aedfde2984
commit
aa8cd29e4d
5 changed files with 77 additions and 2 deletions
1
Pipfile
1
Pipfile
|
@ -5,6 +5,7 @@ name = "pypi"
|
|||
|
||||
[packages]
|
||||
django = "*"
|
||||
gitpython = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
|
24
Pipfile.lock
generated
24
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "627ef89f247ecee27e9ef0dabe116108d09c47abf171c900a8817befa64f9dd2"
|
||||
"sha256": "8f5375aad28234aa513d8d0b3921e77eded8dcb11a81afcebae00a618d4aec94"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -24,12 +24,34 @@
|
|||
"index": "pypi",
|
||||
"version": "==2.1.7"
|
||||
},
|
||||
"gitdb2": {
|
||||
"hashes": [
|
||||
"sha256:83361131a1836661a155172932a13c08bda2db3674e4caa32368aa6eb02f38c2",
|
||||
"sha256:e3a0141c5f2a3f635c7209d56c496ebe1ad35da82fe4d3ec4aaa36278d70648a"
|
||||
],
|
||||
"version": "==2.0.5"
|
||||
},
|
||||
"gitpython": {
|
||||
"hashes": [
|
||||
"sha256:563221e5a44369c6b79172f455584c9ebbb122a13368cc82cb4b5addff788f82",
|
||||
"sha256:8237dc5bfd6f1366abeee5624111b9d6879393d84745a507de0fda86043b65a8"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.1.11"
|
||||
},
|
||||
"pytz": {
|
||||
"hashes": [
|
||||
"sha256:32b0891edff07e28efe91284ed9c31e123d84bea3fd98e1f72be2508f43ef8d9",
|
||||
"sha256:d5f05e487007e29e03409f9398d074e158d920d36eb82eaf66fb1136b0c5374c"
|
||||
],
|
||||
"version": "==2018.9"
|
||||
},
|
||||
"smmap2": {
|
||||
"hashes": [
|
||||
"sha256:0555a7bf4df71d1ef4218e4807bbf9b201f910174e6e08af2e138d4e517b4dde",
|
||||
"sha256:29a9ffa0497e7f2be94ca0ed1ca1aa3cd4cf25a1f6b4f5f87f74b46ed91d609a"
|
||||
],
|
||||
"version": "==2.0.5"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
|
|
|
@ -64,6 +64,8 @@ TEMPLATES = [
|
|||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'map.context_processors.app_settings',
|
||||
'map.context_processors.git_version',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -123,3 +125,21 @@ STATIC_URL = '/static/'
|
|||
|
||||
AUTH_USER_MODEL = 'map.Friend'
|
||||
|
||||
APP = {
|
||||
'site': {
|
||||
'name': "FriendsMap",
|
||||
'url': os.environ.get('SITE_URL', "http://127.0.0.1:8000"),
|
||||
'repository': {
|
||||
'url': "https://github.com/Crocmagnon/friends_map",
|
||||
'bugtracker': "https://github.com/Crocmagnon/friends_map/issues",
|
||||
},
|
||||
'licences': {
|
||||
'source': {
|
||||
'code': "GPL v3",
|
||||
'url_license': "http://www.gnu.org/licenses/gpl-3.0.html",
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
32
map/context_processors.py
Normal file
32
map/context_processors.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from git import Repo
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def get_git_version():
|
||||
"""
|
||||
Get the git version of the site.
|
||||
"""
|
||||
try:
|
||||
repo = Repo(settings.BASE_DIR)
|
||||
commit = repo.head.commit.hexsha
|
||||
name = commit[:7]
|
||||
return {'name': name, 'url': u'{}/commit/{}'.format(settings.APP['site']['repository']['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()}
|
||||
|
||||
|
||||
def app_settings(request):
|
||||
"""
|
||||
A context processor with all APP settings.
|
||||
"""
|
||||
return {
|
||||
'app': settings.APP,
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
{% block add-head %}
|
||||
{% endblock %}
|
||||
|
||||
<title>FriendsMap · {% block title %}Home{% endblock %}</title>
|
||||
<title>{{ app.site.name }} · {% block title %}Home{% endblock %}</title>
|
||||
</head>
|
||||
<body>
|
||||
{#{% include 'map/navbar.html' %}#}
|
||||
|
|
Loading…
Reference in a new issue