ソースを参照

Clean up and document object, object list templates

jeremystretch 4 年 前
コミット
624eda297f

+ 2 - 5
netbox/dcim/views.py

@@ -803,7 +803,6 @@ class DeviceTypeView(generic.ObjectView):
 
 
         return {
         return {
             'instance_count': instance_count,
             'instance_count': instance_count,
-            'active_tab': 'devicetype',
         }
         }
 
 
 
 
@@ -953,11 +952,10 @@ class ModuleTypeView(generic.ObjectView):
     queryset = ModuleType.objects.prefetch_related('manufacturer')
     queryset = ModuleType.objects.prefetch_related('manufacturer')
 
 
     def get_extra_context(self, request, instance):
     def get_extra_context(self, request, instance):
-        # instance_count = Module.objects.restrict(request.user).filter(device_type=instance).count()
+        instance_count = Module.objects.restrict(request.user).filter(module_type=instance).count()
 
 
         return {
         return {
-            # 'instance_count': instance_count,
-            'active_tab': 'moduletype',
+            'instance_count': instance_count,
         }
         }
 
 
 
 
@@ -1570,7 +1568,6 @@ class DeviceView(generic.ObjectView):
         return {
         return {
             'services': services,
             'services': services,
             'vc_members': vc_members,
             'vc_members': vc_members,
-            'active_tab': 'device',
         }
         }
 
 
 
 

+ 2 - 2
netbox/netbox/views/generic/bulk_views.py

@@ -7,7 +7,7 @@ from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import FieldDoesNotExist, ValidationError
 from django.core.exceptions import FieldDoesNotExist, ValidationError
 from django.db import transaction, IntegrityError
 from django.db import transaction, IntegrityError
 from django.db.models import ManyToManyField, ProtectedError
 from django.db.models import ManyToManyField, ProtectedError
-from django.forms import Form, ModelMultipleChoiceField, MultipleHiddenInput, Textarea
+from django.forms import Form, ModelMultipleChoiceField, MultipleHiddenInput
 from django.http import HttpResponse
 from django.http import HttpResponse
 from django.shortcuts import get_object_or_404, redirect, render
 from django.shortcuts import get_object_or_404, redirect, render
 from django_tables2.export import TableExport
 from django_tables2.export import TableExport
