2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 03:25:42 +00:00

remove css template functions

This commit is contained in:
Matthias Mair
2024-10-28 21:13:06 +01:00
parent 5a2eaf77ec
commit c7cffbe1b6
2 changed files with 0 additions and 114 deletions

View File

@ -8,7 +8,6 @@ from django import template
from django.conf import settings as djangosettings
from django.templatetags.static import StaticNode
from django.urls import NoReverseMatch, reverse
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
@ -395,117 +394,6 @@ def visible_global_settings(*args, **kwargs):
return common.models.InvenTreeSetting.allValues(exclude_hidden=True)
@register.simple_tag()
def progress_bar(val, max_val, *args, **kwargs):
"""Render a progress bar element."""
item_id = kwargs.get('id', 'progress-bar')
val = InvenTree.helpers.normalize(val)
max_val = InvenTree.helpers.normalize(max_val)
if val > max_val:
style = 'progress-bar-over'
elif val < max_val:
style = 'progress-bar-under'
else:
style = ''
percent = float(val / max_val) * 100 if max_val != 0 else 0
if percent > 100:
percent = 100
elif percent < 0:
percent = 0
style_tags = []
max_width = kwargs.get('max_width')
if max_width:
style_tags.append(f'max-width: {max_width};')
html = f"""
<div id='{item_id}' class='progress' style='{' '.join(style_tags)}'>
<div class='progress-bar {style}' role='progressbar' aria-valuemin='0' aria-valuemax='100' style='width:{percent}%'></div>
<div class='progress-value'>{val} / {max_val}</div>
</div>
"""
return mark_safe(html)
@register.simple_tag()
def get_color_theme_css(user):
"""Return the custom theme .css file for the selected user."""
user_theme_name = get_user_color_theme(user)
# Build path to CSS sheet
inventree_css_sheet = os.path.join('css', 'color-themes', user_theme_name + '.css')
# Build static URL
inventree_css_static_url = os.path.join(settings.STATIC_URL, inventree_css_sheet)
return inventree_css_static_url
@register.simple_tag()
def get_user_color_theme(user):
"""Get current user color theme."""
from common.models import ColorTheme
try:
if not user.is_authenticated:
return 'default'
except Exception:
return 'default'
try:
user_theme = ColorTheme.objects.filter(user_obj=user).get()
user_theme_name = user_theme.name
if not user_theme_name or not ColorTheme.is_valid_choice(user_theme):
user_theme_name = 'default'
except ColorTheme.DoesNotExist:
user_theme_name = 'default'
return user_theme_name
@register.simple_tag()
def get_available_themes(*args, **kwargs):
"""Return the available theme choices."""
themes = []
from common.models import ColorTheme
for key, name in ColorTheme.get_color_themes_choices():
themes.append({'key': key, 'name': name})
return themes
@register.simple_tag()
def primitive_to_javascript(primitive):
"""Convert a python primitive to a javascript primitive.
e.g. True -> true
'hello' -> '"hello"'
"""
if type(primitive) is bool:
return str(primitive).lower()
elif type(primitive) in [int, float]:
return primitive
# Wrap with quotes
return format_html("'{}'", primitive)
@register.simple_tag()
def js_bool(val):
"""Return a javascript boolean value (true or false)."""
if val:
return 'true'
return 'false'
@register.filter
def keyvalue(dict, key):
"""Access to key of supplied dict.

View File

@ -54,8 +54,6 @@
<link rel="stylesheet" href="{% static 'css/inventree.css' %}">
<link rel="stylesheet" href="{% get_color_theme_css request.user %}">
<style>
{% block css %}
<!-- Custom CSS style goes here -->