From ce45250f015d7fb7933997fdd167166303584c3e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 30 Aug 2017 11:11:59 -0400 Subject: [PATCH] Closes #1341: Added a MEDIA_ROOT configuration setting to specify where uploaded files are stored on disk --- docs/configuration/optional-settings.md | 8 ++++++++ netbox/netbox/configuration.example.py | 4 ++++ netbox/netbox/settings.py | 10 +++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/configuration/optional-settings.md b/docs/configuration/optional-settings.md index 83b289b9aa3..22916d54c1f 100644 --- a/docs/configuration/optional-settings.md +++ b/docs/configuration/optional-settings.md @@ -135,6 +135,14 @@ An API consumer can request an arbitrary number of objects by appending the "lim --- +## MEDIA_ROOT + +Default: $BASE_DIR/netbox/media/ + +The file path to the location where media files (such as image attachments) are stored. By default, this is the `netbox/media` directory within the base NetBox installation path. + +--- + ## NAPALM_USERNAME ## NAPALM_PASSWORD diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index 78e870072ed..192653dc4e6 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -93,6 +93,10 @@ # all objects by specifying "?limit=0". MAX_PAGE_SIZE = 1000 +# The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that +# the default value of this setting is derived from the installed location. +# MEDIA_ROOT = '/opt/netbox/netbox/media' + # Credentials that NetBox will uses to authenticate to devices when connecting via NAPALM. NAPALM_USERNAME = '' NAPALM_PASSWORD = '' diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index eff6ac0bd05..5e397598bd4 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -15,6 +15,8 @@ VERSION = '2.1.4-dev' +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + # Import required configuration parameters ALLOWED_HOSTS = DATABASE = SECRET_KEY = None for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']: @@ -44,14 +46,15 @@ LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False) MAINTENANCE_MODE = getattr(configuration, 'MAINTENANCE_MODE', False) MAX_PAGE_SIZE = getattr(configuration, 'MAX_PAGE_SIZE', 1000) -PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) -PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False) +MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media')).rstrip('/') NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '') NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '') NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30) NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {}) NETBOX_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '') # Deprecated NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '') # Deprecated +PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) +PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False) SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d') SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i') SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s') @@ -104,8 +107,6 @@ "netbox/ldap_config.py to disable LDAP." ) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - # Database configuration.DATABASE.update({'ENGINE': 'django.db.backends.postgresql'}) DATABASES = { @@ -201,7 +202,6 @@ ) # Media -MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/{}media/'.format(BASE_PATH) # Disable default limit of 1000 fields per request. Needed for bulk deletion of objects. (Added in Django 1.10.)