mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
18423 review changes
This commit is contained in:
parent
1a1b39d11c
commit
7ac9bd9a3d
@ -220,17 +220,21 @@ STORAGES = {
|
|||||||
|
|
||||||
Within the STORAGES dict, "default" is used for image uploads and "scripts" is used for Scripts.
|
Within the STORAGES dict, "default" is used for image uploads and "scripts" is used for Scripts.
|
||||||
|
|
||||||
The configuration parameters for the specified storage backend are defined under the `STORAGE_CONFIG` setting.
|
If using a remote storage like S3, define the config as STORAGES[key]["OPTIONS"] for each storage item as needed. For example:
|
||||||
|
|
||||||
---
|
```python
|
||||||
|
STORAGES = {
|
||||||
|
"scripts": {
|
||||||
|
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
|
||||||
|
"OPTIONS": {
|
||||||
|
'access_key': 'access key',
|
||||||
|
'secret_key': 'secret key',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## STORAGE_CONFIG
|
The specific configuration settings for each storage can be found in the [django-storages documentation](https://django-storages.readthedocs.io/en/latest/index.html).
|
||||||
|
|
||||||
Default: Empty
|
|
||||||
|
|
||||||
A dictionary of configuration parameters for the storage backend configured as `STORAGE_BACKEND`. The specific parameters to be used here are specific to each backend; see the documentation for your selected backend ([`django-storages`](https://django-storages.readthedocs.io/en/stable/) or [`django-storage-swift`](https://github.com/dennisv/django-storage-swift)) for more detail.
|
|
||||||
|
|
||||||
If `STORAGE_BACKEND` is not defined, this setting will be ignored.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class ManagedFile(SyncedDataMixin, models.Model):
|
|||||||
Write the object's data to disk at the specified path
|
Write the object's data to disk at the specified path
|
||||||
"""
|
"""
|
||||||
# Check whether file already exists
|
# Check whether file already exists
|
||||||
storage = self.get_storage()
|
storage = self.get_storage
|
||||||
if storage.exists(path) and not overwrite:
|
if storage.exists(path) and not overwrite:
|
||||||
raise FileExistsError()
|
raise FileExistsError()
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ class ManagedFile(SyncedDataMixin, models.Model):
|
|||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
# Delete file from disk
|
# Delete file from disk
|
||||||
storage = self.get_storage()
|
storage = self.get_storage
|
||||||
try:
|
try:
|
||||||
storage.delete(self.full_path)
|
storage.delete(self.full_path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -26,17 +26,6 @@ class CustomStoragesLoader(importlib.abc.Loader):
|
|||||||
exec(code, module.__dict__)
|
exec(code, module.__dict__)
|
||||||
|
|
||||||
|
|
||||||
def load_module(module_name, filename):
|
|
||||||
spec = importlib.util.spec_from_file_location(module_name, filename)
|
|
||||||
if spec is None:
|
|
||||||
raise ModuleNotFoundError(f"Could not find module: {module_name}")
|
|
||||||
loader = CustomStoragesLoader(filename)
|
|
||||||
module = importlib.util.module_from_spec(spec)
|
|
||||||
sys.modules[module_name] = module
|
|
||||||
loader.exec_module(module)
|
|
||||||
return module
|
|
||||||
|
|
||||||
|
|
||||||
class PythonModuleMixin:
|
class PythonModuleMixin:
|
||||||
|
|
||||||
def get_jobs(self, name):
|
def get_jobs(self, name):
|
||||||
@ -64,5 +53,16 @@ class PythonModuleMixin:
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
def get_module(self):
|
def get_module(self):
|
||||||
module = load_module(self.python_name, self.name)
|
"""
|
||||||
|
Load the module using importlib, but use a custom loader to use django-storages
|
||||||
|
instead of the file system.
|
||||||
|
"""
|
||||||
|
spec = importlib.util.spec_from_file_location(self.python_name, self.name)
|
||||||
|
if spec is None:
|
||||||
|
raise ModuleNotFoundError(f"Could not find module: {self.python_name}")
|
||||||
|
loader = CustomStoragesLoader(self.name)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
sys.modules[self.python_name] = module
|
||||||
|
loader.exec_module(module)
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
Loading…
Reference in New Issue
Block a user