mirror of https://github.com/snachodog/mybuddy.git
Add version string template tag.
This commit is contained in:
parent
96658a8c29
commit
2de04a5f22
|
@ -50,3 +50,5 @@ __version__ = '0.1.0'
|
|||
__license__ = 'BSD 2-Clause'
|
||||
|
||||
VERSION = __version__
|
||||
|
||||
default_app_config = 'babybuddy.apps.BabyBuddyConfig'
|
||||
|
|
|
@ -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])
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue