From 751937e0c2f08ca5d54577862d445d6c0b0ad215 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 6 Apr 2020 20:11:36 +1000 Subject: [PATCH] Use InstanceName around the place - Report in /api/ endpoint - Display in About window - Include in any generated barcode --- InvenTree/InvenTree/helpers.py | 4 ++++ InvenTree/InvenTree/version.py | 6 +++++ InvenTree/InvenTree/views.py | 5 ++-- .../part/templatetags/inventree_extras.py | 6 +++++ InvenTree/templates/about.html | 24 ++++++++++++------- InvenTree/templates/base.html | 4 +++- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 0abe5313ee..5492f13a05 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -13,6 +13,8 @@ from django.http import StreamingHttpResponse from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ +from .version import inventreeVersion, inventreeInstanceName + def TestIfImage(img): """ Test if an image file is indeed an image """ @@ -134,6 +136,8 @@ def MakeBarcode(object_type, object_id, object_url, data={}): data['id'] = object_id data['url'] = object_url data['tool'] = 'InvenTree' + data['instance'] = inventreeInstanceName() + data['version'] = inventreeVersion() return json.dumps(data, sort_keys=True) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index be4e6c708e..182c8f58f7 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -3,9 +3,15 @@ Provides information on the current InvenTree version """ import subprocess +from common.models import InvenTreeSetting + INVENTREE_SW_VERSION = "0.0.10" +def inventreeInstanceName(): + """ Returns the InstanceName settings for the current database """ + return InvenTreeSetting.get_setting("InstanceName", "") + def inventreeVersion(): """ Returns the InvenTree version string """ diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 5121b1bad9..9cdfecbd8a 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -22,7 +22,7 @@ from common.models import InvenTreeSetting from .forms import DeleteForm, EditUserForm, SetPasswordForm from .helpers import str2bool -from .version import inventreeVersion +from .version import inventreeVersion, inventreeInstanceName from rest_framework import views @@ -422,7 +422,8 @@ class InfoView(AjaxView): data = { 'server': 'InvenTree', - 'version': inventreeVersion() + 'version': inventreeVersion(), + 'instance': inventreeInstanceName(), } return JsonResponse(data) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index d508452e80..e68e9c23dc 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -43,6 +43,12 @@ def part_allocation_count(build, part, *args, **kwargs): return decimal2string(build.getAllocatedQuantity(part)) +@register.simple_tag() +def inventree_instance_name(*args, **kwargs): + """ Return the InstanceName associated with the current database """ + return version.inventreeInstanceName() + + @register.simple_tag() def inventree_version(*args, **kwargs): """ Return InvenTree version string """ diff --git a/InvenTree/templates/about.html b/InvenTree/templates/about.html index 4f8d7e6d4e..412e7fc644 100644 --- a/InvenTree/templates/about.html +++ b/InvenTree/templates/about.html @@ -10,35 +10,41 @@ Inventree Logo +

{% trans "InvenTree Version Information" %}