mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
19529 fix custom script path
This commit is contained in:
parent
17cecb0d0b
commit
39d7ca42fb
31
netbox/extras/migrations/0129_fix_script_paths.py
Normal file
31
netbox/extras/migrations/0129_fix_script_paths.py
Normal file
@ -0,0 +1,31 @@
|
||||
from django.conf import settings
|
||||
from django.core.files.storage import storages
|
||||
from django.db import migrations
|
||||
|
||||
from extras.storage import ScriptFileSystemStorage
|
||||
|
||||
|
||||
def fix_script_paths(apps, schema_editor):
|
||||
"""
|
||||
Fix script paths for scripts that had incorrect path from NB 4.3.
|
||||
"""
|
||||
storage = storages.create_storage(storages.backends["scripts"])
|
||||
if not isinstance(storage, ScriptFileSystemStorage):
|
||||
return
|
||||
|
||||
ScriptModule = apps.get_model('extras', 'ScriptModule')
|
||||
for script in ScriptModule.objects.all():
|
||||
if script.file_path.startswith(settings.SCRIPTS_ROOT):
|
||||
script.file_path = script.file_path[len(settings.SCRIPTS_ROOT):]
|
||||
script.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0128_tableconfig'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(code=fix_script_paths, reverse_code=migrations.RunPython.noop),
|
||||
]
|
Loading…
Reference in New Issue
Block a user