Add build number display based on git information.
This commit is contained in:
@@ -58,8 +58,12 @@
|
||||
<h3>{% trans 'About' %}</h3>
|
||||
<hr>
|
||||
|
||||
{% build as build_number %}
|
||||
<div class="well">
|
||||
<h3 class="text-center">{% project_name %} ({% trans 'Version' %} {% project_version %})</h3>
|
||||
{% if build_number %}
|
||||
<p class='text-center'>{% blocktrans with build_number as build_number %}Build number: {{ build_number }}{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
<p class="text-center">
|
||||
{% project_description as project_description %}
|
||||
{% trans project_description %}
|
||||
|
||||
@@ -2,6 +2,8 @@ from __future__ import unicode_literals
|
||||
|
||||
from json import dumps
|
||||
|
||||
import sh
|
||||
|
||||
from django.conf import settings
|
||||
from django.template import Context, Library
|
||||
from django.template.loader import get_template
|
||||
@@ -12,6 +14,14 @@ from ..utils import return_attrib
|
||||
|
||||
register = Library()
|
||||
|
||||
try:
|
||||
BUILD = sh.Command('git').bake('describe', '--tags', '--always', 'HEAD')
|
||||
DATE = sh.Command('git').bake('--no-pager', 'log', '-1', '--format=%cd')
|
||||
except sh.CommandNotFound:
|
||||
logger.debug('git not found')
|
||||
BUILD = None
|
||||
DATE = None
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_encoded_parameter(item, parameters_dict):
|
||||
@@ -61,3 +71,11 @@ def render_subtemplate(context, template_name, template_context):
|
||||
new_context = Context(context)
|
||||
new_context.update(Context(template_context))
|
||||
return get_template(template_name).render(new_context)
|
||||
|
||||
|
||||
@register.assignment_tag
|
||||
def build():
|
||||
if BUILD:
|
||||
return '{} {}'.format(BUILD(), DATE().decode())
|
||||
else:
|
||||
return 'No build information'
|
||||
|
||||
Reference in New Issue
Block a user