out-of-scope:update settings value lookup to include typ (#3636)

This commit is contained in:
Matthias Mair 2022-09-02 08:51:16 +02:00 committed by GitHub
parent 23edd79431
commit eaaf98f9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 5 deletions

View File

@ -1329,6 +1329,8 @@ class InvenTreeSetting(BaseInvenTreeSetting):
}, },
} }
typ = 'inventree'
class Meta: class Meta:
"""Meta options for InvenTreeSetting.""" """Meta options for InvenTreeSetting."""
@ -1642,6 +1644,8 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
}, },
} }
typ = 'user'
class Meta: class Meta:
"""Meta options for InvenTreeUserSetting.""" """Meta options for InvenTreeUserSetting."""

View File

@ -70,6 +70,7 @@ class GlobalSettingsSerializer(SettingsSerializer):
'choices', 'choices',
'model_name', 'model_name',
'api_url', 'api_url',
'typ',
] ]
@ -93,6 +94,7 @@ class UserSettingsSerializer(SettingsSerializer):
'choices', 'choices',
'model_name', 'model_name',
'api_url', 'api_url',
'typ',
] ]
@ -122,6 +124,7 @@ class GenericReferencedSettingSerializer(SettingsSerializer):
'choices', 'choices',
'model_name', 'model_name',
'api_url', 'api_url',
'typ',
] ]
# set Meta class # set Meta class

View File

@ -173,6 +173,8 @@ class PluginConfig(models.Model):
class PluginSetting(common.models.BaseInvenTreeSetting): class PluginSetting(common.models.BaseInvenTreeSetting):
"""This model represents settings for individual plugins.""" """This model represents settings for individual plugins."""
typ = 'plugin'
class Meta: class Meta:
"""Meta for PluginSetting.""" """Meta for PluginSetting."""
unique_together = [ unique_together = [
@ -222,6 +224,8 @@ class PluginSetting(common.models.BaseInvenTreeSetting):
class NotificationUserSetting(common.models.BaseInvenTreeSetting): class NotificationUserSetting(common.models.BaseInvenTreeSetting):
"""This model represents notification settings for a user.""" """This model represents notification settings for a user."""
typ = 'notification'
class Meta: class Meta:
"""Meta for NotificationUserSetting.""" """Meta for NotificationUserSetting."""
unique_together = [ unique_together = [

View File

@ -24,11 +24,11 @@
<td> <td>
{% if setting.is_bool %} {% if setting.is_bool %}
<div class='form-check form-switch'> <div class='form-check form-switch'>
<input class='form-check-input boolean-setting' fieldname='{{ setting.key.upper }}' pk='{{ setting.pk }}' setting='{{ setting.key.upper }}' id='setting-value-{{ setting.key.upper }}' type='checkbox' {% if setting.as_bool %}checked=''{% endif %} {% if plugin %}plugin='{{ plugin.slug }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}{% if notification_setting %}notification='{{request.user.id}}'{% endif %}> <input class='form-check-input boolean-setting' fieldname='{{ setting.key.upper }}' pk='{{ setting.pk }}' setting='{{ setting.key.upper }}' id='setting-value-{{ setting.pk }}-{{ setting.typ }}' type='checkbox' {% if setting.as_bool %}checked=''{% endif %}{{reference}}>
</div> </div>
{% else %} {% else %}
<div id='setting-{{ setting.pk }}'> <div id='setting-{{ setting.pk }}'>
<span id='setting-value-{{ setting.key.upper }}' fieldname='{{ setting.key.upper }}'> <span id='setting-value-{{ setting.pk }}-{{ setting.typ }}' fieldname='{{ setting.key.upper }}'>
{% if setting.value %} {% if setting.value %}
{% if setting.is_choice %} {% if setting.is_choice %}
<strong>{{ setting.as_choice }}</strong> <strong>{{ setting.as_choice }}</strong>

View File

@ -118,15 +118,16 @@ function editSetting(key, options={}) {
}, },
onSuccess: function(response) { onSuccess: function(response) {
var setting = response.key; var setting_pk = response.pk;
var setting_typ = response.typ;
if (reload_required) { if (reload_required) {
location.reload(); location.reload();
} else if (response.type == 'boolean') { } else if (response.type == 'boolean') {
var enabled = response.value.toString().toLowerCase() == 'true'; var enabled = response.value.toString().toLowerCase() == 'true';
$(`#setting-value-${setting}`).prop('checked', enabled); $(`#setting-value-${setting_pk}-${setting_typ}`).prop('checked', enabled);
} else { } else {
$(`#setting-value-${setting}`).html(response.value); $(`#setting-value-${setting_pk}-${setting_typ}`).html(response.value);
} }
} }
}); });