1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Enable scheduling_enabled parameter for reports

This commit is contained in:
jeremystretch
2023-04-17 13:12:14 -04:00
committed by Jeremy Stretch
parent 197c6a1cbf
commit b167153186
8 changed files with 43 additions and 18 deletions

View File

@@ -443,6 +443,16 @@ class ReportInputSerializer(serializers.Serializer):
schedule_at = serializers.DateTimeField(required=False, allow_null=True)
interval = serializers.IntegerField(required=False, allow_null=True)
def validate_schedule_at(self, value):
if value and not self.context['report'].scheduling_enabled:
raise serializers.ValidationError("Scheduling is not enabled for this report.")
return value
def validate_interval(self, value):
if value and not self.context['report'].scheduling_enabled:
raise serializers.ValidationError("Scheduling is not enabled for this report.")
return value
#
# Scripts

View File

@@ -244,8 +244,12 @@ class ReportViewSet(ViewSet):
raise RQWorkerNotRunningException()
# Retrieve and run the Report. This will create a new Job.
module, report = self._get_report(pk)
input_serializer = serializers.ReportInputSerializer(data=request.data)
module, report_cls = self._get_report(pk)
report = report_cls()
input_serializer = serializers.ReportInputSerializer(
data=request.data,
context={'report': report}
)
if input_serializer.is_valid():
report.result = Job.enqueue(