mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 04:58:16 -06:00
14438 temp
This commit is contained in:
parent
c4ffafaca2
commit
ecd2712253
@ -1,11 +1,11 @@
|
||||
# Generated by Django 4.2.9 on 2024-02-05 21:37
|
||||
import inspect
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
def update_event_rules(apps, schema_editor):
|
||||
from extras.models import ScriptModule
|
||||
Script = apps.get_model('extras', 'Script')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
ct = ContentType.objects.filter(app_label='extras', model='script').first()
|
||||
@ -25,7 +25,20 @@ def update_event_rules(apps, schema_editor):
|
||||
rule.save()
|
||||
|
||||
|
||||
def get_module_scripts(instance):
|
||||
def is_script(obj):
|
||||
"""
|
||||
Returns True if the object is a Script or Report.
|
||||
"""
|
||||
from extras.scripts import Script
|
||||
from extras.reports import Report
|
||||
|
||||
try:
|
||||
return (issubclass(obj, Report) and obj != Report) or (issubclass(obj, Script) and obj != Script)
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
def get_module_scripts(apps, instance):
|
||||
|
||||
def _get_name(cls):
|
||||
# For child objects in submodules use the full import path w/o the root module as the name
|
||||
@ -34,7 +47,6 @@ def get_module_scripts(instance):
|
||||
try:
|
||||
module = instance.get_module()
|
||||
except Exception as e:
|
||||
logger.debug(f"Failed to load script: {instance.python_name} error: {e}")
|
||||
module = None
|
||||
|
||||
scripts = {}
|
||||
@ -43,6 +55,7 @@ def get_module_scripts(instance):
|
||||
for cls in ordered:
|
||||
scripts[_get_name(cls)] = cls
|
||||
for name, cls in inspect.getmembers(module, is_script):
|
||||
breakpoint()
|
||||
if cls not in ordered:
|
||||
scripts[_get_name(cls)] = cls
|
||||
|
||||
@ -56,7 +69,7 @@ def update_scripts(apps, schema_editor):
|
||||
ct = ContentType.objects.filter(app_label='extras', model='script').first()
|
||||
|
||||
for module in ScriptModule.objects.all():
|
||||
for script in get_module_scripts(module).keys():
|
||||
for script in get_module_scripts(apps, module).keys():
|
||||
obj = Script.objects.create(
|
||||
name=script,
|
||||
module=ScriptModule.objects.get(file_root=module.file_root, file_path=module.file_path),
|
||||
|
Loading…
Reference in New Issue
Block a user