Skip to content

Commit

Permalink
Merge pull request #9 from pythdasch/add_support_for_static
Browse files Browse the repository at this point in the history
adding static support
  • Loading branch information
ricobl committed Jun 8, 2016
2 parents b33f622 + 91827fd commit e7ad572
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions django_thumbor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ def _prepend_media_url(url):
return url


def _prepend_static_url(url):
if url.startswith(settings.STATIC_URL):
url = _remove_prefix(url, settings.STATIC_URL)
url.lstrip('/')
return '%s/%s' % (conf.THUMBOR_STATIC_URL, url)
return url


def generate_url(image_url, **kwargs):
image_url = _prepend_media_url(image_url)
image_url = _prepend_static_url(image_url)
image_url = _remove_schema(image_url)

kwargs = dict(conf.THUMBOR_ARGUMENTS, **kwargs)
Expand Down
4 changes: 4 additions & 0 deletions django_thumbor/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
THUMBOR_MEDIA_URL = getattr(settings, 'THUMBOR_MEDIA_URL',
'http://localhost:8000/media').rstrip('/')


THUMBOR_STATIC_URL = getattr(settings, 'THUMBOR_STATIC_URL',
'http://localhost:8000/static').rstrip('/')

# The same security key used in the thumbor service to
# match the URL construction
THUMBOR_SECURITY_KEY = getattr(settings, 'THUMBOR_SECURITY_KEY',
Expand Down
8 changes: 8 additions & 0 deletions testproject/tests/test_generate_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ def test_should_prepend_the_domain_to_media_url_images(self):
self.assertURLEquals('/media/uploads/image.jpg',
'localhost:8000/media/uploads/image.jpg')

def test_should_prepend_the_domain_to_static_url_images(self):
self.assertURLEquals('/static/uploads/image.jpg',
'localhost:8000/static/uploads/image.jpg')

@override_settings(MEDIA_URL="")
def test_should_not_prepend_media_url_if_none_is_set(self):
self.assertURLEquals('http://www.domain.com/media/uploads/image.jpg', 'www.domain.com/media/uploads/image.jpg')

@override_settings(MEDIA_URL="")
def test_should_not_prepend_media_url_if_none_is_set(self):
self.assertURLEquals('http://www.domain.com/static/uploads/image.jpg', 'www.domain.com/static/uploads/image.jpg')

def test_should_remove_the_scheme_from_external_images(self):
self.assertURLEquals('http://some.domain.com/path/image.jpg',
'some.domain.com/path/image.jpg')

0 comments on commit e7ad572

Please sign in to comment.