Add version string template tag.

This commit is contained in:
Christopher Charbonneau Wells 2017-12-26 08:53:38 -05:00
parent 96658a8c29
commit 2de04a5f22
3 changed files with 34 additions and 0 deletions

View File

@ -50,3 +50,5 @@ __version__ = '0.1.0'
__license__ = 'BSD 2-Clause'
VERSION = __version__
default_app_config = 'babybuddy.apps.BabyBuddyConfig'

20
babybuddy/apps.py Normal file
View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.apps import AppConfig
from babybuddy import VERSION
class BabyBuddyConfig(AppConfig):
name = 'babybuddy'
verbose_name = 'Baby Buddy'
version = VERSION
version_string = VERSION
def ready(self):
if os.path.isfile('.git/refs/heads/master'):
commit = open('.git/refs/heads/master').read()
self.version_string += ' ({})'.format(commit[0:7])

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals
from django import template
from django.apps import apps
register = template.Library()
@ -22,3 +23,14 @@ def relative_url(context, field_name, value):
lambda p: p.split('=')[0] != field_name, querystring)
encoded_querystring = '&'.join(filtered_querystring)
return '{}&{}'.format(url, encoded_querystring)
@register.simple_tag()
def version_string():
"""
Get Baby Buddy's current version string.
:return: version string ('n.n.n (commit)')
"""
config = apps.get_app_config('babybuddy')
return config.version_string