From 0498331a15cfa8de7f2c3f4a761695ae21ae6245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 7 Aug 2023 12:49:54 +0200 Subject: Introduce dl function. --- mu4web/components.py | 10 ++++++++++ mu4web/main.py | 26 +++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/mu4web/components.py b/mu4web/components.py index e9701de..07ab400 100644 --- a/mu4web/components.py +++ b/mu4web/components.py @@ -9,6 +9,16 @@ from .html_render import HTML from typing import cast, Optional from urllib.parse import urlencode from email.message import EmailMessage +from typing import Iterable + + +def dl(entries: Iterable[tuple[HTML, HTML]]) -> HTML: + """Build a description list.""" + items = [] + for k, v in entries: + items += [('dt', k), + ('dd', v)] + return ('dl', items) def format_email(addr: Address) -> list[HTML]: diff --git a/mu4web/main.py b/mu4web/main.py index e782233..bfade9d 100644 --- a/mu4web/main.py +++ b/mu4web/main.py @@ -35,16 +35,15 @@ from flask import ( get_flashed_messages ) from .components import ( + attachement_tree, + dl, + flashed_messages, header_format, -) -from .components import ( include_stylesheet, - flashed_messages, + login_page, login_prompt, - user_info, search_field, - attachement_tree, - login_page, + user_info, ) from .util import MutableString @@ -447,20 +446,17 @@ def response_for(id: str, mail: EmailMessage) -> str: for (key, value) in mail.items(): headers[key.lower()] = value - head = [] + header_entries = [] for h in app.config['MESSAGE_HEADERS']: if x := headers.get(h.lower()): - head += [('dt', h.title()), - ('dd', header_format(h.lower(), x))] + header_entries.append((h.title(), + header_format(h.lower(), x))) - all_heads = [] - for key, value in mail.items(): - all_heads += [('dt', key.title()), - ('dd', value)] + header_list = dl(header_entries) full_headers = ('details', ('summary', 'Alla mailhuvuden'), - ('dl', *all_heads)) + dl((key.title(), value) for (key, value) in mail.items())) # Setup title if t := headers.get('subject'): @@ -496,7 +492,7 @@ def response_for(id: str, mail: EmailMessage) -> str: # Setup attachements tree, idx = attachement_tree(id, mail) - main_body: list[HTML] = [('dl', *head), + main_body: list[HTML] = [header_list, full_headers, ('hr',), ('main', body), -- cgit v1.2.3