18423 review changes

This commit is contained in:
Arthur 2025-03-06 08:56:00 -08:00
parent 7ac9bd9a3d
commit af6f41d8e6
2 changed files with 23 additions and 18 deletions

View File

@ -10,6 +10,7 @@ from django.urls import reverse
from django.utils.translation import gettext as _
from ..choices import ManagedFileRootPathChoices
from extras.storage import ScriptFileSystemStorage
from netbox.models.features import SyncedDataMixin
from utilities.querysets import RestrictedQuerySet
@ -78,10 +79,14 @@ class ManagedFile(SyncedDataMixin, models.Model):
return os.path.join(self._resolve_root_path(), self.file_path)
def _resolve_root_path(self):
storage = self.get_storage
if isinstance(storage, ScriptFileSystemStorage):
return {
'scripts': settings.SCRIPTS_ROOT,
'reports': settings.REPORTS_ROOT,
}[self.file_root]
else:
return ""
def sync_data(self):
if self.data_file:

View File

@ -75,6 +75,7 @@ AUTH_PASSWORD_VALIDATORS = getattr(configuration, 'AUTH_PASSWORD_VALIDATORS', [
BASE_PATH = trailing_slash(getattr(configuration, 'BASE_PATH', ''))
CHANGELOG_SKIP_EMPTY_CHANGES = getattr(configuration, 'CHANGELOG_SKIP_EMPTY_CHANGES', True)
CENSUS_REPORTING_ENABLED = getattr(configuration, 'CENSUS_REPORTING_ENABLED', True)
CONFIG_STORAGES = getattr(configuration, 'STORAGES', {})
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIST', [])
CORS_ORIGIN_WHITELIST = getattr(configuration, 'CORS_ORIGIN_WHITELIST', [])
@ -178,7 +179,6 @@ SESSION_COOKIE_SECURE = getattr(configuration, 'SESSION_COOKIE_SECURE', False)
SESSION_FILE_PATH = getattr(configuration, 'SESSION_FILE_PATH', None)
STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
STORAGES = getattr(configuration, 'STORAGES', None)
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
TRANSLATION_ENABLED = getattr(configuration, 'TRANSLATION_ENABLED', True)
@ -236,7 +236,7 @@ DATABASES = {
#
if STORAGE_BACKEND is not None:
if STORAGES is not None:
if not CONFIG_STORAGES:
raise ImproperlyConfigured(
"STORAGE_BACKEND and STORAGES are both set, remove the deprecated STORAGE_BACKEND setting."
)
@ -251,8 +251,7 @@ if STORAGE_CONFIG is not None:
)
# Default STORAGES for Django
if STORAGES is None:
STORAGES = {
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
@ -262,7 +261,8 @@ if STORAGES is None:
"scripts": {
"BACKEND": "extras.storage.ScriptFileSystemStorage",
},
}
}
STORAGES.update(CONFIG_STORAGES)
# TODO: This code is deprecated and needs to be removed in the future
if STORAGE_BACKEND is not None: