mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix imports in inventree_extras.py (#5770)
- Can cause a circular import - Ref: https://github.com/inventree/inventree-app/actions/runs/6603924590/job/17937528806
This commit is contained in:
parent
4d79c9f985
commit
d03927dea4
@ -13,9 +13,9 @@ from django.utils.html import format_html
|
|||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
import common.models
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
import InvenTree.helpers_model
|
import InvenTree.helpers_model
|
||||||
from common.models import ColorTheme, InvenTreeSetting, InvenTreeUserSetting
|
|
||||||
from common.settings import currency_code_default
|
from common.settings import currency_code_default
|
||||||
from InvenTree import settings, version
|
from InvenTree import settings, version
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
@ -79,7 +79,7 @@ def render_date(context, date_object):
|
|||||||
|
|
||||||
if user and user.is_authenticated:
|
if user and user.is_authenticated:
|
||||||
# User is specified - look for their date display preference
|
# User is specified - look for their date display preference
|
||||||
user_date_format = InvenTreeUserSetting.get_setting('DATE_DISPLAY_FORMAT', user=user)
|
user_date_format = common.models.InvenTreeUserSetting.get_setting('DATE_DISPLAY_FORMAT', user=user)
|
||||||
else:
|
else:
|
||||||
user_date_format = 'YYYY-MM-DD'
|
user_date_format = 'YYYY-MM-DD'
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ def inventree_in_debug_mode(*args, **kwargs):
|
|||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_show_about(user, *args, **kwargs):
|
def inventree_show_about(user, *args, **kwargs):
|
||||||
"""Return True if the about modal should be shown."""
|
"""Return True if the about modal should be shown."""
|
||||||
if InvenTreeSetting.get_setting('INVENTREE_RESTRICT_ABOUT'):
|
if common.models.InvenTreeSetting.get_setting('INVENTREE_RESTRICT_ABOUT'):
|
||||||
# Return False if the user is not a superuser, or no user information is provided
|
# Return False if the user is not a superuser, or no user information is provided
|
||||||
if not user or not user.is_superuser:
|
if not user or not user.is_superuser:
|
||||||
return False
|
return False
|
||||||
@ -356,10 +356,10 @@ def setting_object(key, *args, **kwargs):
|
|||||||
return NotificationUserSetting.get_setting_object(key, user=kwargs['user'], method=kwargs['method'], cache=cache)
|
return NotificationUserSetting.get_setting_object(key, user=kwargs['user'], method=kwargs['method'], cache=cache)
|
||||||
|
|
||||||
elif 'user' in kwargs:
|
elif 'user' in kwargs:
|
||||||
return InvenTreeUserSetting.get_setting_object(key, user=kwargs['user'], cache=cache)
|
return common.models.InvenTreeUserSetting.get_setting_object(key, user=kwargs['user'], cache=cache)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return InvenTreeSetting.get_setting_object(key, cache=cache)
|
return common.models.InvenTreeSetting.get_setting_object(key, cache=cache)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
@ -367,28 +367,28 @@ def settings_value(key, *args, **kwargs):
|
|||||||
"""Return a settings value specified by the given key."""
|
"""Return a settings value specified by the given key."""
|
||||||
if 'user' in kwargs:
|
if 'user' in kwargs:
|
||||||
if not kwargs['user'] or (kwargs['user'] and kwargs['user'].is_authenticated is False):
|
if not kwargs['user'] or (kwargs['user'] and kwargs['user'].is_authenticated is False):
|
||||||
return InvenTreeUserSetting.get_setting(key)
|
return common.models.InvenTreeUserSetting.get_setting(key)
|
||||||
return InvenTreeUserSetting.get_setting(key, user=kwargs['user'])
|
return common.models.InvenTreeUserSetting.get_setting(key, user=kwargs['user'])
|
||||||
|
|
||||||
return InvenTreeSetting.get_setting(key)
|
return common.models.InvenTreeSetting.get_setting(key)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def user_settings(user, *args, **kwargs):
|
def user_settings(user, *args, **kwargs):
|
||||||
"""Return all USER settings as a key:value dict."""
|
"""Return all USER settings as a key:value dict."""
|
||||||
return InvenTreeUserSetting.allValues(user=user)
|
return common.models.InvenTreeUserSetting.allValues(user=user)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def global_settings(*args, **kwargs):
|
def global_settings(*args, **kwargs):
|
||||||
"""Return all GLOBAL InvenTree settings as a key:value dict."""
|
"""Return all GLOBAL InvenTree settings as a key:value dict."""
|
||||||
return InvenTreeSetting.allValues()
|
return common.models.InvenTreeSetting.allValues()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def visible_global_settings(*args, **kwargs):
|
def visible_global_settings(*args, **kwargs):
|
||||||
"""Return any global settings which are not marked as 'hidden'."""
|
"""Return any global settings which are not marked as 'hidden'."""
|
||||||
return InvenTreeSetting.allValues(exclude_hidden=True)
|
return common.models.InvenTreeSetting.allValues(exclude_hidden=True)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
@ -435,7 +435,7 @@ def progress_bar(val, max_val, *args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def get_color_theme_css(username):
|
def get_color_theme_css(username):
|
||||||
"""Return the cutsom theme .css file for the selected user"""
|
"""Return the custom theme .css file for the selected user"""
|
||||||
user_theme_name = get_user_color_theme(username)
|
user_theme_name = get_user_color_theme(username)
|
||||||
# Build path to CSS sheet
|
# Build path to CSS sheet
|
||||||
inventree_css_sheet = os.path.join('css', 'color-themes', user_theme_name + '.css')
|
inventree_css_sheet = os.path.join('css', 'color-themes', user_theme_name + '.css')
|
||||||
@ -449,6 +449,9 @@ def get_color_theme_css(username):
|
|||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def get_user_color_theme(username):
|
def get_user_color_theme(username):
|
||||||
"""Get current user color theme."""
|
"""Get current user color theme."""
|
||||||
|
|
||||||
|
from common.models import ColorTheme
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_theme = ColorTheme.objects.filter(user=username).get()
|
user_theme = ColorTheme.objects.filter(user=username).get()
|
||||||
user_theme_name = user_theme.name
|
user_theme_name = user_theme.name
|
||||||
@ -465,6 +468,8 @@ def get_available_themes(*args, **kwargs):
|
|||||||
"""Return the available theme choices."""
|
"""Return the available theme choices."""
|
||||||
themes = []
|
themes = []
|
||||||
|
|
||||||
|
from common.models import ColorTheme
|
||||||
|
|
||||||
for key, name in ColorTheme.get_color_themes_choices():
|
for key, name in ColorTheme.get_color_themes_choices():
|
||||||
themes.append({
|
themes.append({
|
||||||
'key': key,
|
'key': key,
|
||||||
|
Loading…
Reference in New Issue
Block a user