18423 review changes

This commit is contained in:
Arthur 2025-03-05 17:48:02 -08:00
parent 1a1b39d11c
commit 7ac9bd9a3d
3 changed files with 27 additions and 23 deletions

View File

@ -220,17 +220,21 @@ STORAGES = {
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
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.
The specific configuration settings for each storage can be found in the [django-storages documentation](https://django-storages.readthedocs.io/en/latest/index.html).
---

View File

@ -93,7 +93,7 @@ class ManagedFile(SyncedDataMixin, models.Model):
Write the object's data to disk at the specified path
"""
# Check whether file already exists
storage = self.get_storage()
storage = self.get_storage
if storage.exists(path) and not overwrite:
raise FileExistsError()
@ -122,7 +122,7 @@ class ManagedFile(SyncedDataMixin, models.Model):
def delete(self, *args, **kwargs):
# Delete file from disk
storage = self.get_storage()
storage = self.get_storage
try:
storage.delete(self.full_path)
except FileNotFoundError:

View File

@ -26,17 +26,6 @@ class CustomStoragesLoader(importlib.abc.Loader):
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:
def get_jobs(self, name):
@ -64,5 +53,16 @@ class PythonModuleMixin:
return name
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