mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-10 05:42:16 -06:00
Compare commits
1 Commits
5f09dff5d3
...
20660-scri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
285abe7cc0 |
@@ -3,6 +3,7 @@ import importlib.util
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from django.core.cache import cache
|
||||||
from django.core.files.storage import storages
|
from django.core.files.storage import storages
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
@@ -30,7 +31,14 @@ class CustomStoragesLoader(importlib.abc.Loader):
|
|||||||
return None # Use default module creation
|
return None # Use default module creation
|
||||||
|
|
||||||
def exec_module(self, module):
|
def exec_module(self, module):
|
||||||
storage = storages.create_storage(storages.backends["scripts"])
|
# Cache storage for 5 minutes (300 seconds)
|
||||||
|
cache_key = "storage_scripts"
|
||||||
|
storage = cache.get(cache_key)
|
||||||
|
|
||||||
|
if storage is None:
|
||||||
|
storage = storages['scripts']
|
||||||
|
cache.set(cache_key, storage, timeout=300) # 5 minutes
|
||||||
|
|
||||||
with storage.open(self.filename, 'rb') as f:
|
with storage.open(self.filename, 'rb') as f:
|
||||||
code = f.read()
|
code = f.read()
|
||||||
exec(code, module.__dict__)
|
exec(code, module.__dict__)
|
||||||
|
|||||||
Reference in New Issue
Block a user