From 90972f1afac20bbcec4b1d5d366f8d30a2cb4478 Mon Sep 17 00:00:00 2001 From: smueller Date: Tue, 7 Jul 2026 16:04:00 +0200 Subject: [PATCH] Refactor newsletter generation to improve contact information handling - Added a new function to generate a plain text contact line based on the provided email. - Updated the plain text and HTML newsletter templates to include the contact information dynamically. - Removed direct contact email handling from the footer function to streamline the code and enhance readability. --- app/services/newsletter.py | 44 ++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/app/services/newsletter.py b/app/services/newsletter.py index c31ab2a..d14fd37 100644 --- a/app/services/newsletter.py +++ b/app/services/newsletter.py @@ -231,6 +231,7 @@ def create_plain_text( "", ] ) + lines.extend(_plain_contact_line(contact_email)) highlight_articles = _match_highlights(new_articles + edited_articles, highlights) if highlight_articles: @@ -251,7 +252,7 @@ def create_plain_text( ] ) lines.extend(_plain_editor_tip(editor_tip)) - lines.append(_plain_footer(new_articles, edited_articles, contact_email)) + lines.append(_plain_footer(new_articles, edited_articles)) return "\n".join(lines).strip() if show_new: @@ -268,10 +269,19 @@ def create_plain_text( ) lines.append("") lines.extend(_plain_editor_tip(editor_tip)) - lines.append(_plain_footer(new_articles, edited_articles, contact_email)) + lines.append(_plain_footer(new_articles, edited_articles)) return "\n".join(lines).strip() +def _plain_contact_line(contact_email: str) -> list[str]: + if contact_email.strip(): + return [ + f"Fragen oder ein Themenwunsch? E-Mail an das Wiki-Team: {contact_email.strip()}", + "", + ] + return ["Fragen oder ein Themenwunsch? Meldet euch gern beim Wiki-Team.", ""] + + def _plain_editor_tip(editor_tip: str) -> list[str]: text = (editor_tip or "").strip() if not text: @@ -345,6 +355,12 @@ def create_html( else: contact_html = "Fragen oder ein Themenwunsch? Meldet euch gern beim Wiki-Team." + contact_section = ( + f'' + f'

{contact_html}

' + f"" + ) + return f""" @@ -407,6 +423,7 @@ def create_html( + {contact_section} {category_hint} {highlights_section} {body} @@ -422,7 +439,6 @@ def create_html( @@ -739,17 +755,18 @@ def create_outlook_html( editor_tip_row = _outlook_editor_tip(editor_tip) if contact_email.strip(): - contact_inner = ( + contact_block = ( + f'

' f'{_outlook_font("Fragen oder ein Themenwunsch? Meldet euch gern beim Wiki-Team: ", size="1")}' f'{_outlook_link(contact_email.strip(), f"mailto:{contact_email.strip()}", color=OUTLOOK_ORANGE, bold=False)}' + f"

" ) - contact_row = f""" - -""" else: - contact_row = "" + contact_block = ( + f'

' + f'{_outlook_font("Fragen oder ein Themenwunsch? Meldet euch gern beim Wiki-Team.", size="1")}' + f"

" + ) return f""" @@ -799,6 +816,7 @@ def create_outlook_html(
- {contact_html}

Viele Grüße
Euer Thomas-Krenn-Wiki Team
- {contact_inner} -

{_outlook_font("Servus,")}

{_outlook_font(f"hier ist deine Übersicht mit den neuesten Beiträgen aus dem Thomas-Krenn-Wiki vom {period_start} bis {period_end}.")}

+ {contact_block} {category_block} {highlights_rows} @@ -810,7 +828,6 @@ def create_outlook_html( {_outlook_cta(WIKI_HOME_URL, "Zum Thomas-Krenn-Wiki →")} - {contact_row}
{_outlook_font(f"Automatisch erstellter interner Newsletter · Nur für den Gebrauch bei {ORG_NAME}", color=OUTLOOK_MUTED, size="1")} @@ -961,12 +978,8 @@ def _plain_item(idx: int, item: dict[str, Any], display: DisplayOptions) -> list def _plain_footer( new_articles: list[dict[str, Any]], edited_articles: list[dict[str, Any]], - contact_email: str = "", ) -> str: total = len(new_articles) + len(edited_articles) - contact_lines = [] - if contact_email.strip(): - contact_lines = [f"Fragen oder ein Themenwunsch? E-Mail an das Wiki-Team: {contact_email.strip()}", ""] return "\n".join( [ SUBLINE, @@ -978,7 +991,6 @@ def _plain_footer( "", f"Wiki: {WIKI_HOME_URL}", "", - *contact_lines, SUBLINE, "Dieser Newsletter wurde automatisch erstellt und ist nur für den internen", f"Gebrauch bei {ORG_NAME} bestimmt.",