Skip to content
Browse files

Correctly handle secure/non-secure media_url when doing offsite linking

  • Loading branch information...
1 parent e61c2fc commit 08b0505c71ad028a6d632a71a2c58e641900c109 @cnorthwood cnorthwood committed Nov 18, 2010
Showing with 16 additions and 2 deletions.
  1. +1 −1 demos/molly_oxford/settings.py
  2. +15 −1 molly/utils/context_processors.py
View
2 demos/molly_oxford/settings.py
@@ -75,7 +75,7 @@
'django.core.context_processors.auth',
'django.core.context_processors.debug',
# 'django.core.context_processors.i18n',
- 'django.core.context_processors.media',
+ 'molly.utils.context_processors.ssl_media',
# 'django.contrib.messages.context_processors.messages',
'molly.wurfl.context_processors.wurfl_device',
'molly.wurfl.context_processors.device_specific_media',
View
16 molly/utils/context_processors.py
@@ -8,4 +8,18 @@ def full_path(request):
def google_analytics(request):
return {
'google_analytics': settings.API_KEYS.get('google_analytics'),
- }
+ }
+
+def ssl_media(request):
+ """
+ If the request is secure, then the media url should be HTTPS
+
+ Source: http://djangosnippets.org/snippets/1754/
+ """
+
+ if request.is_secure():
+ ssl_media_url = settings.MEDIA_URL.replace('http://', 'https://')
+ else:
+ ssl_media_url = settings.MEDIA_URL
+
+ return {'MEDIA_URL': ssl_media_url}

0 comments on commit 08b0505

Please sign in to comment.
Something went wrong with that request. Please try again.