Edit setting directly

This commit is contained in:
Oliver Walters 2020-10-25 08:02:46 +11:00
parent 10758a9626
commit 3e17bf3316
6 changed files with 47 additions and 2 deletions

View File

@ -39,6 +39,8 @@ from .views import IndexView, SearchView, DatabaseStatsView
from .views import SettingsView, EditUserView, SetPasswordView, ColorThemeSelectView from .views import SettingsView, EditUserView, SetPasswordView, ColorThemeSelectView
from .views import DynamicJsView from .views import DynamicJsView
from common.views import SettingEdit
from .api import InfoView from .api import InfoView
from .api import ActionPluginView 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'^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'^sales-order/?', SettingsView.as_view(template_name='InvenTree/settings/so.html'), name='settings-so'),
url(r'^(?P<pk>\d+)/edit/?', SettingEdit.as_view(), name='setting-edit'),
# Catch any other urls # Catch any other urls
url(r'^.*$', SettingsView.as_view(template_name='InvenTree/settings/user.html'), name='settings'), url(r'^.*$', SettingsView.as_view(template_name='InvenTree/settings/user.html'), name='settings'),
] ]

View File

@ -33,6 +33,5 @@ class SettingEditForm(HelperForm):
model = InvenTreeSetting model = InvenTreeSetting
fields = [ fields = [
'key',
'value' 'value'
] ]

View File

@ -165,6 +165,22 @@ class InvenTreeSetting(models.Model):
else: else:
return '' 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 @classmethod
def get_setting(cls, key, backup_value=None): def get_setting(cls, key, backup_value=None):
""" """

View File

@ -115,8 +115,17 @@ def settings_value(key, *args, **kwargs):
""" """
Returns the value of a GLOBAL_SETTINGS object Returns the value of a GLOBAL_SETTINGS object
""" """
return InvenTreeSetting.get_setting(key, backup_value=kwargs.get('backup', None)) 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() @register.simple_tag()
def get_color_theme_css(username): def get_color_theme_css(username):

View File

@ -7,7 +7,7 @@
<td>{% settings_description key %}</td> <td>{% settings_description key %}</td>
<td> <td>
<div class='btn-group float-right'> <div class='btn-group float-right'>
<button class='btn btn-default btn-glyph btn-edit-setting' setting='{{ key }}' title='{% trans "Edit setting" %}'> <button class='btn btn-default btn-glyph btn-edit-setting' pk='{% settings_pk key %}' setting='{{ key }}' title='{% trans "Edit setting" %}'>
<span class='fas fa-edit icon-green'></span> <span class='fas fa-edit icon-green'></span>
</button> </button>
</div> </div>

View File

@ -37,3 +37,20 @@ InvenTree | {% trans "Settings" %}
{% block js_load %} {% block js_load %}
{{ block.super }} {{ block.super }}
{% endblock %} {% 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 %}