Remove "description" field from InvenTreeSettings key:value fields

This commit is contained in:
Oliver Walters 2020-10-20 00:02:54 +11:00
parent 92c1e3c1a5
commit 06040f94ee
5 changed files with 19 additions and 67 deletions

View File

@ -14,7 +14,7 @@ class CurrencyAdmin(ImportExportModelAdmin):
class SettingsAdmin(ImportExportModelAdmin):
list_display = ('key', 'value', 'description')
list_display = ('key', 'value')
admin.site.register(Currency, CurrencyAdmin)

View File

@ -1,10 +1,6 @@
from django.apps import AppConfig
from django.db.utils import OperationalError, ProgrammingError
import os
import uuid
import yaml
class CommonConfig(AppConfig):
name = 'common'
@ -12,46 +8,8 @@ class CommonConfig(AppConfig):
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__))
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):
"""
Check if an InstanceName has been defined for this database.
@ -64,14 +22,9 @@ class CommonConfig(AppConfig):
try:
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."
value="InvenTree Server"
)
name.save()

View File

@ -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'

View File

@ -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',
),
]

View File

@ -76,8 +76,6 @@ class InvenTreeSetting(models.Model):
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):
""" Ensure that the key:value pair is unique.
In addition to the base validators, this ensures that the 'key'