mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Introduced fgcolor template filter to render ideal foreground color for any background color
This commit is contained in:
parent
aca57ec281
commit
f4a22e5af3
@ -29,7 +29,8 @@ SITE_REGION_LINK = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
COLOR_LABEL = """
|
COLOR_LABEL = """
|
||||||
<label class="label" style="background-color: #{{ record.color }}">{{ record }}</label>
|
{% load helpers %}
|
||||||
|
<label class="label" style="color: {{ record.color|fgcolor }}; background-color: #{{ record.color }}">{{ record }}</label>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DEVICE_LINK = """
|
DEVICE_LINK = """
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
|
|
||||||
from utilities.forms import unpack_grouped_choices
|
from utilities.forms import unpack_grouped_choices
|
||||||
|
from utilities.utils import foreground_color
|
||||||
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
@ -152,6 +154,17 @@ def tzoffset(value):
|
|||||||
return datetime.datetime.now(value).strftime('%z')
|
return datetime.datetime.now(value).strftime('%z')
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def fgcolor(value):
|
||||||
|
"""
|
||||||
|
Return black (#000000) or white (#ffffff) given an arbitrary background color in RRGGBB format.
|
||||||
|
"""
|
||||||
|
value = value.lower().strip('#')
|
||||||
|
if not re.match('^[0-9a-f]{6}$', value):
|
||||||
|
return ''
|
||||||
|
return '#{}'.format(foreground_color(value))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Tags
|
# Tags
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user