piknik

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit 0cb789ef7591a13d872de80ab55a0be720228e32
parent 886db2bcb7fd6aaadcd623ec55a63b3a512627b0
Author: lash <dev@holbrook.no>
Date:   Fri,  2 Dec 2022 21:26:00 +0000

Render message parts in html

Diffstat:
Mpiknik/render/html.py | 29++++++++++++++++++++++-------
Mpiknik/wrap.py | 6++++--
Mtests/test_render.py | 16++++++++++++++--
3 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/piknik/render/html.py b/piknik/render/html.py @@ -51,6 +51,8 @@ class Accumulator: self.msg = ol(_id='message_list') elif v_id[:2] == 'm_': self.msg.add(li(v)) + elif v_id[:4] == 'd_m_': + self.msg.add(v) else: self.doc = v @@ -125,9 +127,7 @@ class Renderer(BaseRenderer): def apply_message(self, state, issue, tags, envelope, message, message_id, message_date, accumulator=None): - import uuid - rnd = str(uuid.uuid4()) - r = div(_id='m_' + message_id + '_' + rnd) + r = div(_id='m_' + message_id) s = dd() s.add(dt('Date')) @@ -145,11 +145,26 @@ class Renderer(BaseRenderer): s.add(dd(v)) r.add(s) - s = div(message.get_payload()) - r.add(s) + self.add(r) - return r - + #return r + + + def apply_message_part(self, state, issue, tags, envelope, message, message_date, message_content, accumulator=None): + if message_content['filename'] != None: + s = 'data:{}/{};base64,{}'.format( + message_content['type'][0], + message_content['type'][1], + message.get_payload(), + ) + v = os.path.basename(message_content['filename']) + r = a(v, href=s) + + s = 'd_m_{}_{}'.format( + message_content['id'], + message_content['idx'], + ) + return div(r, _id=s) # def apply_state_post(self, state, w=sys.stdout): # r = div(_id='state_' + state) diff --git a/piknik/wrap.py b/piknik/wrap.py @@ -17,12 +17,13 @@ class Wrapper: self.envelope_state = -1 # -1 not in envelope, 0 in outer envelope, 1 inner envelope, not (yet) valid, 2 envelope valid (with signature) self.envelope = None self.dump_dir = dump_dir - + self.msg_idx = 0 def process_envelope(self, msg, env_header): self.envelope = MessageEnvelope(msg) self.envelope_state = 0 + self.msg_idx = 0 return self.envelope @@ -30,7 +31,6 @@ class Wrapper: if msg.get('X-Piknik-Msg-Id') == None: self.add(self.envelope, message_id, msg) return (self.envelope, msg,) - #raise NotImplementedError() def add(self, envelope, message_id, message): @@ -64,7 +64,9 @@ class Wrapper: 'filename': filename, 'size': sz, 'contents': v, + 'idx': self.msg_idx, } + self.msg_idx += 1 logg.info('buffered content {}'.format(o)) self.content_buffer.append(o) diff --git a/tests/test_render.py b/tests/test_render.py @@ -64,8 +64,6 @@ class TestRenderer(Renderer): return r - - class TestRendererComposite(TestRenderer): def __init__(self, basket, accumulator=None): @@ -128,5 +126,19 @@ class TestMsg(unittest.TestCase): self.assertEqual(len(renderer.m), 1) + def test_attachment(self): + renderer = TestRendererComposite(self.b, accumulator=self.accumulate) + issue_one = Issue('foo') + self.b.add(issue_one) + + issue_two = Issue('bar') + v = self.b.add(issue_two) + + m = self.b.msg(v, 'f:tests/one.png') + + renderer.apply() + self.assertEqual(len(renderer.m), 1) + + if __name__ == '__main__': unittest.main()