summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-10-27 11:20:22 -0500
committerDan McGee <dan@archlinux.org>2010-10-27 11:20:22 -0500
commit52662150470140cdea9bf1166265fb36ff4cd7c1 (patch)
tree21e682a1305ac4311a52d1a5be3be3dd0cd17973 /main
parent1a8114c00f22252b6e2b0c4a741f0bea1de5dd1d (diff)
Add tag for inserting CDN prefix on media URLs
This tag will just be placed before any media reference that is available on the CDN; if the CDN is enabled and CDN_PATH/CDN_PATH_SECURE are defined the correct URL will be generated. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r--main/templatetags/cdn.py20
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: