Skip to content

Commit

Permalink
Adds message if Job is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
joewesch committed Sep 5, 2023
1 parent 15f35d6 commit cda3867
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion nautobot_golden_config/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
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
from nautobot.dcim.filters import DeviceFilterSet
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
Expand Down Expand Up @@ -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"<a href='{reverse('extras:job_edit', kwargs={'slug': job.slug})}'>Click here to edit the Job</a>."
),
)
return super().create(request, *args, **kwargs)


class ConfigPlanBulkDeploy(ObjectPermissionRequiredMixin, View):
"""View to run the Config Plan Deploy Job."""
Expand Down

0 comments on commit cda3867

Please sign in to comment.