Skip to content

Commit

Permalink
Add customer filter, minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
itdependsnetworks committed Jul 24, 2023
1 parent a839773 commit 117afb2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
23 changes: 23 additions & 0 deletions nautobot_golden_config/filter_extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Custom filter to extend base API for filterform use case."""
import django_filters

from nautobot.apps.filters import FilterExtension


def config_plan_null_search(queryset, name, value):
return queryset.filter(config_plan__isnull=False).distinct()


class JobResultFilterExtension(FilterExtension):
"""Filter provided to be used in select2 query for only jobs that were used by ConfigPlan."""

model = "extras.jobresult"

filterset_fields = {
"nautobot_golden_config_config_plan_null": django_filters.BooleanFilter(
label="Is FK to ConfigPlan Model", method=config_plan_null_search
)
}


filter_extensions = [JobResultFilterExtension]
2 changes: 1 addition & 1 deletion nautobot_golden_config/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class ConfigPlanFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
label="Feature Name",
)
job_result_id = django_filters.ModelMultipleChoiceFilter(
queryset=JobResult.objects.all(),
queryset=JobResult.objects.filter(config_plan__isnull=False).distinct(),
label="JobResult ID",
)
change_control_id = django_filters.CharFilter(
Expand Down
5 changes: 3 additions & 2 deletions nautobot_golden_config/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ class ConfigPlanForm(NautobotModelForm):
)

def __init__(self, *args, **kwargs):
"""Method to provide provide data be used in django template -> JS to toggle form fields."""
"""Method to get data from Python -> Django template -> JS in support of toggle form fields."""
super().__init__(*args, **kwargs)
hide_form_data = [
{
Expand Down Expand Up @@ -598,7 +598,8 @@ class ConfigPlanFilterForm(NautobotFilterForm):
)
change_control_id = forms.CharField(required=False, label="Change Control ID")
job_result_id = utilities_forms.DynamicModelMultipleChoiceField(
queryset=JobResult.objects.all(),
queryset=JobResult.objects.filter(config_plan__isnull=False).distinct(),
query_params={"nautobot_golden_config_config_plan_null": True},
label="Job Result",
required=False,
display_field="id",
Expand Down
8 changes: 4 additions & 4 deletions nautobot_golden_config/static/run_job.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

/**
* Used in conjuction with `job_result_modal` to pop up the modal, start the job, provide progress spinner,
* and provide job status, job results link, redirect link, and error message.
* provide job status, job results link, redirect link, and error message.
*
* @requires nautobot_csrf_token - The CSRF token obtained from Nautobot.
* @param {string} jobClass - The jobs `class_path` as defined on the job detail page.
* @param {Object} data - The object containing payload data to replace the job.
* @param {string} jobClass - The jobs `class_path` as defined on the job detail page.
* @param {Object} data - The object containing payload data to send to the job.
* @param {string} redirectUrlTemplate - The redirect url to provide, you have access to jobData with the syntax like `{jobData.someKey}`, leave `undefined` if none is required.
*/
function startJob(jobClass, data, redirectUrlTemplate) {
Expand Down Expand Up @@ -104,7 +104,7 @@ function pollJobStatus(jobId) {
/**
* Converts a list of form data objects to a dictionary.
*
* @param {FormData} formData - The list of form data objects to be converted.
* @param {FormData} formData - The form data object to be converted.
* @param {string[]} listKeys - The list of keys for which values should be collected as lists.
* @returns {Object} - The dictionary representation of the form data.
*/
Expand Down

0 comments on commit 117afb2

Please sign in to comment.