Skip to content

Commit

Permalink
Correctly handle secure/non-secure media_url when doing offsite linking
Browse files Browse the repository at this point in the history
  • Loading branch information
cnorthwood committed Nov 18, 2010
1 parent e61c2fc commit 08b0505
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demos/molly_oxford/settings.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
'django.core.context_processors.auth', 'django.core.context_processors.auth',
'django.core.context_processors.debug', 'django.core.context_processors.debug',
# 'django.core.context_processors.i18n', # 'django.core.context_processors.i18n',
'django.core.context_processors.media', 'molly.utils.context_processors.ssl_media',
# 'django.contrib.messages.context_processors.messages', # 'django.contrib.messages.context_processors.messages',
'molly.wurfl.context_processors.wurfl_device', 'molly.wurfl.context_processors.wurfl_device',
'molly.wurfl.context_processors.device_specific_media', 'molly.wurfl.context_processors.device_specific_media',
Expand Down
16 changes: 15 additions & 1 deletion molly/utils/context_processors.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@ def full_path(request):
def google_analytics(request): def google_analytics(request):
return { return {
'google_analytics': settings.API_KEYS.get('google_analytics'), '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.