def render(self, context):
        path = self.path.resolve(context)
        if self.static:
            base_url = settings.STATIC_URL
        else:
            base_url = settings.MEDIA_URL
        if request_is_secure():
            if hasattr(base_url, 'https'):
                url = base_url.https()
            else:
                if hasattr(base_url, 'match'):
                    url = base_url.match(path)
                else:
                    url = base_url
                url = url.replace('http://', 'https://')
        else:
            if hasattr(base_url, 'match'):
                url = base_url.match(path)
            else:
                url = base_url
            url = url.replace('https://', 'http://')

        uri = urljoin(url, iri_to_uri(path))
        if self.as_var:
            context[self.as_var] = uri
            return ''
        else:
            return uri
Esempio n. 2
0
 def get_url(self, path, force_https=False):
     if force_https or request_is_secure():
         url = self.https()
     else:
         url = self.match(path).replace('https://', 'http://')
     url = list(urlparse(urljoin(url, path)))
     if sys.version_info[0] == 2:
         url[2] = url[2].encode('utf-8')
     url[2] = urlquote(unquote(url[2]))
     return urlunparse(url)
 def render(self, context):
     path = self.path.resolve(context)
     base_url = settings.MEDIA_URL
     if request_is_secure():
         if hasattr(base_url, 'https'):
             url = base_url.https()
         else:
             if hasattr(base_url, 'match'):
                 url = base_url.match(path)
             else:
                 url = base_url
             url = url.replace('http://', 'https://')
     else:
         if hasattr(base_url, 'match'):
             url = base_url.match(path)
         else:
             url = base_url
         url = url.replace('https://', 'http://')
     return urljoin(url, iri_to_uri(path))
 def render(self, context):
     path = self.path.resolve(context)
     base_url = settings.MEDIA_URL
     if request_is_secure():
         if hasattr(base_url, 'https'):
             url = base_url.https()
         else:
             if hasattr(base_url, 'match'):
                 url = base_url.match(path)
             else:
                 url = base_url
             url = url.replace('http://', 'https://')
     else:
         if hasattr(base_url, 'match'):
             url = base_url.match(path)
         else:
             url = base_url
         url = url.replace('https://', 'http://')
     return urljoin(url, iri_to_uri(path))
Esempio n. 5
0
 def url(self, name):
     if self.base_url is None:
         raise ValueError("This file is not accessible via a URL.")
     name = self._path(name)
     if request_is_secure():
         if hasattr(self.base_url, 'https'):
             url = self.base_url.https()
         else:
             if hasattr(self.base_url, 'match'):
                 url = self.base_url.match(name)
             else:
                 url = self.base_url
             url = url.replace('http://', 'https://')
     else:
         if hasattr(self.base_url, 'match'):
             url = self.base_url.match(name)
         else:
             url = self.base_url
         url = url.replace('https://', 'http://')
     return urljoin(url, iri_to_uri(name))
 def url(self, name):
     if self.base_url is None:
         raise ValueError("This file is not accessible via a URL.")
     name = self._path(name)
     if request_is_secure():
         if hasattr(self.base_url, 'https'):
             url = self.base_url.https()
         else:
             if hasattr(self.base_url, 'match'):
                 url = self.base_url.match(name)
             else:
                 url = self.base_url
             url = url.replace('http://', 'https://')
     else:
         if hasattr(self.base_url, 'match'):
             url = self.base_url.match(name)
         else:
             url = self.base_url
         url = url.replace('https://', 'http://')
     return urljoin(url, iri_to_uri(name))
Esempio n. 7
0
 def get_url(self, path, force_https=False):
     if force_https or request_is_secure():
         url = self.https()
     else:
         url = self.match(path).replace('https://', 'http://')
     return urljoin(url, iri_to_uri(path))
Esempio n. 8
0
 def get_url(self, path, force_https=False):
     if force_https or request_is_secure():
         url = self.https()
     else:
         url = self.match(path).replace('https://', 'http://')
     return urljoin(url, iri_to_uri(path))