diff --git a/netbox/core/migrations/0011_job_report_to_script.py b/netbox/core/migrations/0011_job_report_to_script.py index 4273475ef..25bc181c4 100644 --- a/netbox/core/migrations/0011_job_report_to_script.py +++ b/netbox/core/migrations/0011_job_report_to_script.py @@ -8,9 +8,10 @@ def migrate_report_jobs(apps, schema_editor): Job = apps.get_model('core', 'Job') # Delete the new ContentType effected by the introduction of core.ConfigRevision - report_content_type = ContentType.objects.get(app_label='extras', model='reportmodule') - script_content_type = ContentType.objects.get(app_label='extras', model='scriptmodule') - jobs = Job.objects.filter(object_type_id=report_content_type.id).update(object_type_id=script_content_type.id) + if ContentType.objects.filter(app_label='extras', model='reportmodule'): + report_content_type = ContentType.objects.get(app_label='extras', model='reportmodule') + script_content_type = ContentType.objects.get(app_label='extras', model='scriptmodule') + jobs = Job.objects.filter(object_type_id=report_content_type.id).update(object_type_id=script_content_type.id) class Migration(migrations.Migration): diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index 93be2d2c4..0c414ef21 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -730,37 +730,6 @@ class ConfigTemplateTest(APIViewTestCases.APIViewTestCase): ConfigTemplate.objects.bulk_create(config_templates) -class ReportTest(APITestCase): - - class TestReport(Report): - - def test_foo(self): - self.log_success(None, "Report completed") - - @classmethod - def setUpTestData(cls): - ReportModule.objects.create( - file_root=ManagedFileRootPathChoices.REPORTS, - file_path='/var/tmp/report.py' - ) - - def get_test_report(self, *args): - return ReportModule.objects.first(), self.TestReport() - - def setUp(self): - super().setUp() - - # Monkey-patch the API viewset's _get_report() method to return our test Report above - from extras.api.views import ReportViewSet - ReportViewSet._get_report = self.get_test_report - - def test_get_report(self): - url = reverse('extras-api:report-detail', kwargs={'pk': None}) - response = self.client.get(url, **self.header) - - self.assertEqual(response.data['name'], self.TestReport.__name__) - - class ScriptTest(APITestCase): class TestScript(Script): diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 76c6b186a..4c9d25ceb 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -1165,15 +1165,10 @@ class ScriptResultView(ContentTypePermissionRequiredMixin, View): legacy_script = False legacy_report = False - if job.data: - if 'logs' in job.data: - legacy_script = False - legacy_report = False - elif 'log' in job.data: + if job.data and ('logs' not in job.data): + if 'log' in job.data: legacy_script = True - legacy_report = False else: - legacy_script = False legacy_report = True # If this is an HTMX request, return only the result HTML diff --git a/netbox/templates/extras/htmx/script_result.html b/netbox/templates/extras/htmx/script_result.html index 469403580..f27672d10 100644 --- a/netbox/templates/extras/htmx/script_result.html +++ b/netbox/templates/extras/htmx/script_result.html @@ -32,8 +32,11 @@ {% endfor %} +
- {{ method }} - | + {% for time, level, obj, url, message in data.log %} +|||
---|---|---|---|
{{ time }} | ++ + | ++ {% if obj and url %} + {{ obj }} + {% elif obj %} + {{ obj }} + {% else %} + {{ ''|placeholder }} + {% endif %} + | +{{ message|markdown }} |
{{ time }} | -- - | -- {% if obj and url %} - {{ obj }} - {% elif obj %} - {{ obj }} - {% else %} - {{ ''|placeholder }} - {% endif %} - | -{{ message|markdown }} | -