Get secure/unsecure checking actually working
We need a bit more, like actually having something relevant in the RequestContext object, in order for this to all work. Instead of putting the full request in just populate a 'secure' key with a boolean value indicating whether the request is secure. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
66d6d33c9b
commit
47c95a2821
4
main/context_processors.py
Normal file
4
main/context_processors.py
Normal file
@ -0,0 +1,4 @@
|
||||
def secure(request):
|
||||
return {'secure': request.is_secure()}
|
||||
|
||||
# vim: set ts=4 sw=4 et:
|
@ -11,13 +11,13 @@ class JQueryNode(template.Node):
|
||||
def render(self, context):
|
||||
# if we have the request in context, we can check if it is secure and
|
||||
# serve content from HTTPS instead.
|
||||
secure = 'request' in context and context['request'].is_secure()
|
||||
secure = 'secure' in context and context['secure']
|
||||
prefixes = { False: 'http', True: 'https' }
|
||||
version = '1.4.2'
|
||||
oncdn = getattr(settings, 'CDN_ENABLED', True)
|
||||
if oncdn and secure:
|
||||
jquery = 'https://ajax.googleapis.com/ajax/libs/jquery/%s/jquery.min.js' % version
|
||||
elif oncdn:
|
||||
jquery = 'http://ajax.googleapis.com/ajax/libs/jquery/%s/jquery.min.js' % version
|
||||
if oncdn:
|
||||
jquery = '%s://ajax.googleapis.com/ajax/libs/jquery/' \
|
||||
'%s/jquery.min.js' % (prefixes[secure], version)
|
||||
else:
|
||||
jquery = '/media/jquery-%s.min.js' % version
|
||||
return '<script type="text/javascript" src="%s"></script>' % jquery
|
||||
|
10
settings.py
10
settings.py
@ -52,6 +52,16 @@
|
||||
'django.template.loaders.app_directories.load_template_source',
|
||||
)
|
||||
|
||||
# We add a processor to determine if the request is secure or not
|
||||
TEMPLATE_CONTEXT_PROCESSORS = (
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.core.context_processors.debug',
|
||||
'django.core.context_processors.i18n',
|
||||
'django.core.context_processors.media',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'main.context_processors.secure',
|
||||
)
|
||||
|
||||
# This bug is a real bummer:
|
||||
# http://code.djangoproject.com/ticket/14105
|
||||
MIDDLEWARE_CLASSES = (
|
||||
|
Loading…
Reference in New Issue
Block a user