diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/templatetags/cdn.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/main/templatetags/cdn.py b/main/templatetags/cdn.py index 96181c16..43a7f4bc 100644 --- a/main/templatetags/cdn.py +++ b/main/templatetags/cdn.py @@ -9,8 +9,7 @@ def jquery(parser, token): 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. + # serve content from HTTPS if we know this request is secure secure = 'secure' in context and context['secure'] prefixes = { False: 'http', True: 'https' } version = '1.4.3' @@ -22,4 +21,21 @@ class JQueryNode(template.Node): jquery = '/media/jquery-%s.min.js' % version return '<script type="text/javascript" src="%s"></script>' % jquery +@register.tag +def cdnprefix(parser, token): + return CDNPrefixNode() + +class CDNPrefixNode(template.Node): + def render(self, context): + oncdn = getattr(settings, 'CDN_ENABLED', True) + if not oncdn: + return '' + secure = 'secure' in context and context['secure'] + # if left undefined, same behavior as if CDN is turned off + paths = { + False: getattr(settings, 'CDN_PATH', ''), + True: getattr(settings, 'CDN_PATH_SECURE', ''), + } + return paths[secure] + # vim: set ts=4 sw=4 et: |