@@ -178,7 +178,7 @@ class ObjectListView(BaseMultiObjectView):
             })
             })
 
 
         context = {
         context = {
-            'content_type': content_type,
+            'model': model,
             'table': table,
             'table': table,
             'permissions': permissions,
             'permissions': permissions,
             'action_buttons': self.action_buttons,
             'action_buttons': self.action_buttons,

+ 1 - 7
netbox/templates/dcim/device/base.html

@@ -95,13 +95,7 @@
     {% endif %}
     {% endif %}
 {% endblock %}
 {% endblock %}
 
 
-{% block tab_items %}
-    <li role="presentation" class="nav-item">
-        <a href="{% url 'dcim:device' pk=object.pk %}" class="nav-link{% if active_tab == 'device' %} active{% endif %}">
-            Device
-        </a>
-    </li>
-
+{% block extra_tabs %}
     {% with tab_name='device-bays' devicebay_count=object.devicebays.count %}
     {% with tab_name='device-bays' devicebay_count=object.devicebays.count %}
         {% if active_tab == tab_name or devicebay_count %}
         {% if active_tab == tab_name or devicebay_count %}
             <li role="presentation" class="nav-item">
             <li role="presentation" class="nav-item">

+ 1 - 7
netbox/templates/dcim/devicetype/base.html

@@ -52,13 +52,7 @@
   {% endif %}
   {% endif %}
 {% endblock %}
 {% endblock %}
 
 
-{% block tab_items %}
-    <li role="presentation" class="nav-item">
-        <a href="{% url 'dcim:devicetype' pk=object.pk %}" class="nav-link{% if active_tab == 'devicetype' %} active{% endif %}">
-            Device Type
-        </a>
-    </li>
-
+{% block extra_tabs %}
     {% with tab_name='device-bay-templates' devicebay_count=object.devicebaytemplates.count %}
     {% with tab_name='device-bay-templates' devicebay_count=object.devicebaytemplates.count %}
         {% if active_tab == tab_name or devicebay_count %}
         {% if active_tab == tab_name or devicebay_count %}
             <li role="presentation" class="nav-item">
             <li role="presentation" class="nav-item">

+ 0 - 2
netbox/templates/dcim/moduletype.html

@@ -22,12 +22,10 @@
               <td>Part Number</td>
               <td>Part Number</td>
               <td>{{ object.part_number|placeholder }}</td>
               <td>{{ object.part_number|placeholder }}</td>
             </tr>
             </tr>
-            {% comment %}
             <tr>
             <tr>
               <td>Instances</td>
               <td>Instances</td>
               <td><a href="{% url 'dcim:module_list' %}?module_type_id={{ object.pk }}">{{ instance_count }}</a></td>
               <td><a href="{% url 'dcim:module_list' %}?module_type_id={{ object.pk }}">{{ instance_count }}</a></td>
             </tr>
             </tr>
-            {% endcomment %}
           </table>
           </table>
         </div>
         </div>
       </div>
       </div>

+ 1 - 7
netbox/templates/dcim/moduletype/base.html

@@ -43,13 +43,7 @@
   {% endif %}
   {% endif %}
 {% endblock %}
 {% endblock %}
 
 
-{% block tab_items %}
-    <li role="presentation" class="nav-item">
-        <a href="{% url 'dcim:moduletype' pk=object.pk %}" class="nav-link{% if active_tab == 'moduletype' %} active{% endif %}">
-            Module Type
-        </a>
-    </li>
-
+{% block extra_tabs %}
     {% with interface_count=object.interfacetemplates.count %}
     {% with interface_count=object.interfacetemplates.count %}
         {% if interface_count %}
         {% if interface_count %}
             <li role="presentation" class="nav-item">
             <li role="presentation" class="nav-item">

+ 23 - 5
netbox/templates/generic/object.html

@@ -5,6 +5,18 @@
 {% load perms %}
 {% load perms %}
 {% load plugins %}
 {% load plugins %}
 
 
+{% comment %}
+Blocks:
+  breadcrumbs: Breadcrumb list items (HTML <li> elements)
+  object_identifier: Unique identifier for the object
+  extra_controls: Additional action buttons to display
+  extra_tabs: Additional tabs to include
+  content: Page content
+
+Context:
+  object: The object instance being viewed
+{% endcomment %}
+
 {% block header %}
 {% block header %}
   <div class="d-flex justify-content-between align-items-center">
   <div class="d-flex justify-content-between align-items-center">
     {# Breadcrumbs #}
     {# Breadcrumbs #}
@@ -66,11 +78,15 @@
 
 
 {% block tabs %}
 {% block tabs %}
   <ul class="nav nav-tabs px-3">
   <ul class="nav nav-tabs px-3">
-    {% block tab_items %}
-      <li class="nav-item" role="presentation">
-        <a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
-      </li>
-    {% endblock tab_items %}
+    {# Primary tab #}
+    <li class="nav-item" role="presentation">
+      <a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
+    </li>
+
+    {# Include any additional tabs #}
+    {% block extra_tabs %}{% endblock %}
+
+    {# Object journal #}
     {% if perms.extras.view_journalentry %}
     {% if perms.extras.view_journalentry %}
       {% with journal_viewname=object|viewname:'journal' %}
       {% with journal_viewname=object|viewname:'journal' %}
         {% url journal_viewname pk=object.pk as journal_url %}
         {% url journal_viewname pk=object.pk as journal_url %}
@@ -83,6 +99,8 @@
         {% endif %}
         {% endif %}
       {% endwith %}
       {% endwith %}
     {% endif %}
     {% endif %}
+
+    {# Object changelog #}
     {% if perms.extras.view_objectchange %}
     {% if perms.extras.view_objectchange %}
       {% with changelog_viewname=object|viewname:'changelog' %}
       {% with changelog_viewname=object|viewname:'changelog' %}
         {% url changelog_viewname pk=object.pk as changelog_url %}
         {% url changelog_viewname pk=object.pk as changelog_url %}

+ 34 - 19
netbox/templates/generic/object_list.html

@@ -4,20 +4,37 @@
 {% load render_table from django_tables2 %}
 {% load render_table from django_tables2 %}
 {% load static %}
 {% load static %}
 
 
-{% block title %}{{ content_type.model_class|meta:"verbose_name_plural"|bettertitle }}{% endblock %}
+{% comment %}
+Blocks:
+  extra_controls: Additional action buttons
+  bulk_buttons: Additional bulk action buttons to display beneath the objects
+    list
+
+Context:
+  model: The model class being listed
+  table: The table class used for rendering the list of objects
+  permissions: A mapping of add/change/delete permissions to boolean indicating
+    whether the current user possesses each of them. Controls the display of
+    add/edit/delete buttons.
+  action_buttons: A list of buttons to display. Options are add, import, export.
+  filter_form: The bound filterset form for filtering the objects list (optional)
+  return_url: Return URL to use for bulk actions (optional)
+{% endcomment %}
+
+{% block title %}{{ model|meta:"verbose_name_plural"|bettertitle }}{% endblock %}
 
 
 {% block controls %}
 {% block controls %}
   <div class="controls">
   <div class="controls">
     <div class="control-group">
     <div class="control-group">
       {% block extra_controls %}{% endblock %}
       {% block extra_controls %}{% endblock %}
       {% if permissions.add and 'add' in action_buttons %}
       {% if permissions.add and 'add' in action_buttons %}
-          {% add_button content_type.model_class|validated_viewname:"add" %}
+          {% add_button model|validated_viewname:"add" %}
       {% endif %}
       {% endif %}
       {% if permissions.add and 'import' in action_buttons %}
       {% if permissions.add and 'import' in action_buttons %}
-          {% import_button content_type.model_class|validated_viewname:"import" %}
+          {% import_button model|validated_viewname:"import" %}
       {% endif %}
       {% endif %}
       {% if 'export' in action_buttons %}
       {% if 'export' in action_buttons %}
-          {% export_button content_type %}
+          {% export_button model|content_type %}
       {% endif %}
       {% endif %}
     </div>
     </div>
   </div>
   </div>
@@ -25,22 +42,20 @@
 
 
 {% block tabs %}
 {% block tabs %}
   <ul class="nav nav-tabs px-3">
   <ul class="nav nav-tabs px-3">
-    {% block tab_items %}
+    <li class="nav-item" role="presentation">
+      <button class="nav-link active" id="object-list-tab" data-bs-toggle="tab" data-bs-target="#object-list" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
+        Records
+        {% badge table.page.paginator.count %}
+      </button>
+    </li>
+    {% if filter_form %}
       <li class="nav-item" role="presentation">
       <li class="nav-item" role="presentation">
-        <button class="nav-link active" id="object-list-tab" data-bs-toggle="tab" data-bs-target="#object-list" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
-          Records
-          {% badge table.page.paginator.count %}
+        <button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="object-list" aria-selected="false">
+          Filters
+          {% if filter_form %}{% badge filter_form.changed_data|length bg_class="primary" %}{% endif %}
         </button>
         </button>
       </li>
       </li>
-      {% if filter_form %}
-        <li class="nav-item" role="presentation">
-          <button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="object-list" aria-selected="false">
-            Filters
-            {% if filter_form %}{% badge filter_form.changed_data|length bg_class="primary" %}{% endif %}
-          </button>
-        </li>
-      {% endif %}
-    {% endblock tab_items %}
+    {% endif %}
   </ul>
   </ul>
 {% endblock tabs %}
 {% endblock tabs %}
 
 
@@ -57,7 +72,7 @@
 
 
       {# "Select all" form #}
       {# "Select all" form #}
       {% if table.paginator.num_pages > 1 %}
       {% if table.paginator.num_pages > 1 %}
-        {% with bulk_edit_url=content_type.model_class|validated_viewname:"bulk_edit" bulk_delete_url=content_type.model_class|validated_viewname:"bulk_delete" %}
+        {% with bulk_edit_url=model|validated_viewname:"bulk_edit" bulk_delete_url=model|validated_viewname:"bulk_delete" %}
           <div id="select-all-box" class="d-none card noprint">
           <div id="select-all-box" class="d-none card noprint">
             <form method="post" class="form col-md-12">
             <form method="post" class="form col-md-12">
               {% csrf_token %}
               {% csrf_token %}
@@ -102,7 +117,7 @@
 
 
         {# Form buttons #}
         {# Form buttons #}
         {% if permissions.change or permissions.delete %}
         {% if permissions.change or permissions.delete %}
-          {% with bulk_edit_url=content_type.model_class|validated_viewname:"bulk_edit" bulk_delete_url=content_type.model_class|validated_viewname:"bulk_delete" %}
+          {% with bulk_edit_url=model|validated_viewname:"bulk_edit" bulk_delete_url=model|validated_viewname:"bulk_delete" %}
             <div class="noprint bulk-buttons">
             <div class="noprint bulk-buttons">
               <div class="bulk-button-group">
               <div class="bulk-button-group">
                 {% block bulk_buttons %}{% endblock %}
                 {% block bulk_buttons %}{% endblock %}

+ 1 - 6
netbox/templates/ipam/aggregate/base.html

@@ -7,12 +7,7 @@
   <li class="breadcrumb-item"><a href="{% url 'ipam:aggregate_list' %}?rir_id={{ object.rir.pk }}">{{ object.rir }}</a></li>
   <li class="breadcrumb-item"><a href="{% url 'ipam:aggregate_list' %}?rir_id={{ object.rir.pk }}">{{ object.rir }}</a></li>
 {% endblock %}
 {% endblock %}
 
 
-{% block tab_items %}
-  <li role="presentation" class="nav-item">
-    <a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">
-      Aggregate
-    </a>
-  </li>
+{% block extra_tabs %}
   {% if perms.ipam.view_prefix %}
   {% if perms.ipam.view_prefix %}
     <li role="presentation" class="nav-item">
     <li role="presentation" class="nav-item">
       <a class="nav-link{% if active_tab == 'prefixes' %} active{% endif %}" href="{% url 'ipam:aggregate_prefixes' pk=object.pk %}">
       <a class="nav-link{% if active_tab == 'prefixes' %} active{% endif %}" href="{% url 'ipam:aggregate_prefixes' pk=object.pk %}">

+ 1 - 6
netbox/templates/ipam/iprange/base.html

@@ -9,12 +9,7 @@
   {% endif %}
   {% endif %}
 {% endblock %}
 {% endblock %}
 
 
-{% block tab_items %}
-  <li role="presentation" class="nav-item">
-    <a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">
-      IP Range
-    </a>
-  </li>
+{% block extra_tabs %}
   {% if perms.ipam.view_ipaddress %}
   {% if perms.ipam.view_ipaddress %}
     <li role="presentation" class="nav-item">
     <li role="presentation" class="nav-item">
       <a class="nav-link{% if active_tab == 'ip-addresses' %} active{% endif %}" href="{% url 'ipam:iprange_ipaddresses' pk=object.pk %}">
       <a class="nav-link{% if active_tab == 'ip-addresses' %} active{% endif %}" href="{% url 'ipam:iprange_ipaddresses' pk=object.pk %}">

+ 1 - 6
netbox/templates/ipam/prefix/base.html

@@ -9,12 +9,7 @@
   {% endif %}
   {% endif %}
 {% endblock %}
 {% endblock %}
 
 
-{% block tab_items %}
-  <li role="presentation" class="nav-item">
-    <a class="nav-link{% if not active_tab %} active{% endif %}" href="{% url 'ipam:prefix' pk=object.pk %}">
-      Prefix
-    </a>
-  </li>
+{% block extra_tabs %}
   <li role="presentation" class="nav-item">
   <li role="presentation" class="nav-item">
     <a class="nav-link{% if active_tab == 'prefixes' %} active{% endif %}" href="{% url 'ipam:prefix_prefixes' pk=object.pk %}">
     <a class="nav-link{% if active_tab == 'prefixes' %} active{% endif %}" href="{% url 'ipam:prefix_prefixes' pk=object.pk %}">
       Child Prefixes {% badge object.get_child_prefixes.count %}
       Child Prefixes {% badge object.get_child_prefixes.count %}