Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Image.js: use protocol-relative urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wentz committed Sep 24, 2014
1 parent fa92bb0 commit cc89c32
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions betty/cropper/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.http import Http404, HttpResponse, HttpResponseServerError, HttpResponseRedirect
from django.shortcuts import render
from django.views.decorators.cache import cache_control
from six.moves import urllib

from .models import Image, Ratio
from .utils.placeholder import placeholder
Expand All @@ -25,12 +26,18 @@ def image_js(request):
widths = settings.BETTY_WIDTHS
if 0 not in widths:
widths.append(0)

betty_image_url = settings.BETTY_IMAGE_URL
# make the url protocol-relative
url_parts = list(urllib.parse.urlparse(betty_image_url))
url_parts[0] = ""
betty_image_url = urllib.parse.urlunparse(url_parts)
if betty_image_url.endswith("/"):
betty_image_url = betty_image_url[:-1]
context = {
"BETTY_IMAGE_URL": settings.BETTY_IMAGE_URL,
"BETTY_IMAGE_URL": betty_image_url,
"BETTY_WIDTHS": sorted(widths)
}
if context["BETTY_IMAGE_URL"].endswith("/"):
context["BETTY_IMAGE_URL"] = context["BETTY_IMAGE_URL"][:-1]
BETTY_RATIOS = []
ratios_sorted = sorted(settings.BETTY_RATIOS, key=lambda r: Ratio(r).width / float(Ratio(r).height))
for ratio_string in ratios_sorted:
Expand Down

0 comments on commit cc89c32

Please sign in to comment.