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

Commit

Permalink
Merge branch 'master' into cropped-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
camsom committed Sep 15, 2015
2 parents 6be164e + 68e56a7 commit 851f60f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ def pytest_configure():
BETTY_IMAGE_URL="http://example.com/betty/",
BETTY_PUBLIC_KEY="noop",
BETTY_PRIVATE_KEY="noop",
BETTY_DEFAULT_IMAGE=666
BETTY_DEFAULT_IMAGE=0
)
6 changes: 3 additions & 3 deletions djbetty/templatetags/betty.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def coerce_image(image):
"""For right now, we need to be able to pass a string, or an int, or None
into the template tags, and still have them return something meaningful"""

if image is None:
if settings.BETTY_DEFAULT_IMAGE:
if not image:
if hasattr(settings, 'BETTY_DEFAULT_IMAGE') and settings.BETTY_DEFAULT_IMAGE != None:
# If we have a default image, let's use that.
return AnonymousImageField(settings.BETTY_DEFAULT_IMAGE)
else:
Expand Down Expand Up @@ -62,7 +62,7 @@ def cropped_url(image, ratio="16x9", width=600, format="jpg"):
def cropped(context, image, ratio="16x9", width=600, format="jpg"):
image = coerce_image(image)
if not image or not image.id:
if settings.BETTY_DEFAULT_IMAGE:
if hasattr(settings, 'BETTY_DEFAULT_IMAGE'):
image = AnonymousImageField(settings.BETTY_DEFAULT_IMAGE)
else:
return ""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_cropped_bad_value(self):
t = Template("{% load betty %}{% cropped image %}")
c = Context({"image": ""})
html = t.render(c)
self.assertEqual(html, '<img src="http://example.com/betty/666/16x9/600.jpg" />')
self.assertEqual(html, '<img src="http://example.com/betty/0/16x9/600.jpg" />')

def test_cropped_url_template_tag(self):
test_object = TestModel()
Expand All @@ -47,10 +47,10 @@ def test_image_id(self):
self.assertEquals(t.render(c), '<img src="http://example.com/betty/1234/5/16x9/600.jpg" />')

c = Context({"image": ""})
self.assertEquals(t.render(c), '<img src="http://example.com/betty/666/16x9/600.jpg" />')
self.assertEquals(t.render(c), '<img src="http://example.com/betty/0/16x9/600.jpg" />')

c = Context({"image": None})
self.assertEquals(t.render(c), '<img src="http://example.com/betty/666/16x9/600.jpg" />')
self.assertEquals(t.render(c), '<img src="http://example.com/betty/0/16x9/600.jpg" />')

def test_no_default_image(self):
settings.BETTY_DEFAULT_IMAGE = None
Expand Down

0 comments on commit 851f60f

Please sign in to comment.