commit 154ae5ea322a87c48d5273c26b1aa2fa93fb3b36
parent 963f1ea33bb35a8d8b16af776e18d684c6494415
Author: lash <dev@holbrook.no>
Date: Fri, 2 Dec 2022 21:44:08 +0000
Inline image attachment in html render
Diffstat:
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/piknik/render/html.py b/piknik/render/html.py
@@ -154,8 +154,12 @@ class Renderer(BaseRenderer):
message_content['type'][1],
message.get_payload(),
)
- v = os.path.basename(message_content['filename'])
- r = a(v, href=s)
+ r = None
+ if message_content['type'][0] == 'image':
+ r = img(src=s)
+ else:
+ v = os.path.basename(message_content['filename'])
+ r = a(v, href=s)
s = 'd_m_{}_{}'.format(
message_content['id'],
diff --git a/tests/test_html.py b/tests/test_html.py
@@ -30,18 +30,13 @@ logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
-#def test_wrapper(p):
-# m = Message()
-# m.add_header('Foo', 'bar')
-# m.set_type('multipart/relative')
-# m.set_payload(p)
-# return m
-#
-#
-#def test_unwrapper(msg, message_callback=None, part_callback=None):
-# for v in msg.walk():
-# if message_callback != None:
-# message_callback(v)
+def test_wrapper(p):
+ m = Message()
+ m.add_header('Foo', 'bar')
+ m.add_header('X-Piknik-Envelope', 'foo')
+ m.set_type('multipart/relative')
+ m.set_payload(p)
+ return m
class TestMsg(unittest.TestCase):
@@ -100,18 +95,19 @@ class TestMsg(unittest.TestCase):
def test_issue_attachment(self):
+ b = Basket(self.store, message_wrapper=test_wrapper)
issue = Issue('foo')
- issue_id = self.b.add(issue)
+ issue_id = b.add(issue)
- m = self.b.msg(issue_id, 'f:tests/one.png')
+ m = b.msg(issue_id, 'f:tests/three.webp')
- state = self.b.get_state(issue_id)
+ state = b.get_state(issue_id)
tags = []
w = io.StringIO()
acc = Accumulator(w=w)
wrapper = Wrapper()
- renderer = Renderer(self.b, outdir=self.render_dir, wrapper=wrapper, accumulator=acc.add)
+ renderer = Renderer(b, outdir=self.render_dir, wrapper=wrapper, accumulator=acc.add)
renderer.apply_begin()
renderer.apply_issue(state, issue, tags)
renderer.apply_end()
diff --git a/tests/three.webp b/tests/three.webp
Binary files differ.