diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/context_processors.py | 4 | ||||
-rw-r--r-- | main/templatetags/cdn.py | 10 |
2 files changed, 9 insertions, 5 deletions
diff --git a/main/context_processors.py b/main/context_processors.py new file mode 100644 index 0000000..a60d4e6 --- /dev/null +++ b/main/context_processors.py @@ -0,0 +1,4 @@ +def secure(request): + return {'secure': request.is_secure()} + +# vim: set ts=4 sw=4 et: diff --git a/main/templatetags/cdn.py b/main/templatetags/cdn.py index ef6bb14..ff45e52 100644 --- a/main/templatetags/cdn.py +++ b/main/templatetags/cdn.py @@ -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 |