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

Commit

Permalink
Merge pull request #35 from theonion/imgjs-proto-relative
Browse files Browse the repository at this point in the history
image.js: generate protocol-relative URLs
  • Loading branch information
csinchok committed Sep 24, 2014
2 parents fa92bb0 + b72bbf8 commit 256d270
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ bin
dist
include
.Python
.DS_Store
.DS_Store
betty.conf.py
betty.db
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 256d270

Please sign in to comment.