diff --git a/babybuddy/__init__.py b/babybuddy/__init__.py index 9d38a362..829c865c 100644 --- a/babybuddy/__init__.py +++ b/babybuddy/__init__.py @@ -50,3 +50,5 @@ __version__ = '0.1.0' __license__ = 'BSD 2-Clause' VERSION = __version__ + +default_app_config = 'babybuddy.apps.BabyBuddyConfig' diff --git a/babybuddy/apps.py b/babybuddy/apps.py new file mode 100644 index 00000000..b59b87e2 --- /dev/null +++ b/babybuddy/apps.py @@ -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]) diff --git a/babybuddy/templatetags/babybuddy_tags.py b/babybuddy/templatetags/babybuddy_tags.py index 2e7f7295..e9e56586 100644 --- a/babybuddy/templatetags/babybuddy_tags.py +++ b/babybuddy/templatetags/babybuddy_tags.py @@ -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