Repository: netbox-community/netbox

Issue:
Toggle suggested/Available prefixes in Child Prefix tab
<!--
    NOTE: This form is only for proposing specific new features or enhancements.
    If you have a general idea or question, please post to our mailing list
    instead of opening an issue:

        https://groups.google.com/forum/#!forum/netbox-discuss

    NOTE: Due to an excessive backlog of feature requests, we are not currently
    accepting any proposals which significantly extend NetBox's feature scope.

    Please describe the environment in which you are running NetBox. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report.
-->
### Environment
* Python version:  3.4.3
* NetBox version: 2.4.1

<!--
    Describe in detail the new functionality you are proposing. Include any
    specific changes to work flows, data models, or the user interface.
-->
### Proposed Functionality
Currently, when clicking on the Child Prefix tab of a given prefix, it shows 'Active' and 'Available' prefixes. A button to show/hide the 'Available' prefixes would be useful.

<!--
    Convey an example use case for your proposed feature. Write from the
    perspective of a NetBox user who would benefit from the proposed
    functionality and describe how.
--->
### Use Case

Daily prefix view

<!--
    Note any changes to the database schema necessary to support the new
    feature. For example, does the proposal require adding a new model or
    field? (Not all new features require database changes.)
--->
### Database Changes


<!--
    List any new dependencies on external libraries or services that this new
    feature would introduce. For example, does the proposal require the
    installation of a new Python package? (Not all new features introduce new
    dependencies.)
-->
### External Dependencies



Discussion:
Thank you for your interest in NetBox. We require that all issues be submitted using one of the templates provided [here](https://github.com/digitalocean/netbox/tree/develop/.github/ISSUE_TEMPLATE). This is to ensure that only valid issues are reported and that each issue includes all the information necessary for a developer to act on it. Please update your issue so that it matches the appropriate template (this may require rewriting your issue entirely). This issue will be closed in one week if it has not been updated. Thanks!

Resolving patch:
diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py
--- a/netbox/ipam/views.py
+++ b/netbox/ipam/views.py
@@ -333,7 +333,10 @@ def get(self, request, pk):
         ).annotate_depth(
             limit=0
         )
-        child_prefixes = add_available_prefixes(aggregate.prefix, child_prefixes)
+
+        # Add available prefixes to the table if requested
+        if request.GET.get('show_available', 'true') == 'true':
+            child_prefixes = add_available_prefixes(aggregate.prefix, child_prefixes)
 
         prefix_table = tables.PrefixDetailTable(child_prefixes)
         if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
@@ -356,6 +359,7 @@ def get(self, request, pk):
             'aggregate': aggregate,
             'prefix_table': prefix_table,
             'permissions': permissions,
+            'show_available': request.GET.get('show_available', 'true') == 'true',
         })
 
 
@@ -511,8 +515,8 @@ def get(self, request, pk):
             'site', 'vlan', 'role',
         ).annotate_depth(limit=0)
 
-        # Annotate available prefixes
-        if child_prefixes:
+        # Add available prefixes to the table if requested
+        if child_prefixes and request.GET.get('show_available', 'true') == 'true':
             child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
 
         prefix_table = tables.PrefixDetailTable(child_prefixes)
@@ -539,6 +543,7 @@ def get(self, request, pk):
             'permissions': permissions,
             'bulk_querystring': 'vrf_id={}&within={}'.format(prefix.vrf.pk if prefix.vrf else '0', prefix.prefix),
             'active_tab': 'prefixes',
+            'show_available': request.GET.get('show_available', 'true') == 'true',
         })
 
 
@@ -553,7 +558,10 @@ def get(self, request, pk):
         ipaddresses = prefix.get_child_ips().prefetch_related(
             'vrf', 'interface__device', 'primary_ip4_for', 'primary_ip6_for'
         )
-        ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses, prefix.is_pool)
+
+        # Add available IP addresses to the table if requested
+        if request.GET.get('show_available', 'true') == 'true':
+            ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses, prefix.is_pool)
 
         ip_table = tables.IPAddressTable(ipaddresses)
         if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'):
@@ -579,6 +587,7 @@ def get(self, request, pk):
             'permissions': permissions,
             'bulk_querystring': 'vrf_id={}&parent={}'.format(prefix.vrf.pk if prefix.vrf else '0', prefix.prefix),
             'active_tab': 'ip-addresses',
+            'show_available': request.GET.get('show_available', 'true') == 'true',
         })
 
 


Test patch: