mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 17:26:10 -06:00
Fix module child ordering
This commit is contained in:
parent
bf6cfd22b4
commit
87442f2a4f
@ -874,13 +874,20 @@ class ScriptModule(PythonModuleMixin, ManagedFile):
|
||||
|
||||
@cached_property
|
||||
def scripts(self):
|
||||
module = self.get_module()
|
||||
|
||||
scripts = {}
|
||||
for name, cls in inspect.getmembers(module, is_script):
|
||||
def _get_name(cls):
|
||||
# For child objects in submodules use the full import path w/o the root module as the name
|
||||
child_name = cls.full_name.split(".", maxsplit=1)[1]
|
||||
scripts[child_name] = cls
|
||||
return cls.full_name.split(".", maxsplit=1)[1]
|
||||
|
||||
module = self.get_module()
|
||||
scripts = {}
|
||||
ordered = getattr(module, 'script_order', [])
|
||||
|
||||
for cls in ordered:
|
||||
scripts[_get_name(cls)] = cls
|
||||
for name, cls in inspect.getmembers(module, is_script):
|
||||
if cls not in ordered:
|
||||
scripts[_get_name(cls)] = cls
|
||||
|
||||
return scripts
|
||||
|
||||
@ -928,13 +935,20 @@ class ReportModule(PythonModuleMixin, ManagedFile):
|
||||
|
||||
@cached_property
|
||||
def reports(self):
|
||||
module = self.get_module()
|
||||
|
||||
reports = {}
|
||||
for name, cls in inspect.getmembers(module, is_report):
|
||||
def _get_name(cls):
|
||||
# For child objects in submodules use the full import path w/o the root module as the name
|
||||
child_name = cls().full_name.split(".", maxsplit=1)[1]
|
||||
reports[child_name] = cls
|
||||
return cls.full_name.split(".", maxsplit=1)[1]
|
||||
|
||||
module = self.get_module()
|
||||
reports = {}
|
||||
ordered = getattr(module, 'report_order', [])
|
||||
|
||||
for cls in ordered:
|
||||
reports[_get_name(cls)] = cls
|
||||
for name, cls in inspect.getmembers(module, is_report):
|
||||
if cls not in ordered:
|
||||
reports[_get_name(cls)] = cls
|
||||
|
||||
return reports
|
||||
|
||||
|
@ -805,6 +805,7 @@ class ReportModuleCreateView(generic.ObjectEditView):
|
||||
@register_model_view(ReportModule, 'delete')
|
||||
class ReportModuleDeleteView(generic.ObjectDeleteView):
|
||||
queryset = ReportModule.objects.all()
|
||||
default_return_url = 'extras:report_list'
|
||||
|
||||
|
||||
class ReportListView(ContentTypePermissionRequiredMixin, View):
|
||||
@ -943,6 +944,7 @@ class ScriptModuleCreateView(generic.ObjectEditView):
|
||||
@register_model_view(ScriptModule, 'delete')
|
||||
class ScriptModuleDeleteView(generic.ObjectDeleteView):
|
||||
queryset = ScriptModule.objects.all()
|
||||
default_return_url = 'extras:script_list'
|
||||
|
||||
|
||||
class ScriptListView(ContentTypePermissionRequiredMixin, View):
|
||||
|
Loading…
Reference in New Issue
Block a user