diff --git a/netbox_config_diff/migrations/0008_alter_configcompliance_device.py b/netbox_config_diff/migrations/0008_alter_configcompliance_device.py new file mode 100644 index 0000000..1972edc --- /dev/null +++ b/netbox_config_diff/migrations/0008_alter_configcompliance_device.py @@ -0,0 +1,21 @@ +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("dcim", "0181_rename_device_role_device_role"), + ("netbox_config_diff", "0007_configurationrequest"), + ] + + operations = [ + migrations.AlterField( + model_name="configcompliance", + name="device", + field=models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + related_name="config_compliance", + to="dcim.device", + ), + ), + ] diff --git a/netbox_config_diff/models/models.py b/netbox_config_diff/models/models.py index 4bb0dfd..10b0f73 100644 --- a/netbox_config_diff/models/models.py +++ b/netbox_config_diff/models/models.py @@ -24,7 +24,7 @@ class ConfigCompliance(AbsoluteURLMixin, ChangeLoggingMixin, models.Model): device = models.OneToOneField( to="dcim.Device", on_delete=models.CASCADE, - related_name="config_compliamce", + related_name="config_compliance", ) status = models.CharField( max_length=50, diff --git a/netbox_config_diff/templates/netbox_config_diff/configcompliance.html b/netbox_config_diff/templates/netbox_config_diff/configcompliance.html index 50bc5d6..2505fc7 100644 --- a/netbox_config_diff/templates/netbox_config_diff/configcompliance.html +++ b/netbox_config_diff/templates/netbox_config_diff/configcompliance.html @@ -1,81 +1,13 @@ -{% extends "netbox_config_diff/configcompliance/base.html" %} -{% load static %} +{% extends "generic/object.html" %} +{% load buttons %} +{% load perms %} -{% block content %} -
-
-
-
{{ object|meta:"verbose_name"|bettertitle }}
-
- - - - - - - - - -
Device{{ object.device|linkify }}
Status{% badge object.get_status_display bg_color=object.get_status_color %}
-
-
+{% block controls %} +
+
+ {% if request.user|can_delete:object %} + {% delete_button object %} + {% endif %}
- {% if object.error %} -
-
-
Error
-
-
{{ object.error }}
-
-
-
- {% endif %}
- {% if object.diff %} -
-
-
-
Diff
-
-
-
-
- {% endif %} -{% endblock content %} - -{% block javascript %} - - -{% endblock javascript %} +{% endblock controls %} diff --git a/netbox_config_diff/templates/netbox_config_diff/configcompliance/base.html b/netbox_config_diff/templates/netbox_config_diff/configcompliance/base.html deleted file mode 100644 index 8fdcc6f..0000000 --- a/netbox_config_diff/templates/netbox_config_diff/configcompliance/base.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "generic/object.html" %} -{% load buttons %} -{% load perms %} - -{% block controls %} -
-
- {% if request.user|can_delete:object %} - {% delete_button object %} - {% endif %} -
-
-{% endblock controls %} \ No newline at end of file diff --git a/netbox_config_diff/templates/netbox_config_diff/configcompliance/config.html b/netbox_config_diff/templates/netbox_config_diff/configcompliance/config.html index 8bc2722..ae2c864 100644 --- a/netbox_config_diff/templates/netbox_config_diff/configcompliance/config.html +++ b/netbox_config_diff/templates/netbox_config_diff/configcompliance/config.html @@ -1,4 +1,4 @@ -{% extends "netbox_config_diff/configcompliance/base.html" %} +{% extends "netbox_config_diff/configcompliance.html" %} {% block title %}{{ object }} - {{ header }}{% endblock %} diff --git a/netbox_config_diff/templates/netbox_config_diff/configcompliance/data.html b/netbox_config_diff/templates/netbox_config_diff/configcompliance/data.html new file mode 100644 index 0000000..5c20e42 --- /dev/null +++ b/netbox_config_diff/templates/netbox_config_diff/configcompliance/data.html @@ -0,0 +1,81 @@ +{% extends base_template %} +{% load static %} + +{% block content %} +
+
+
+
{{ instance|meta:"verbose_name"|bettertitle }}
+
+ + + + + + + + + +
Device{{ instance.device|linkify }}
Status{% badge instance.get_status_display bg_color=instance.get_status_color %}
+
+
+
+ {% if instance.error %} +
+
+
Error
+
+
{{ instance.error }}
+
+
+
+ {% endif %} +
+ {% if instance.diff %} +
+
+
+
Diff
+
+
+
+
+ {% endif %} +{% endblock content %} + +{% block javascript %} + + +{% endblock javascript %} diff --git a/netbox_config_diff/templates/netbox_config_diff/configcompliance/missing_extra.html b/netbox_config_diff/templates/netbox_config_diff/configcompliance/missing_extra.html index c7692fd..de94dd9 100644 --- a/netbox_config_diff/templates/netbox_config_diff/configcompliance/missing_extra.html +++ b/netbox_config_diff/templates/netbox_config_diff/configcompliance/missing_extra.html @@ -1,4 +1,4 @@ -{% extends "netbox_config_diff/configcompliance/base.html" %} +{% extends "netbox_config_diff/configcompliance.html" %} {% block title %}{{ object }} - Missing/Extra{% endblock %} diff --git a/netbox_config_diff/views/compliance.py b/netbox_config_diff/views/compliance.py index fbe5c95..2a4d49c 100644 --- a/netbox_config_diff/views/compliance.py +++ b/netbox_config_diff/views/compliance.py @@ -1,5 +1,6 @@ +from dcim.models import Device from django.http import HttpResponse -from django.shortcuts import render +from django.shortcuts import redirect, render from django.utils.translation import gettext as _ from netbox.views import generic from utilities.views import ViewTab, register_model_view @@ -51,6 +52,14 @@ def get_extra_context(self, request, instance): @register_model_view(ConfigCompliance) class ConfigComplianceView(generic.ObjectView): queryset = ConfigCompliance.objects.all() + base_template = "netbox_config_diff/configcompliance.html" + template_name = "netbox_config_diff/configcompliance/data.html" + + def get_extra_context(self, request, instance): + return { + "instance": instance, + "base_template": self.base_template, + } @register_model_view(ConfigCompliance, "rendered-config") @@ -113,6 +122,37 @@ def get(self, request, **kwargs): ) +@register_model_view(Device, "config_compliance", "config-compliance") +class ConfigComplianceDeviceView(generic.ObjectView): + queryset = Device.objects.all() + base_template = "dcim/device/base.html" + template_name = "netbox_config_diff/configcompliance/data.html" + tab = ViewTab( + label=_("Config Compliance"), + weight=2110, + badge=lambda obj: 1 if hasattr(obj, "config_compliance") else 0, + hide_if_empty=True, + ) + + def get(self, request, **kwargs): + instance = self.get_object(**kwargs) + + if not hasattr(instance, "config_compliance"): + return redirect("dcim:device", pk=instance.pk) + + return render( + request, + self.get_template_name(), + { + "object": instance, + "instance": instance.config_compliance, + "tab": self.tab, + "base_template": self.base_template, + **self.get_extra_context(request, instance), + }, + ) + + class ConfigComplianceListView(generic.ObjectListView): queryset = ConfigCompliance.objects.prefetch_related("device") filterset = ConfigComplianceFilterSet