Skip to content

Commit 62c01cb

Browse files
authored
Merge pull request #50 from thomasina-lee/master
replace TEMPLATE_DEBUG in templatetag fb_version
2 parents 1efdc5c + 2b7406b commit 62c01cb

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed
Lines changed: 1 addition & 0 deletions
Loading

filebrowser/templatetags/fb_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def render(self, context):
4545
else:
4646
return version.url
4747
except Exception:
48-
if settings.TEMPLATE_DEBUG:
48+
if context.template.engine.debug:
4949
raise
5050
if self.var_name:
5151
context[self.var_name] = ""

tests/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ def setUp(self):
4040

4141
self.STATIC_IMG_PATH = os.path.join(settings.BASE_DIR, 'filebrowser', "static", "filebrowser", "img", "testimage.jpg")
4242
self.STATIC_IMG_BAD_NAME_PATH = os.path.join(settings.BASE_DIR, 'filebrowser', "static", "filebrowser", "img", "TEST_IMAGE_000.jpg")
43+
self.STATIC_IMG_BAD_PATH = os.path.join(settings.BASE_DIR, 'filebrowser', "static", "filebrowser", "img", "test_not_an_image.jpg")
4344

4445
self.F_IMAGE = FileObject(os.path.join(DIRECTORY, 'folder', "testimage.jpg"), site=site)
46+
self.F_IMAGE_BAD = FileObject(os.path.join(DIRECTORY, 'folder', "test_not_an_image.jpg"), site=site)
4547
self.F_MISSING = FileObject(os.path.join(DIRECTORY, 'folder', "missing.jpg"), site=site)
4648
self.F_FOLDER = FileObject(os.path.join(DIRECTORY, 'folder'), site=site)
4749
self.F_SUBFOLDER = FileObject(os.path.join(DIRECTORY, 'folder', 'subfolder'), site=site)

tests/test_versions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ class VersionObjectTemplateTagTests(TestCase):
361361
def setUp(self):
362362
super(VersionObjectTemplateTagTests, self).setUp()
363363
shutil.copy(self.STATIC_IMG_PATH, self.FOLDER_PATH)
364+
shutil.copy(self.STATIC_IMG_BAD_PATH, self.FOLDER_PATH)
364365

365366
os.makedirs(self.PLACEHOLDER_PATH)
366367
shutil.copy(self.STATIC_IMG_PATH, self.PLACEHOLDER_PATH)
@@ -408,6 +409,13 @@ def test_non_existing_path(self):
408409
self.assertEqual(c["version_large"].url, os.path.join(settings.MEDIA_URL, ""))
409410
self.assertEqual(r, os.path.join(settings.MEDIA_URL, ""))
410411

412+
def test_jpg_not_an_image(self):
413+
t = Template('{% load fb_versions %}{% version obj "large" as version_large %}{{ version_large.url }}')
414+
c = Context({"obj": self.F_IMAGE_BAD})
415+
r = t.render(c)
416+
self.assertEqual(c["version_large"], "")
417+
self.assertEqual(r, "")
418+
411419
@patch('filebrowser.templatetags.fb_versions.SHOW_PLACEHOLDER', True)
412420
@patch('filebrowser.templatetags.fb_versions.FORCE_PLACEHOLDER', True)
413421
def test_force_with_existing_image(self):

0 commit comments

Comments
 (0)