Przeglądaj źródła

Save old JobResults

kkthxbye 3 lat temu
rodzic
commit
f13a00b2dd

+ 2 - 2
netbox/extras/api/views.py

@@ -179,7 +179,7 @@ class ReportViewSet(ViewSet):
             for r in JobResult.objects.filter(
             for r in JobResult.objects.filter(
                 obj_type=report_content_type,
                 obj_type=report_content_type,
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-            ).defer('data')
+            ).order_by('name', '-created').distinct('name').defer('data')
         }
         }
 
 
         # Iterate through all available Reports.
         # Iterate through all available Reports.
@@ -271,7 +271,7 @@ class ScriptViewSet(ViewSet):
             for r in JobResult.objects.filter(
             for r in JobResult.objects.filter(
                 obj_type=script_content_type,
                 obj_type=script_content_type,
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-            ).defer('data').order_by('created')
+            ).order_by('name', '-created').distinct('name').defer('data')
         }
         }
 
 
         flat_list = []
         flat_list = []

+ 0 - 7
netbox/extras/management/commands/runscript.py

@@ -113,13 +113,6 @@ class Command(BaseCommand):
 
 
         script_content_type = ContentType.objects.get(app_label='extras', model='script')
         script_content_type = ContentType.objects.get(app_label='extras', model='script')
 
 
-        # Delete any previous terminal state results
-        JobResult.objects.filter(
-            obj_type=script_content_type,
-            name=script.full_name,
-            status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-        ).delete()
-
         # Create the job result
         # Create the job result
         job_result = JobResult.objects.create(
         job_result = JobResult.objects.create(
             name=script.full_name,
             name=script.full_name,

+ 0 - 9
netbox/extras/reports.py

@@ -84,15 +84,6 @@ def run_report(job_result, *args, **kwargs):
         job_result.save()
         job_result.save()
         logging.error(f"Error during execution of report {job_result.name}")
         logging.error(f"Error during execution of report {job_result.name}")
 
 
-    # Delete any previous terminal state results
-    JobResult.objects.filter(
-        obj_type=job_result.obj_type,
-        name=job_result.name,
-        status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-    ).exclude(
-        pk=job_result.pk
-    ).delete()
-
 
 
 class Report(object):
 class Report(object):
     """
     """

+ 1 - 10
netbox/extras/scripts.py

@@ -481,15 +481,6 @@ def run_script(data, request, commit=True, *args, **kwargs):
     else:
     else:
         _run_script()
         _run_script()
 
 
-    # Delete any previous terminal state results
-    JobResult.objects.filter(
-        obj_type=job_result.obj_type,
-        name=job_result.name,
-        status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-    ).exclude(
-        pk=job_result.pk
-    ).delete()
-
 
 
 def get_scripts(use_names=False):
 def get_scripts(use_names=False):
     """
     """
@@ -497,7 +488,7 @@ def get_scripts(use_names=False):
     defined name in place of the actual module name.
     defined name in place of the actual module name.
     """
     """
     scripts = OrderedDict()
     scripts = OrderedDict()
-    # Iterate through all modules within the reports path. These are the user-created files in which reports are
+    # Iterate through all modules within the scripts path. These are the user-created files in which reports are
     # defined.
     # defined.
     for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
     for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
         # Remove cached module to ensure consistency with filesystem
         # Remove cached module to ensure consistency with filesystem

+ 2 - 2
netbox/extras/views.py

@@ -524,7 +524,7 @@ class ReportListView(ContentTypePermissionRequiredMixin, View):
             for r in JobResult.objects.filter(
             for r in JobResult.objects.filter(
                 obj_type=report_content_type,
                 obj_type=report_content_type,
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-            ).defer('data')
+            ).order_by('name', '-created').distinct('name').defer('data')
         }
         }
 
 
         ret = []
         ret = []
@@ -656,7 +656,7 @@ class ScriptListView(ContentTypePermissionRequiredMixin, View):
             for r in JobResult.objects.filter(
             for r in JobResult.objects.filter(
                 obj_type=script_content_type,
                 obj_type=script_content_type,
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
                 status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-            ).defer('data')
+            ).order_by('name', '-created').distinct('name').defer('data')
         }
         }
 
 
         for _scripts in scripts.values():
         for _scripts in scripts.values():

+ 1 - 10
netbox/netbox/views/__init__.py

@@ -19,8 +19,7 @@ from circuits.models import Circuit, Provider
 from dcim.models import (
 from dcim.models import (
     Cable, ConsolePort, Device, DeviceType, Interface, PowerPanel, PowerFeed, PowerPort, Rack, Site,
     Cable, ConsolePort, Device, DeviceType, Interface, PowerPanel, PowerFeed, PowerPort, Rack, Site,
 )
 )
-from extras.choices import JobResultStatusChoices
-from extras.models import ObjectChange, JobResult
+from extras.models import ObjectChange
 from extras.tables import ObjectChangeTable
 from extras.tables import ObjectChangeTable
 from ipam.models import Aggregate, IPAddress, IPRange, Prefix, VLAN, VRF
 from ipam.models import Aggregate, IPAddress, IPRange, Prefix, VLAN, VRF
 from netbox.constants import SEARCH_MAX_RESULTS, SEARCH_TYPES
 from netbox.constants import SEARCH_MAX_RESULTS, SEARCH_TYPES
@@ -48,13 +47,6 @@ class HomeView(View):
             pk__lt=F('_path__destination_id')
             pk__lt=F('_path__destination_id')
         )
         )
 
 
-        # Report Results
-        report_content_type = ContentType.objects.get(app_label='extras', model='report')
-        report_results = JobResult.objects.filter(
-            obj_type=report_content_type,
-            status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
-        ).defer('data')[:10]
-
         def build_stats():
         def build_stats():
             org = (
             org = (
                 ("dcim.view_site", "Sites", Site.objects.restrict(request.user, 'view').count),
                 ("dcim.view_site", "Sites", Site.objects.restrict(request.user, 'view').count),
@@ -150,7 +142,6 @@ class HomeView(View):
         return render(request, self.template_name, {
         return render(request, self.template_name, {
             'search_form': SearchForm(),
             'search_form': SearchForm(),
             'stats': build_stats(),
             'stats': build_stats(),
-            'report_results': report_results,
             'changelog_table': changelog_table,
             'changelog_table': changelog_table,
             'new_release': new_release,
             'new_release': new_release,
         })
         })