Load build order prefix setting

This commit is contained in:
Oliver Walters 2020-10-20 08:41:08 +11:00
parent 7aa473712f
commit 406d7bcf80
5 changed files with 26 additions and 3 deletions

View File

@ -19,9 +19,18 @@ from django.contrib.auth.models import Permission
import InvenTree.version
from common.models import InvenTreeSetting
from .settings import MEDIA_URL, STATIC_URL
def getSetting(key, backup_value=None):
"""
Shortcut for reading a setting value from the database
"""
return InvenTreeSetting.get_setting(key, backup_value=backup_value)
def generateTestKey(test_name):
"""
Generate a test 'key' for a given test name.

View File

@ -22,7 +22,7 @@ from markdownx.models import MarkdownxField
from mptt.models import MPTTModel, TreeForeignKey
from InvenTree.status_codes import BuildStatus
from InvenTree.helpers import increment
from InvenTree.helpers import increment, getSetting
from InvenTree.validators import validate_build_order_reference
import InvenTree.fields
@ -56,7 +56,9 @@ class Build(MPTTModel):
def __str__(self):
return f"BO{self.reference}"
prefix = getSetting("BUILDORDER_REFERENCE_PREFIX")
return f"{prefix}{self.reference}"
def get_absolute_url(self):
return reverse('build-detail', kwargs={'pk': self.id})

View File

@ -71,7 +71,7 @@ src="{% static 'img/blank_image.png' %}"
<tr>
<td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Build Order Reference" %}</td>
<td>{{ build.reference }}</td>
<td>{{ build }}</td>
</tr>
<tr>
<td><span class='fas fa-shapes'></span></td>

View File

@ -62,6 +62,10 @@ class InvenTreeSetting(models.Model):
If it does not exist, return the backup value (default = None)
"""
# If no backup value is specified, atttempt to retrieve a "default" value
if backup_value is None:
backup_value = InvenTreeSetting.DEFAULT_VALUES.get(key, None)
try:
settings = InvenTreeSetting.objects.filter(key__iexact=key)

View File

@ -1,4 +1,5 @@
{% load i18n %}
{% load inventree_extras %}
function loadBuildTable(table, options) {
// Display a table of Build objects
@ -40,6 +41,13 @@ function loadBuildTable(table, options) {
sortable: true,
switchable: false,
formatter: function(value, row, index, field) {
var prefix = "{% inventree_setting 'BUILDORDER_REFERENCE_PREFIX' 'BO' %}";
if (prefix) {
value = `${prefix}${value}`;
}
return renderLink(value, '/build/' + row.pk + '/');
}
},