mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 20:22:53 -06:00
19529 fix custom script path
This commit is contained in:
parent
39d7ca42fb
commit
2ece669bde
@ -1,10 +1,15 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files.storage import storages
|
from django.core.files.storage import storages
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from extras.storage import ScriptFileSystemStorage
|
from extras.storage import ScriptFileSystemStorage
|
||||||
|
|
||||||
|
|
||||||
|
def normalize(url):
|
||||||
|
return url if urlparse(url).path else url + "/"
|
||||||
|
|
||||||
|
|
||||||
def fix_script_paths(apps, schema_editor):
|
def fix_script_paths(apps, schema_editor):
|
||||||
"""
|
"""
|
||||||
Fix script paths for scripts that had incorrect path from NB 4.3.
|
Fix script paths for scripts that had incorrect path from NB 4.3.
|
||||||
@ -14,9 +19,10 @@ def fix_script_paths(apps, schema_editor):
|
|||||||
return
|
return
|
||||||
|
|
||||||
ScriptModule = apps.get_model('extras', 'ScriptModule')
|
ScriptModule = apps.get_model('extras', 'ScriptModule')
|
||||||
|
script_root_path = normalize(settings.SCRIPTS_ROOT)
|
||||||
for script in ScriptModule.objects.all():
|
for script in ScriptModule.objects.all():
|
||||||
if script.file_path.startswith(settings.SCRIPTS_ROOT):
|
if script.file_path.startswith(script_root_path):
|
||||||
script.file_path = script.file_path[len(settings.SCRIPTS_ROOT):]
|
script.file_path = script.file_path[len(script_root_path):]
|
||||||
script.save()
|
script.save()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user