diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 0b4292cbd9..0c5c988ca0 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -39,6 +39,8 @@ from .views import IndexView, SearchView, DatabaseStatsView from .views import SettingsView, EditUserView, SetPasswordView, ColorThemeSelectView from .views import DynamicJsView +from common.views import SettingEdit + from .api import InfoView from .api import ActionPluginView @@ -78,6 +80,8 @@ settings_urls = [ url(r'^purchase-order/?', SettingsView.as_view(template_name='InvenTree/settings/po.html'), name='settings-po'), url(r'^sales-order/?', SettingsView.as_view(template_name='InvenTree/settings/so.html'), name='settings-so'), + url(r'^(?P\d+)/edit/?', SettingEdit.as_view(), name='setting-edit'), + # Catch any other urls url(r'^.*$', SettingsView.as_view(template_name='InvenTree/settings/user.html'), name='settings'), ] diff --git a/InvenTree/common/forms.py b/InvenTree/common/forms.py index 53493faff0..ba6289221e 100644 --- a/InvenTree/common/forms.py +++ b/InvenTree/common/forms.py @@ -33,6 +33,5 @@ class SettingEditForm(HelperForm): model = InvenTreeSetting fields = [ - 'key', 'value' ] diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 1c460225c8..434f0571e5 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -165,6 +165,22 @@ class InvenTreeSetting(models.Model): else: return '' + @classmethod + def get_setting_pk(cls, key): + """ + Return the primary-key value for a given setting. + + If the setting does not exist, return None + """ + + key = str(key).strip().upper() + + try: + setting = InvenTreeSetting.objects.filter(key__iexact=key).first() + return setting.pk + except InvenTreeSettingSetting.DoesNotExist: + return None + @classmethod def get_setting(cls, key, backup_value=None): """ diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 228d530934..54e9a0ba24 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -115,8 +115,17 @@ def settings_value(key, *args, **kwargs): """ Returns the value of a GLOBAL_SETTINGS object """ + return InvenTreeSetting.get_setting(key, backup_value=kwargs.get('backup', None)) +@register.simple_tag() +def settings_pk(key, *args, **kwargs): + """ + Return the ID (pk) of a GLOBAL_SETTINGS Object + """ + + return InvenTreeSetting.get_setting_pk(key) + @register.simple_tag() def get_color_theme_css(username): diff --git a/InvenTree/templates/InvenTree/settings/setting.html b/InvenTree/templates/InvenTree/settings/setting.html index 347b93553d..6f6a516b84 100644 --- a/InvenTree/templates/InvenTree/settings/setting.html +++ b/InvenTree/templates/InvenTree/settings/setting.html @@ -7,7 +7,7 @@ {% settings_description key %}
-
diff --git a/InvenTree/templates/InvenTree/settings/settings.html b/InvenTree/templates/InvenTree/settings/settings.html index 90adfd5fed..fe9fd00e53 100644 --- a/InvenTree/templates/InvenTree/settings/settings.html +++ b/InvenTree/templates/InvenTree/settings/settings.html @@ -37,3 +37,20 @@ InvenTree | {% trans "Settings" %} {% block js_load %} {{ block.super }} {% endblock %} + +{% block js_ready %} +{{ block.super }} + +$('table').find('.btn-edit-setting').click(function() { + var setting = $(this).attr('setting'); + var pk = $(this).attr('pk'); + + launchModalForm( + `/settings/${pk}/edit/`, + { + reload: true, + } + ); +}); + +{% endblock %}