Browse Source

Tweaked links to ensure that new child prefixes inherit the VRF and site of their parent by default

Jeremy Stretch 10 năm trước cách đây
mục cha
commit
7776ce5266
3 tập tin đã thay đổi với 10 bổ sung3 xóa
  1. 2 2
      netbox/ipam/tables.py
  2. 1 0
      netbox/ipam/views.py
  3. 7 1
      netbox/templates/ipam/prefix.html

+ 2 - 2
netbox/ipam/tables.py

@@ -21,13 +21,13 @@ PREFIX_LINK = """
 {% else %}
     <span style="padding-left: {{ record.depth }}9px">
 {% endif %}
-    <a href="{% if record.pk %}{% url 'ipam:prefix' pk=record.pk %}{% else %}{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if site %}&site={{ site.pk }}{% endif %}{% endif %}">{{ record.prefix }}</a>
+    <a href="{% if record.pk %}{% url 'ipam:prefix' pk=record.pk %}{% else %}{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if parent.vrf %}&vrf={{ parent.vrf.pk }}{% endif %}{% if parent.site %}&site={{ parent.site.pk }}{% endif %}{% endif %}">{{ record.prefix }}</a>
 </span>
 """
 
 PREFIX_LINK_BRIEF = """
 <span style="padding-left: {{ record.depth }}0px">
-    <a href="{% if record.pk %}{% url 'ipam:prefix' pk=record.pk %}{% else %}{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if site %}&site={{ site.pk }}{% endif %}{% endif %}">{{ record.prefix }}</a>
+    <a href="{% if record.pk %}{% url 'ipam:prefix' pk=record.pk %}{% else %}{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if parent.vrf %}&vrf={{ parent.vrf.pk }}{% endif %}{% if parent.site %}&site={{ parent.site.pk }}{% endif %}{% endif %}">{{ record.prefix }}</a>
 </span>
 """
 

+ 1 - 0
netbox/ipam/views.py

@@ -447,6 +447,7 @@ def prefix_add(request):
     else:
         form = PrefixForm(initial={
             'site': request.GET.get('site'),
+            'vrf': request.GET.get('vrf'),
             'prefix': request.GET.get('prefix'),
         })
 

+ 7 - 1
netbox/templates/ipam/prefix.html

@@ -86,7 +86,13 @@
 </div>
 <div class="row">
 	<div class="col-md-12">
-        {% include 'ipam/inc/prefix_table.html' with table=child_prefix_table table_template='panel_table.html' heading='Child Prefixes' site=prefix.site %}
+        {% if child_prefix_table.rows %}
+            {% include 'ipam/inc/prefix_table.html' with table=child_prefix_table table_template='panel_table.html' heading='Child Prefixes' parent=prefix %}
+        {% elif prefix.new_subnet %}
+            <a href="{% url 'ipam:prefix_add' %}?prefix={{ prefix.new_subnet }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}{% if prefix.site %}&site={{ prefix.site.pk }}{% endif %}" class="btn btn-success">
+                <i class="glyphicon glyphicon-plus" aria-hidden="true"></i> Add Child Prefix
+            </a>
+        {% endif %}
     </div>
 </div>
 {% endblock %}