change template setting behaviour for user setting

This commit is contained in:
Matthias 2021-07-22 23:48:28 +02:00
parent e287860e10
commit 3f6c7df7a8
3 changed files with 18 additions and 7 deletions

View File

@ -18,7 +18,7 @@ from InvenTree import version, settings
import InvenTree.helpers import InvenTree.helpers
from common.models import InvenTreeSetting, ColorTheme from common.models import InvenTreeSetting, ColorTheme, InvenTreeUserSetting
from common.settings import currency_code_default from common.settings import currency_code_default
register = template.Library() register = template.Library()
@ -182,11 +182,12 @@ def setting_object(key, *args, **kwargs):
""" """
Return a setting object speciifed by the given key Return a setting object speciifed by the given key
(Or return None if the setting does not exist) (Or return None if the setting does not exist)
if a user-setting was requested return that
""" """
setting = InvenTreeSetting.get_setting_object(key) if 'user' in kwargs:
return InvenTreeUserSetting.get_setting_object(key, user=kwargs['user'])
return setting return InvenTreeSetting.get_setting_object(key)
@register.simple_tag() @register.simple_tag()

View File

@ -1,7 +1,12 @@
{% load inventree_extras %} {% load inventree_extras %}
{% load i18n %} {% load i18n %}
{% if user_setting %}
{% setting_object key user=request.user as setting %}
{% else %}
{% setting_object key as setting %} {% setting_object key as setting %}
{% endif %}
<tr> <tr>
<td> <td>
{% if icon %} {% if icon %}
@ -28,7 +33,7 @@
</td> </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' pk='{{ setting.pk }}' setting='{{ key }}' title='{% trans "Edit setting" %}'> <button class='btn btn-default btn-glyph btn-edit-setting' pk='{{ setting.pk }}' setting='{{ key }}' title='{% trans "Edit setting" %}' {% if user_setting %}user='{{request.user.id}}'{% endif %}>
<span class='fas fa-edit icon-green'></span> <span class='fas fa-edit icon-green'></span>
</button> </button>
</div> </div>

View File

@ -45,9 +45,14 @@
$('table').find('.btn-edit-setting').click(function() { $('table').find('.btn-edit-setting').click(function() {
var setting = $(this).attr('setting'); var setting = $(this).attr('setting');
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
var url = `/settings/${pk}/edit/`;
if ($(this).attr('user')){
url += `user/`;
}
launchModalForm( launchModalForm(
`/settings/${pk}/edit/`, url,
{ {
reload: true, reload: true,
} }