Просмотр исходного кода

Fixes #18738: Ensure ScriptList respects script_order option

Jason Novinger 10 месяцев назад
Родитель
Сommit
39a96ddf3a
2 измененных файлов с 10 добавлено и 1 удалено
  1. 9 0
      netbox/extras/models/scripts.py
  2. 1 1
      netbox/templates/extras/script_list.html

+ 9 - 0
netbox/extras/models/scripts.py

@@ -117,6 +117,15 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
     def __str__(self):
         return self.python_name
 
+    @property
+    def ordered_scripts(self):
+        script_objects = {s.name: s for s in self.scripts.all()}
+        ordered = [
+            script_objects.pop(sc) for sc in self.module_scripts.keys() if sc in script_objects
+        ]
+        ordered.extend(script_objects.items())
+        return ordered
+
     @property
     def module_scripts(self):
 

+ 1 - 1
netbox/templates/extras/script_list.html

@@ -37,7 +37,7 @@
           {% endif %}
         </div>
       </h2>
-      {% with scripts=module.scripts.all %}
+      {% with scripts=module.ordered_scripts %}
         {% if scripts %}
           <table class="table table-hover scripts">
             <thead>