Просмотр исходного кода

Merge pull request #6779 from netbox-community/jstretch-ui-work

Pending UI work for v3.0 beta
Jeremy Stretch 4 лет назад
Родитель
Сommit
108305a3e3

+ 16 - 0
netbox/extras/views.py

@@ -276,6 +276,21 @@ class ConfigContextView(generic.ObjectView):
     queryset = ConfigContext.objects.all()
 
     def get_extra_context(self, request, instance):
+        # Gather assigned objects for parsing in the template
+        assigned_objects = (
+            ('Regions', instance.regions.all),
+            ('Site Groups', instance.site_groups.all),
+            ('Sites', instance.sites.all),
+            ('Device Types', instance.device_types.all),
+            ('Roles', instance.roles.all),
+            ('Platforms', instance.platforms.all),
+            ('Cluster Groups', instance.cluster_groups.all),
+            ('Clusters', instance.clusters.all),
+            ('Tenant Groups', instance.tenant_groups.all),
+            ('Tenants', instance.tenants.all),
+            ('Tags', instance.tags.all),
+        )
+
         # Determine user's preferred output format
         if request.GET.get('format') in ['json', 'yaml']:
             format = request.GET.get('format')
@@ -287,6 +302,7 @@ class ConfigContextView(generic.ObjectView):
             format = 'json'
 
         return {
+            'assigned_objects': assigned_objects,
             'format': format,
         }
 

+ 1 - 12
netbox/templates/circuits/circuit.html

@@ -66,18 +66,7 @@
         </div>
         {% include 'inc/custom_fields_panel.html' %}
         {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='circuits:circuit_list' %}
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-                {% if object.comments %}
-                    {{ object.comments|render_markdown }}
-                {% else %}
-                    <span class="text-muted">None</span>
-                {% endif %}
-            </div>
-        </div>
+        {% include 'inc/comments_panel.html' %}
         {% plugin_left_page object %}
 	</div>
 	<div class="col col-md-6">

+ 1 - 12
netbox/templates/circuits/provider.html

@@ -52,18 +52,7 @@
     <div class="col col-md-6">
         {% include 'inc/custom_fields_panel.html' %}
         {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='circuits:provider_list' %}
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-                {% if object.comments %}
-                    {{ object.comments|render_markdown }}
-                {% else %}
-                    <span class="text-muted">None</span>
-                {% endif %}
-            </div>
-        </div>
+        {% include 'inc/comments_panel.html' %}
         {% plugin_right_page object %}
     </div>
     <div class="col col-md-12">

+ 1 - 12
netbox/templates/circuits/providernetwork.html

@@ -37,20 +37,9 @@
         {% plugin_left_page object %}
     </div>
     <div class="col col-md-6">
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-                {% if object.comments %}
-                    {{ object.comments|render_markdown }}
-                {% else %}
-                    <span class="text-muted">None</span>
-                {% endif %}
-            </div>
-        </div>
         {% include 'inc/custom_fields_panel.html' %}
         {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='circuits:providernetwork_list' %}
+        {% include 'inc/comments_panel.html' %}
         {% plugin_right_page object %}
     </div>
 </div>

+ 1 - 12
netbox/templates/dcim/device.html

@@ -210,18 +210,7 @@
             </div>
             {% include 'inc/custom_fields_panel.html' %}
             {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='dcim:device_list' %}
-            <div class="card">
-                <h5 class="card-header">
-                    Comments
-                </h5>
-                <div class="card-body rendered-markdown">
-                    {% if object.comments %}
-                        {{ object.comments|render_markdown }}
-                    {% else %}
-                        <span class="text-muted">None</span>
-                    {% endif %}
-                </div>
-            </div>
+            {% include 'inc/comments_panel.html' %}
             {% plugin_left_page object %}
         </div>
         <div class="col col-md-6">

+ 1 - 12
netbox/templates/dcim/devicetype.html

@@ -126,18 +126,7 @@
         <div class="col col-md-6">
             {% include 'inc/custom_fields_panel.html' %}
             {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='dcim:devicetype_list' %}
