mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-13 19:18:16 -06:00
Rebuilt feature to be opt-in instead of opt-out so that default/old behaviour is preserved by default. Added settings flag to controll the wanted default behaviour of the show/hide feature. Added docs for the new settingss value.
This commit is contained in:
parent
58f56f2deb
commit
6d8f97eea5
@ -255,6 +255,14 @@ Enable this option to run the webhook backend. See the docs section on the webho
|
||||
|
||||
---
|
||||
|
||||
## HIDE_AVAILABLE_PREFIXES
|
||||
|
||||
Default: False
|
||||
|
||||
Enable this option if you want to hide all available child prefixes and child ip addresses that is shown by default if this option is set to False.
|
||||
|
||||
---
|
||||
|
||||
## Date and Time Formatting
|
||||
|
||||
You may define custom formatting for date and times. For detailed instructions on writing format strings, please see [the Django documentation](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date).
|
||||
|
@ -500,10 +500,23 @@ class PrefixPrefixesView(View):
|
||||
'site', 'vlan', 'role',
|
||||
).annotate_depth(limit=0)
|
||||
|
||||
# Annotate available prefixes
|
||||
if request.GET.get('show_available', None):
|
||||
if child_prefixes:
|
||||
if not settings.HIDE_AVAILABLE_PREFIXES:
|
||||
# Show all available unless explicit set not to show
|
||||
if request.GET.get('show_available', '') == 'off':
|
||||
show_available = False
|
||||
else:
|
||||
# Default to show all available when default configuration is set
|
||||
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
||||
show_available = True
|
||||
else:
|
||||
# Default set to always hide available,
|
||||
# but explicit want to show addresses anyway
|
||||
if request.GET.get('show_available', '') == 'on':
|
||||
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
||||
show_available = True
|
||||
else:
|
||||
# Setting is set to True then hide them by default
|
||||
show_available = False
|
||||
|
||||
prefix_table = tables.PrefixDetailTable(child_prefixes)
|
||||
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
|
||||
@ -529,6 +542,7 @@ class PrefixPrefixesView(View):
|
||||
'permissions': permissions,
|
||||
'bulk_querystring': 'vrf_id={}&within={}'.format(prefix.vrf.pk if prefix.vrf else '0', prefix.prefix),
|
||||
'active_tab': 'prefixes',
|
||||
'show_available': show_available,
|
||||
})
|
||||
|
||||
|
||||
@ -542,8 +556,24 @@ class PrefixIPAddressesView(View):
|
||||
ipaddresses = prefix.get_child_ips().select_related(
|
||||
'vrf', 'interface__device', 'primary_ip4_for', 'primary_ip6_for'
|
||||
)
|
||||
if request.GET.get('show_available', None):
|
||||
ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses, prefix.is_pool)
|
||||
|
||||
if not settings.HIDE_AVAILABLE_PREFIXES:
|
||||
# Show all available unless explicit set not to show
|
||||
if request.GET.get('show_available', '') == 'off':
|
||||
show_available = False
|
||||
else:
|
||||
# Default to show all available when default configuration is set
|
||||
ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses, prefix.is_pool)
|
||||
show_available = True
|
||||
else:
|
||||
# Default set to always hide available,
|
||||
# but explicit want to show addresses anyway
|
||||
if request.GET.get('show_available', '') == 'on':
|
||||
ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses, prefix.is_pool)
|
||||
show_available = True
|
||||
else:
|
||||
# Setting is set to True then hide them by default
|
||||
show_available = False
|
||||
|
||||
ip_table = tables.IPAddressTable(ipaddresses)
|
||||
if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'):
|
||||
@ -569,6 +599,7 @@ class PrefixIPAddressesView(View):
|
||||
'permissions': permissions,
|
||||
'bulk_querystring': 'vrf_id={}&parent={}'.format(prefix.vrf.pk if prefix.vrf else '0', prefix.prefix),
|
||||
'active_tab': 'ip-addresses',
|
||||
'show_available': show_available,
|
||||
})
|
||||
|
||||
|
||||
|
@ -74,6 +74,7 @@ SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s')
|
||||
TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a')
|
||||
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
|
||||
WEBHOOKS_ENABLED = getattr(configuration, 'WEBHOOKS_ENABLED', False)
|
||||
HIDE_AVAILABLE_PREFIXES = getattr(configuration, 'HIDE_AVAILABLE_PREFIXES', False)
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS
|
||||
|
||||
|
@ -54,22 +54,22 @@
|
||||
{% include 'inc/created_updated.html' with obj=prefix %}
|
||||
<div class="pull-right">
|
||||
<div class="btn-group" role="group">
|
||||
<a href="{{ request.path }}{% querystring request show_available=None %}" class="btn btn-default{% if not request.GET.show_available %} active{% endif %}">Hide available</a>
|
||||
<a href="{{ request.path }}{% querystring request show_available='on' %}" class="btn btn-default{% if request.GET.show_available %} active{% endif %}">Show available</a>
|
||||
<a href="{{ request.path }}{% querystring request show_available='on' %}" class="btn btn-default{% if show_available %} active{% endif %}">Show available</a>
|
||||
<a href="{{ request.path }}{% querystring request show_available='off' %}" class="btn btn-default{% if not show_available %} active{% endif %}">Hide available</a>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="nav nav-tabs" style="margin-bottom: 20px">
|
||||
<li role="presentation"{% if not active_tab %} class="active"{% endif %}>
|
||||
<a href="{% url 'ipam:prefix' pk=prefix.pk %}{% if request.GET.show_available %}{% querystring request show_available='on' %}{% endif %}">Prefix</a>
|
||||
<a href="{% url 'ipam:prefix' pk=prefix.pk %}">Prefix</a>
|
||||
</li>
|
||||
<li role="presentation"{% if active_tab == 'prefixes' %} class="active"{% endif %}>
|
||||
<a href="{% url 'ipam:prefix_prefixes' pk=prefix.pk %}{% if request.GET.show_available %}{% querystring request show_available='on' %}{% endif %}">Child Prefixes <span class="badge">{{ prefix.get_child_prefixes.count }}</span></a>
|
||||
<a href="{% url 'ipam:prefix_prefixes' pk=prefix.pk %}">Child Prefixes <span class="badge">{{ prefix.get_child_prefixes.count }}</span></a>
|
||||
</li>
|
||||
<li role="presentation"{% if active_tab == 'ip-addresses' %} class="active"{% endif %}>
|
||||
<a href="{% url 'ipam:prefix_ipaddresses' pk=prefix.pk %}{% if request.GET.show_available %}{% querystring request show_available='on' %}{% endif %}">IP Addresses <span class="badge">{{ prefix.get_child_ips.count }}</span></a>
|
||||
<a href="{% url 'ipam:prefix_ipaddresses' pk=prefix.pk %}">IP Addresses <span class="badge">{{ prefix.get_child_ips.count }}</span></a>
|
||||
</li>
|
||||
<li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
|
||||
<a href="{% url 'ipam:prefix_changelog' pk=prefix.pk %}{% if request.GET.show_available %}{% querystring request show_available='on' %}{% endif %}">Changelog</a>
|
||||
<a href="{% url 'ipam:prefix_changelog' pk=prefix.pk %}">Changelog</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user