From cda38671e158831a04f097cbe647170c903483af Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 5 Sep 2023 12:37:07 -0500 Subject: [PATCH] Adds message if Job is not enabled --- nautobot_golden_config/views.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nautobot_golden_config/views.py b/nautobot_golden_config/views.py index 758d04eb..5a2873c1 100644 --- a/nautobot_golden_config/views.py +++ b/nautobot_golden_config/views.py @@ -16,6 +16,8 @@ from django.forms import ModelMultipleChoiceField, MultipleHiddenInput from django.shortcuts import redirect, render from django.views.generic import View +from django.urls import reverse +from django.utils.html import format_html from django_pivot.pivot import pivot from nautobot.core.views import generic from nautobot.core.views.viewsets import NautobotUIViewSet @@ -23,7 +25,7 @@ from nautobot.dcim.forms import DeviceFilterForm from nautobot.dcim.models import Device from nautobot.extras.jobs import run_job -from nautobot.extras.models import JobResult +from nautobot.extras.models import Job, JobResult from nautobot.extras.utils import get_job_content_type from nautobot.utilities.error_handlers import handle_protectederror from nautobot.utilities.forms import ConfirmationForm @@ -829,6 +831,19 @@ def get_form_class(self, **kwargs): return forms.ConfigPlanUpdateForm return super().get_form_class(**kwargs) + def create(self, request, *args, **kwargs): + """Helper function to warn if the Job is not enabled to run.""" + job = Job.objects.get(name="Generate Config Plans") + if not job.enabled: + messages.warning( + request, + format_html( + "The Job to generate Config Plans is not yet enabled. " + f"Click here to edit the Job." + ), + ) + return super().create(request, *args, **kwargs) + class ConfigPlanBulkDeploy(ObjectPermissionRequiredMixin, View): """View to run the Config Plan Deploy Job."""