mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Remove "description" field from InvenTreeSettings key:value fields
This commit is contained in:
parent
92c1e3c1a5
commit
06040f94ee
@ -14,7 +14,7 @@ class CurrencyAdmin(ImportExportModelAdmin):
|
|||||||
|
|
||||||
class SettingsAdmin(ImportExportModelAdmin):
|
class SettingsAdmin(ImportExportModelAdmin):
|
||||||
|
|
||||||
list_display = ('key', 'value', 'description')
|
list_display = ('key', 'value')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Currency, CurrencyAdmin)
|
admin.site.register(Currency, CurrencyAdmin)
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.db.utils import OperationalError, ProgrammingError
|
from django.db.utils import OperationalError, ProgrammingError
|
||||||
|
|
||||||
import os
|
|
||||||
import uuid
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
|
|
||||||
class CommonConfig(AppConfig):
|
class CommonConfig(AppConfig):
|
||||||
name = 'common'
|
name = 'common'
|
||||||
@ -12,46 +8,8 @@ class CommonConfig(AppConfig):
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
|
|
||||||
""" Will be called when the Common app is first loaded """
|
""" Will be called when the Common app is first loaded """
|
||||||
self.populate_default_settings()
|
|
||||||
self.add_instance_name()
|
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__))
|
|
||||||
settings_file = os.path.join(here, 'kvp.yaml')
|
|
||||||
|
|
||||||
with open(settings_file) as kvp:
|
|
||||||
values = yaml.safe_load(kvp)
|
|
||||||
|
|
||||||
for value in values:
|
|
||||||
key = value['key']
|
|
||||||
default = value['default']
|
|
||||||
description = value['description']
|
|
||||||
|
|
||||||
try:
|
|
||||||
# If a particular setting does not exist in the database, create it now
|
|
||||||
if not InvenTreeSetting.objects.filter(key=key).exists():
|
|
||||||
setting = InvenTreeSetting(
|
|
||||||
key=key,
|
|
||||||
value=default,
|
|
||||||
description=description
|
|
||||||
)
|
|
||||||
|
|
||||||
setting.save()
|
|
||||||
|
|
||||||
print("Creating new key: '{k}' = '{v}'".format(k=key, v=default))
|
|
||||||
except (OperationalError, ProgrammingError):
|
|
||||||
# Migrations have not yet been applied - table does not exist
|
|
||||||
break
|
|
||||||
|
|
||||||
def add_instance_name(self):
|
def add_instance_name(self):
|
||||||
"""
|
"""
|
||||||
Check if an InstanceName has been defined for this database.
|
Check if an InstanceName has been defined for this database.
|
||||||
@ -64,14 +22,9 @@ class CommonConfig(AppConfig):
|
|||||||
try:
|
try:
|
||||||
if not InvenTreeSetting.objects.filter(key='InstanceName').exists():
|
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(
|
name = InvenTreeSetting(
|
||||||
key="InstanceName",
|
key="InstanceName",
|
||||||
value=val,
|
value="InvenTree Server"
|
||||||
description="Instance name for this InvenTree database installation."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
name.save()
|
name.save()
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
# This file contains the default values for the key:value settings available in InvenTree
|
|
||||||
# This file should not be edited locally.
|
|
||||||
|
|
||||||
# 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'
|
|
||||||
|
|
||||||
- key: part_deep_copy
|
|
||||||
default: True
|
|
||||||
description: 'Parts are deep-copied by default'
|
|
@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 3.0.7 on 2020-10-19 13:02
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('common', '0007_colortheme'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='inventreesetting',
|
||||||
|
name='description',
|
||||||
|
),
|
||||||
|
]
|
@ -76,8 +76,6 @@ class InvenTreeSetting(models.Model):
|
|||||||
|
|
||||||
value = models.CharField(max_length=200, blank=True, unique=False, help_text=_('Settings value'))
|
value = models.CharField(max_length=200, blank=True, unique=False, help_text=_('Settings value'))
|
||||||
|
|
||||||
description = models.CharField(max_length=200, blank=True, unique=False, help_text=_('Settings description'))
|
|
||||||
|
|
||||||
def validate_unique(self, exclude=None):
|
def validate_unique(self, exclude=None):
|
||||||
""" Ensure that the key:value pair is unique.
|
""" Ensure that the key:value pair is unique.
|
||||||
In addition to the base validators, this ensures that the 'key'
|
In addition to the base validators, this ensures that the 'key'
|
||||||
|
Loading…
Reference in New Issue
Block a user