Skip to content

Commit

Permalink
Fixes media configuration (#318)
Browse files Browse the repository at this point in the history
* fix MEDIA_URL

c11004a

* Fixes #314

* Fixes #261

* Bump to new version
  • Loading branch information
FinalAngel authored Jan 30, 2024
1 parent 97cd0a7 commit 7f0db7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Changelog
=========


4.2.9.1 (2024-01-30)
====================

* Fixed MEDIA_URL configuration
* Removed not required SESSION_COOKIE_HTTPONLY setting
* Added Sentry Configurations


4.2.9.0 (2024-01-02)
====================

Expand Down
40 changes: 15 additions & 25 deletions aldryn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def domain_settings(self, data, settings, env):
if d.strip()
]
domains = {
env("SITE_ID", 1): {
env('SITE_ID', 1): {
'name': env('SITE_NAME', ''),
'domain': domain,
'aliases': domain_aliases,
Expand Down Expand Up @@ -285,11 +285,6 @@ def security_settings(self, data, settings, env):
)
s['SESSION_COOKIE_AGE'] = env('SESSION_COOKIE_AGE', data.get('session_timeout') or 60 * 60 * 24 * 7 * 2)

# SESSION_COOKIE_HTTPONLY and SECURE_FRAME_DENY must be False for CMS
# SESSION_COOKIE_HTTPONLY is handled by
# django.contrib.sessions.middleware.SessionMiddleware
s['SESSION_COOKIE_HTTPONLY'] = env('SESSION_COOKIE_HTTPONLY', False)

s['SECURE_CONTENT_TYPE_NOSNIFF'] = env('SECURE_CONTENT_TYPE_NOSNIFF', False)
s['SECURE_BROWSER_XSS_FILTER'] = env('SECURE_BROWSER_XSS_FILTER', False)

Expand Down Expand Up @@ -374,6 +369,7 @@ def sentry_settings(self, settings, env):
debug=settings['DEBUG'],
release=env('GIT_COMMIT', 'develop'),
environment=env('STAGE', 'local'),
enable_tracing=True,
)

def storage_settings_for_media(self, settings, env):
Expand All @@ -392,32 +388,26 @@ def storage_settings_for_media(self, settings, env):

storage_dsn = env(DEFAULT_STORAGE_KEY, )
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_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()

settings['STORAGES']['default'] = {
"BACKEND": "aldryn_django.storage.DefaultStorage"
'BACKEND': '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'])

# Handle media domain for built-in serving
settings['MEDIA_URL_IS_ON_OTHER_DOMAIN'] = env('MEDIA_URL_IS_ON_OTHER_DOMAIN', None)
if not settings['MEDIA_URL_IS_ON_OTHER_DOMAIN']:
Expand Down Expand Up @@ -455,7 +445,7 @@ def storage_settings_for_static(self, data, settings, env):
else:
storage = 'django.contrib.staticfiles.storage.StaticFilesStorage'

settings['STORAGES']['staticfiles'] = {"BACKEND": storage}
settings['STORAGES']['staticfiles'] = {'BACKEND': storage}

settings['STATIC_URL'] = env('STATIC_URL', '/static/')
static_host = furl.furl(settings['STATIC_URL']).host
Expand Down
2 changes: 1 addition & 1 deletion aldryn_django/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '4.2.9.0'
__version__ = '4.2.9.1'

0 comments on commit 7f0db7e

Please sign in to comment.