mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add 'InstanceName' setting
- Will be auto-generated if it does not already exist
This commit is contained in:
parent
7c2af32b38
commit
071c317bae
@ -2,7 +2,7 @@ from django.apps import AppConfig
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
|
||||
import os
|
||||
|
||||
import uuid
|
||||
import yaml
|
||||
|
||||
|
||||
@ -10,14 +10,19 @@ class CommonConfig(AppConfig):
|
||||
name = 'common'
|
||||
|
||||
def ready(self):
|
||||
|
||||
""" Will be called when the Common app is first loaded """
|
||||
self.populate_default_settings()
|
||||
self.add_instance_name()
|
||||
|
||||
def populate_default_settings(self):
|
||||
""" Populate the default values for InvenTree key:value pairs.
|
||||
If a setting does not exist, it will be created.
|
||||
"""
|
||||
|
||||
# Import this here, rather than at the global-level,
|
||||
# otherwise it is called all the time, and we don't want that,
|
||||
# as the InvenTreeSetting model may have not been instantiated yet.
|
||||
from .models import InvenTreeSetting
|
||||
|
||||
here = os.path.dirname(os.path.abspath(__file__))
|
||||
@ -46,3 +51,26 @@ class CommonConfig(AppConfig):
|
||||
except (OperationalError, ProgrammingError):
|
||||
# Migrations have not yet been applied - table does not exist
|
||||
break
|
||||
|
||||
def add_instance_name(self):
|
||||
"""
|
||||
Check if an InstanceName has been defined for this database.
|
||||
If not, create a random one!
|
||||
"""
|
||||
|
||||
# See note above
|
||||
from .models import InvenTreeSetting
|
||||
|
||||
if not InvenTreeSetting.objects.filter(key='InstanceName').exists():
|
||||
|
||||
val = uuid.uuid4().hex
|
||||
|
||||
print("No 'InstanceName' found - generating random name '{n}'".format(n=val))
|
||||
|
||||
name = InvenTreeSetting(
|
||||
key="InstanceName",
|
||||
value=val,
|
||||
description="Instance name for this InvenTree database installation."
|
||||
)
|
||||
|
||||
name.save()
|
||||
|
@ -4,6 +4,9 @@
|
||||
# Note: The description strings provided here will be translatable,
|
||||
# so ensure that any translations are provided as appropriate.
|
||||
|
||||
# TODO: Update the formatting here to include logical separators e.g. double-underscore
|
||||
# TODO: This is so when there are enough options, we will be able to display them as a tree
|
||||
|
||||
- key: 'part_ipn_regex'
|
||||
default: ''
|
||||
description: 'Format string for internal part number'
|
||||
|
Loading…
Reference in New Issue
Block a user