-            <div class="card">
-                <h5 class="card-header">
-                    Comments
-                </h5>
-                <div class="card-body rendered-markdown">
-                    {% if object.comments %}
-                        {{ object.comments|render_markdown }}
-                    {% else %}
-                        <span class="text-muted">None</span>
-                    {% endif %}
-                </div>
-            </div>
+            {% include 'inc/comments_panel.html' %}
             {% plugin_right_page object %}
         </div>
     </div>

+ 1 - 12
netbox/templates/dcim/powerfeed.html

@@ -182,18 +182,7 @@
             </div>
             {% endif %}
         </div>
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-                {% if object.comments %}
-                    {{ object.comments|render_markdown }}
-                {% else %}
-                    <span class="text-muted">None</span>
-                {% endif %}
-            </div>
-        </div>
+        {% include 'inc/comments_panel.html' %}
         {% plugin_right_page object %}
     </div>
 </div>

+ 1 - 12
netbox/templates/dcim/rack.html

@@ -168,18 +168,7 @@
         </div>
         {% include 'inc/custom_fields_panel.html' %}
         {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='dcim:rack_list' %}
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-            {% if object.comments %}
-                {{ object.comments|render_markdown }}
-            {% else %}
-                <span class="text-muted">None</span>
-            {% endif %}
-            </div>
-        </div>
+        {% include 'inc/comments_panel.html' %}
         {% if power_feeds %}
             <div class="card">
                 <h5 class="card-header">

+ 1 - 12
netbox/templates/dcim/site.html

@@ -167,18 +167,7 @@
         </div>
         {% include 'inc/custom_fields_panel.html' %}
         {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='dcim:site_list' %}
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-                {% if object.comments %}
-                    {{ object.comments|render_markdown }}
-                {% else %}
-                    <span class="text-muted">None</span>
-                {% endif %}
-            </div>
-        </div>
+        {% include 'inc/comments_panel.html' %}
         {% plugin_left_page object %}
     </div>
     <div class="col col-md-5">

+ 12 - 124
netbox/templates/extras/configcontext.html

@@ -50,132 +50,20 @@
                 </h5>
                 <div class="card-body">
                     <table class="table table-hover attr-table">
+                      {% for title, objects in assigned_objects %}
                         <tr>
