Package madrona :: Package common :: Package templatetags :: Module absolute_media_url
[hide private]

Source Code for Module madrona.common.templatetags.absolute_media_url

 1  from urlparse import * 
 2  from django.template import Library 
 3  from django.contrib.sites.models import Site 
 4  from django.conf import settings 
 5  from django import template 
 6   
 7  register = Library() 
 8   
 9  @register.tag(name="absolute_media_url") 
10 -def do_absolute_media_url(parser, token):
11 """Provides MEDIA_URL, but adds the hostname if necessary 12 """ 13 return AbsoluteMediaUrlNode(settings.MEDIA_URL)
14
15 -class AbsoluteMediaUrlNode(template.Node):
16 - def __init__(self, media_url):
17 self.media_url = media_url
18
19 - def render(self, context):
20 o = urlparse(self.media_url) 21 if o.hostname is None: 22 domain = 'http://%s' % (Site.objects.get_current().domain, ) 23 return "%s" % urljoin(domain, self.media_url) 24 else: 25 return self.media_url
26