1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Merge v3.1.2

This commit is contained in:
jeremystretch
2021-12-20 16:28:11 -05:00
46 changed files with 564 additions and 210 deletions

View File

@@ -1 +1,16 @@
{% include 'django/forms/widgets/number.html' %}
<div class="input-group">
{% include 'django/forms/widgets/number.html' %}
<button type="button" class="btn btn-outline-dark border-input dropdown-toggle" data-bs-toggle="dropdown"></button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a href="#" target="id_{{ widget.name }}" data="10000" class="set_speed dropdown-item">10 Mbps</a></li>
<li><a href="#" target="id_{{ widget.name }}" data="100000" class="set_speed dropdown-item">100 Mbps</a></li>
<li><a href="#" target="id_{{ widget.name }}" data="1000000" class="set_speed dropdown-item">1 Gbps</a></li>
<li><a href="#" target="id_{{ widget.name }}" data="10000000" class="set_speed dropdown-item">10 Gbps</a></li>
<li><a href="#" target="id_{{ widget.name }}" data="25000000" class="set_speed dropdown-item">25 Gbps</a></li>
<li><a href="#" target="id_{{ widget.name }}" data="40000000" class="set_speed dropdown-item">40 Gbps</a></li>
<li><a href="#" target="id_{{ widget.name }}" data="100000000" class="set_speed dropdown-item">100 Gbps</a></li>
<li><hr class="dropdown-divider"/></li>
<li><a href="#" target="id_{{ widget.name }}" data="1544" class="set_speed dropdown-item">T1 (1.544 Mbps)</a></li>
<li><a href="#" target="id_{{ widget.name }}" data="2048" class="set_speed dropdown-item">E1 (2.048 Mbps)</a></li>
</ul>
</div>

View File

@@ -30,7 +30,7 @@ def clone_button(instance):
url = reverse(_get_viewname(instance, 'add'))
# Populate cloned field values
param_string = prepare_cloned_fields(instance)
param_string = prepare_cloned_fields(instance).urlencode()
if param_string:
url = f'{url}?{param_string}'

View File

@@ -233,7 +233,7 @@ def fgcolor(value):
value = value.lower().strip('#')
if not re.match('^[0-9a-f]{6}$', value):
return ''
return '#{}'.format(foreground_color(value))
return f'#{foreground_color(value)}'
@register.filter()

View File

@@ -8,6 +8,7 @@ from typing import Any, Dict, List, Tuple
from django.core.serializers import serialize
from django.db.models import Count, OuterRef, Subquery
from django.db.models.functions import Coalesce
from django.http import QueryDict
from jinja2.sandbox import SandboxedEnvironment
from mptt.models import MPTTModel
@@ -53,9 +54,10 @@ def foreground_color(bg_color, dark='000000', light='ffffff'):
:param dark: RBG color code for dark text
:param light: RBG color code for light text
"""
THRESHOLD = 150
bg_color = bg_color.strip('#')
r, g, b = [int(bg_color[c:c + 2], 16) for c in (0, 2, 4)]
if r * 0.299 + g * 0.587 + b * 0.114 > 186:
if r * 0.299 + g * 0.587 + b * 0.114 > THRESHOLD:
return dark
else:
return light
@@ -248,10 +250,8 @@ def prepare_cloned_fields(instance):
for tag in instance.tags.all():
params.append(('tags', tag.pk))
# Concatenate parameters into a URL query string
param_string = '&'.join([f'{k}={v}' for k, v in params])
return param_string
# Return a QueryDict with the parameters
return QueryDict('&'.join([f'{k}={v}' for k, v in params]), mutable=True)
def shallow_compare_dict(source_dict, destination_dict, exclude=None):