-                            <th scope="row">Regions</th>
-                            <td>
-                                {% if object.regions.all %}
-                                    <ul>
-                                        {% for region in object.regions.all %}
-                                            <li><a href="{{ region.get_absolute_url }}">{{ region }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Sites</th>
-                            <td>
-                                {% if object.sites.all %}
-                                    <ul>
-                                        {% for site in object.sites.all %}
-                                            <li><a href="{{ site.get_absolute_url }}">{{ site }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Roles</th>
-                            <td>
-                                {% if object.roles.all %}
-                                    <ul>
-                                        {% for role in object.roles.all %}
-                                            <li><a href="{% url 'dcim:device_list' %}?role={{ role.slug }}">{{ role }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Platforms</th>
-                            <td>
-                                {% if object.platforms.all %}
-                                    <ul>
-                                        {% for platform in object.platforms.all %}
-                                            <li><a href="{{ platform.get_absolute_url }}">{{ platform }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Cluster Groups</th>
-                            <td>
-                                {% if object.cluster_groups.all %}
-                                    <ul>
-                                        {% for cluster_group in object.cluster_groups.all %}
-                                            <li><a href="{{ cluster_group.get_absolute_url }}">{{ cluster_group }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Clusters</th>
-                            <td>
-                                {% if object.clusters.all %}
-                                    <ul>
-                                        {% for cluster in object.clusters.all %}
-                                            <li><a href="{{ cluster.get_absolute_url }}">{{ cluster }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Tenant Groups</th>
-                            <td>
-                                {% if object.tenant_groups.all %}
-                                    <ul>
-                                        {% for tenant_group in object.tenant_groups.all %}
-                                            <li><a href="{{ tenant_group.get_absolute_url }}">{{ tenant_group }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Tenants</th>
-                            <td>
-                                {% if object.tenants.all %}
-                                    <ul>
-                                        {% for tenant in object.tenants.all %}
-                                            <li><a href="{{ tenant.get_absolute_url }}">{{ tenant }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
-                        </tr>
-                        <tr>
-                            <th scope="row">Tags</th>
-                            <td>
-                                {% if object.tags.all %}
-                                    <ul>
-                                        {% for tag in object.tags.all %}
-                                            <li><a href="{{ tag.get_absolute_url }}">{{ tag }}</a></li>
-                                        {% endfor %}
-                                    </ul>
-                                {% else %}
-                                    <span class="text-muted">None</span>
-                                {% endif %}
-                            </td>
+                          <th scope="row">{{ title }}</th>
+                          <td>
+                            <ul class="list-unstyled mb-0">
+                              {% for object in objects %}
+                                <li><a href="{{ object.get_absolute_url }}">{{ object }}</a></li>
+                              {% empty %}
+                                <li class="text-muted">None</li>
+                              {% endfor %}
+                            </ul>
+                          </td>
                         </tr>
+                      {% endfor %}
                     </table>
                 </div>
             </div>

+ 1 - 8
netbox/templates/extras/journalentry.html

@@ -45,14 +45,7 @@
             </div>
         </div>
         <div class="col col-md-8">
-            <div class="card">
-                <h5 class="card-header">
-                    Comments
-                </h5>
-                <div class="card-body">
-                    {{ object.comments|render_markdown }}
-                </div>
-            </div>
+            {% include 'inc/comments_panel.html' %}
         </div>
     </div>
 {% endblock %}

+ 14 - 0
netbox/templates/inc/comments_panel.html

@@ -0,0 +1,14 @@
+{% load helpers %}
+
+<div class="card">
+  <h5 class="card-header">
+    Comments
+  </h5>
+  <div class="card-body rendered-markdown">
+    {% if object.comments %}
+      {{ object.comments|render_markdown }}
+    {% else %}
+      <span class="text-muted">None</span>
+    {% endif %}
+  </div>
+</div>

+ 1 - 12
netbox/templates/tenancy/tenant.html

@@ -37,18 +37,7 @@
         </div>
         {% include 'inc/custom_fields_panel.html' %}
         {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='tenancy:tenant_list' %}
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-                {% if object.comments %}
-                    {{ object.comments|render_markdown }}
-                {% else %}
-                    <span class="text-muted">None</span>
-                {% endif %}
-            </div>
-        </div>
+        {% include 'inc/comments_panel.html' %}
         {% plugin_left_page object %}
 	</div>
 	<div class="col col-md-5">

+ 1 - 12
netbox/templates/virtualization/cluster.html

@@ -56,18 +56,7 @@
             </table>
         </div>
     </div>
-    <div class="card">
-        <h5 class="card-header">
-            Comments
-        </h5>
-        <div class="card-body rendered-markdown">
-            {% if object.comments %}
-                {{ object.comments|render_markdown }}
-            {% else %}
-                <span class="text-muted">None</span>
-            {% endif %}
-        </div>
-    </div>
+    {% include 'inc/comments_panel.html' %}
     {% plugin_left_page object %}
   </div>
   <div class="col col-md-6">

+ 1 - 12
netbox/templates/virtualization/virtualmachine.html

@@ -91,18 +91,7 @@
         </div>
         {% include 'inc/custom_fields_panel.html' %}
         {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='virtualization:virtualmachine_list' %}
-        <div class="card">
-            <h5 class="card-header">
-                Comments
-            </h5>
-            <div class="card-body rendered-markdown">
-                {% if object.comments %}
-                    {{ object.comments|render_markdown }}
-                {% else %}
-                    <span class="text-muted">None</span>
-                {% endif %}
-            </div>
-        </div>
+        {% include 'inc/comments_panel.html' %}
         {% plugin_left_page object %}
     </div>
 	<div class="col col-md-6">