From a76540cf6abd16434ee635c03aba11f8d90beb5f Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Tue, 26 Nov 2024 14:23:29 -0600 Subject: [PATCH 1/2] Add total_objs_to_delete and remove the table when deleting all objects. These changes bring this into alignment with Nautobot 2.3.11. This also removes the self.store_table, per the TODO it should not be necessary, I was able to confirm through testing in both the unittests and manually in the UI that removing self.store_table did not make any impact to the functionality. --- changes/831.fixed | 1 + nautobot_golden_config/views.py | 11 ++++------- pyproject.toml | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 changes/831.fixed diff --git a/changes/831.fixed b/changes/831.fixed new file mode 100644 index 00000000..ca92de1c --- /dev/null +++ b/changes/831.fixed @@ -0,0 +1 @@ +Resolved issue with tests failing in Nautobot 2.3.11. diff --git a/nautobot_golden_config/views.py b/nautobot_golden_config/views.py index 024c2044..14693c39 100644 --- a/nautobot_golden_config/views.py +++ b/nautobot_golden_config/views.py @@ -252,19 +252,15 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pk_list = None self.report_context = None - self.store_table = None def get_extra_context(self, request, instance=None, **kwargs): """A ConfigCompliance helper function to warn if the Job is not enabled to run.""" context = super().get_extra_context(request, instance) - if self.action == "bulk_destroy": - context["table"] = self.store_table if self.action == "overview": context = {**context, **self.report_context} context["compliance"] = constant.ENABLE_COMPLIANCE context["backup"] = constant.ENABLE_BACKUP context["intended"] = constant.ENABLE_INTENDED - # TODO: See reference to store_table below for action item add_message([["ComplianceJob", constant.ENABLE_COMPLIANCE]], request) return context @@ -315,10 +311,11 @@ def perform_bulk_destroy(self, request, **kwargs): f"No {self.queryset.model._meta.verbose_name_plural} were selected for deletion.", ) return redirect(self.get_return_url(request)) - # TODO: This does not seem right, it is not clear why data does not just get added to context - self.store_table = table - data.update({"table": table}) + if not request.POST.get("_all"): + data.update({"table": table, "total_objs_to_delete": len(table.rows)}) + else: + data.update({"table": None, "delete_all": True, "total_objs_to_delete": len(table.rows)}) return Response(data) @action(detail=True, methods=["get"]) diff --git a/pyproject.toml b/pyproject.toml index 4384122c..39602ff8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nautobot-golden-config" -version = "2.2.0" +version = "2.2.1a0" description = "An app for configuration on nautobot" authors = ["Network to Code, LLC "] license = "Apache-2.0" From 2cde99c08553e02f9b8e4e2e6e701d33ffbdd038 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Tue, 26 Nov 2024 16:02:17 -0600 Subject: [PATCH 2/2] Add back in store_table --- nautobot_golden_config/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nautobot_golden_config/views.py b/nautobot_golden_config/views.py index 14693c39..e094ad66 100644 --- a/nautobot_golden_config/views.py +++ b/nautobot_golden_config/views.py @@ -252,12 +252,17 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pk_list = None self.report_context = None + self.store_table = None # Used to store the table for bulk delete. No longer required in Nautobot 2.3.11 def get_extra_context(self, request, instance=None, **kwargs): """A ConfigCompliance helper function to warn if the Job is not enabled to run.""" context = super().get_extra_context(request, instance) if self.action == "overview": context = {**context, **self.report_context} + # TODO Remove when dropping support for Nautobot < 2.3.11 + if self.action == "bulk_destroy": + context["table"] = self.store_table + context["compliance"] = constant.ENABLE_COMPLIANCE context["backup"] = constant.ENABLE_BACKUP context["intended"] = constant.ENABLE_INTENDED @@ -312,6 +317,9 @@ def perform_bulk_destroy(self, request, **kwargs): ) return redirect(self.get_return_url(request)) + # TODO Remove when dropping support for Nautobot < 2.3.11 + self.store_table = table + if not request.POST.get("_all"): data.update({"table": table, "total_objs_to_delete": len(table.rows)}) else: