diff --git a/aldryn_config.py b/aldryn_config.py index 4c45d6f..b1409d6 100644 --- a/aldryn_config.py +++ b/aldryn_config.py @@ -391,30 +391,23 @@ def storage_settings_for_media(self, settings, env): settings['MEDIA_ROOT'] = env('MEDIA_ROOT', os.path.join(settings['DATA_ROOT'], 'media')) storage_dsn = env(DEFAULT_STORAGE_KEY, ) + settings['DEFAULT_FILE_STORAGE'] = 'aldryn_django.storage.DefaultStorage' if not storage_dsn: + settings['MEDIA_URL'] = env('MEDIA_URL', '/media/') + if not settings['MEDIA_URL'].endswith('/'): + # Django (or something else?) silently sets MEDIA_URL to an empty + # string if it does not end with a '/' + settings['MEDIA_URL'] = '{}/'.format(settings['MEDIA_URL']) dsn = furl.furl() dsn.scheme = 'file' dsn.path = settings['MEDIA_ROOT'] - dsn.args.set("url", env('MEDIA_URL', '/media/')) + dsn.args.set("url", settings['MEDIA_URL']) storage_dsn = str(dsn) - settings[DEFAULT_STORAGE_KEY] = storage_dsn - - settings['DEFAULT_FILE_STORAGE'] = 'aldryn_django.storage.DefaultStorage' - - # Handle MEDIA_URL - settings['MEDIA_URL'] = env('MEDIA_URL', '/media/') - if not settings['MEDIA_URL']: - media_url = lazy_setting( - 'MEDIA_URL', - get_default_storage_url, - str, - ) - - settings['MEDIA_URL'] = media_url - elif not settings['MEDIA_URL'].endswith('/'): - # Django (or something else?) silently sets MEDIA_URL to an empty - # string if it does not end with a '/' - settings['MEDIA_URL'] = '{}/'.format(settings['MEDIA_URL']) + settings[DEFAULT_STORAGE_KEY] = storage_dsn + else: + # lazy_setting is incompatible with django-cms and causes error on first load + settings[DEFAULT_STORAGE_KEY] = storage_dsn + settings['MEDIA_URL'] = get_default_storage_url() # Handle media domain for built-in serving settings['MEDIA_URL_IS_ON_OTHER_DOMAIN'] = env('MEDIA_URL_IS_ON_OTHER_DOMAIN', None)