mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 03:56:43 +00:00
Adds a user-configurable setting to configure how dates are displayed (on the front end only!)
This commit is contained in:
parent
010ce48ce0
commit
b19719516b
@ -443,12 +443,12 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
except self.DoesNotExist:
|
except self.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def choices(self):
|
def choices(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Return the available choices for this setting (or None if no choices are defined)
|
Return the available choices for this setting (or None if no choices are defined)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.__class__.get_setting_choices(self.key)
|
return self.__class__.get_setting_choices(self.key, **kwargs)
|
||||||
|
|
||||||
def valid_options(self):
|
def valid_options(self):
|
||||||
"""
|
"""
|
||||||
@ -462,6 +462,34 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
|
|
||||||
return [opt[0] for opt in choices]
|
return [opt[0] for opt in choices]
|
||||||
|
|
||||||
|
def is_choice(self, **kwargs):
|
||||||
|
"""
|
||||||
|
Check if this setting is a "choice" field
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.__class__.get_setting_choices(self.key, **kwargs) != None
|
||||||
|
|
||||||
|
def as_choice(self, **kwargs):
|
||||||
|
"""
|
||||||
|
Render this setting as the "display" value of a choice field,
|
||||||
|
e.g. if the choices are:
|
||||||
|
[('A4', 'A4 paper'), ('A3', 'A3 paper')],
|
||||||
|
and the value is 'A4',
|
||||||
|
then display 'A4 paper'
|
||||||
|
"""
|
||||||
|
|
||||||
|
choices = self.get_setting_choices(self.key, **kwargs)
|
||||||
|
|
||||||
|
if not choices:
|
||||||
|
return self.value
|
||||||
|
|
||||||
|
for value, display in choices:
|
||||||
|
if value == self.value:
|
||||||
|
return display
|
||||||
|
|
||||||
|
return self.value
|
||||||
|
|
||||||
|
|
||||||
def is_bool(self, **kwargs):
|
def is_bool(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Check if this setting is required to be a boolean value
|
Check if this setting is required to be a boolean value
|
||||||
@ -1212,6 +1240,21 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
|
|||||||
'default': False,
|
'default': False,
|
||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'DATE_DISPLAY_FORMAT': {
|
||||||
|
'name': _('Date Format'),
|
||||||
|
'description': _('Preferred format for displaying dates'),
|
||||||
|
'default': 'YYYY-MM-DD',
|
||||||
|
'choices': [
|
||||||
|
('YYYY-MM-DD', '2022-02-22'),
|
||||||
|
('YYYY/MM/DD', '2022/22/22'),
|
||||||
|
('DD-MM-YYYY', '22-02-2022'),
|
||||||
|
('DD/MM/YYYY', '22/02/2022'),
|
||||||
|
('MM-DD-YYYY', '02-22-2022'),
|
||||||
|
('MM/DD/YYYY', '02/22/2022'),
|
||||||
|
('MMM DD YYYY', 'Feb 22 2022'),
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -28,7 +28,11 @@
|
|||||||
<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.key.upper }}' fieldname='{{ setting.key.upper }}'>
|
||||||
{% if setting.value %}
|
{% if setting.value %}
|
||||||
|
{% if setting.is_choice %}
|
||||||
|
<strong>{{ setting.as_choice }}</strong>
|
||||||
|
{% else %}
|
||||||
<strong>{{ setting.value }}</strong>
|
<strong>{{ setting.value }}</strong>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<em style='color: #855;'>{% trans "No value set" %}</em>
|
<em style='color: #855;'>{% trans "No value set" %}</em>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
<table class='table table-striped table-condensed'>
|
<table class='table table-striped table-condensed'>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% include "InvenTree/settings/setting.html" with key="STICKY_HEADER" icon="fa-bars" user_setting=True %}
|
{% include "InvenTree/settings/setting.html" with key="STICKY_HEADER" icon="fa-bars" user_setting=True %}
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="DATE_DISPLAY_FORMAT" icon="fa-calendar-alt" user_setting=True %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="FORMS_CLOSE_USING_ESCAPE" icon="fa-window-close" user_setting=True %}
|
{% include "InvenTree/settings/setting.html" with key="FORMS_CLOSE_USING_ESCAPE" icon="fa-window-close" user_setting=True %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_QUANTITY_IN_FORMS" icon="fa-hashtag" user_setting=True %}
|
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_QUANTITY_IN_FORMS" icon="fa-hashtag" user_setting=True %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -40,12 +40,15 @@ function editSetting(pk, options={}) {
|
|||||||
url = `/api/settings/user/${pk}/`;
|
url = `/api/settings/user/${pk}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var reload_required = false;
|
||||||
|
|
||||||
// First, read the settings object from the server
|
// First, read the settings object from the server
|
||||||
inventreeGet(url, {}, {
|
inventreeGet(url, {}, {
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
|
||||||
if (response.choices && response.choices.length > 0) {
|
if (response.choices && response.choices.length > 0) {
|
||||||
response.type = 'choice';
|
response.type = 'choice';
|
||||||
|
reload_required = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the field
|
// Construct the field
|
||||||
@ -89,7 +92,9 @@ function editSetting(pk, options={}) {
|
|||||||
|
|
||||||
var setting = response.key;
|
var setting = response.key;
|
||||||
|
|
||||||
if (response.type == 'boolean') {
|
if (reload_required) {
|
||||||
|
location.reload();
|
||||||
|
} 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}`).prop('checked', enabled);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user