From 151374f565169db8b8ade50a1acf137018218549 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 13 Sep 2020 18:24:49 +0200 Subject: [PATCH] stages/email: fix loading of static files when path is a directory --- .../email/templatetags/passbook_stages_email.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/passbook/stages/email/templatetags/passbook_stages_email.py b/passbook/stages/email/templatetags/passbook_stages_email.py index 6d1f14f4b..81d606909 100644 --- a/passbook/stages/email/templatetags/passbook_stages_email.py +++ b/passbook/stages/email/templatetags/passbook_stages_email.py @@ -12,7 +12,7 @@ register = template.Library() def inline_static_ascii(path: str) -> str: """Inline static asset. Doesn't check file contents, plain text is assumed. If no file could be found, original path is returned""" - result = finders.find(path) + result = Path(finders.find(path)) if result: with open(result) as _file: return _file.read() @@ -23,10 +23,9 @@ def inline_static_ascii(path: str) -> str: def inline_static_binary(path: str) -> str: """Inline static asset. Uses file extension for base64 block. If no file could be found, path is returned.""" - result = finders.find(path) - suffix = Path(path).suffix - if result: + result = Path(finders.find(path)) + if result and result.is_file(): with open(result) as _file: - b64content = b64encode(_file.read()) - return f"data:image/{suffix};base64,{b64content.decode('utf-8')}" + b64content = b64encode(_file.read().encode()) + return f"data:image/{result.suffix};base64,{b64content.decode('utf-8')}" return path