"""안내문 발송 화면(index.html)을 진짜 ERP 셸로 렌더 — 브라우저 테스트용(2026-10-27). python tests/js/render_outreach.py # → tests/js/.out/outreach.html, outreach_dm.html, outreach_settings.html 화면 데이터는 실제 router._view 로 만든다(저장소 없이 줄만 가짜). """ from __future__ import annotations import os import sys import jinja2 ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, ROOT) OUT_DIR = os.path.join(ROOT, "tests", "js", ".out") from app.modules.outreach import store # noqa: E402 from app.modules.outreach.router import _view # noqa: E402 def main() -> None: os.makedirs(OUT_DIR, exist_ok=True) env = jinja2.Environment(loader=jinja2.FileSystemLoader([ os.path.join(ROOT, "app", "templates"), os.path.join(ROOT, "app", "modules", "outreach", "templates")]), autoescape=True) t = {**store.normalize_template(None), "updated_by": "", "updated_at": "", "is_default": True} base = {"id": 0, "memo": "", "status": "대기", "sent_at": "", "sent_by": "", "sent_via": "", "last_error": ""} raw = [ {**base, "id": 1, "kind": "email", "handle": "kim@miras.co.kr", "address": "kim@miras.co.kr", "name": "김철수"}, {**base, "id": 2, "kind": "instagram", "handle": "mira.kitchen", "address": "@mira.kitchen", "name": "미라"}, {**base, "id": 3, "kind": "email", "handle": "noname@miras.co.kr", "address": "noname@miras.co.kr", "name": ""}, {**base, "id": 4, "kind": "email", "handle": "done@miras.co.kr", "address": "done@miras.co.kr", "name": "보냄씨", "status": "보냄", "sent_at": "2026-10-27T10:00:00+09:00", "sent_via": "gmail"}, ] ctx = {"user": {"email": "me@miras.co.kr", "name": "나", "picture": ""}, "is_admin": False, "nav_items": [], "page_title": "안내문 발송", "page_subtitle": "", "template": t, "body_text": store.html_to_text(t["body"]), "needs_name": store.needs_name(t), "images": [], "rows": [_view(r, t) for r in raw], "active_tab": "list", "logs": [], "gmail": {"available": True, "connected": True, "email": "me@miras.co.kr"}, "msg": ""} with open(os.path.join(OUT_DIR, "outreach.html"), "w", encoding="utf-8") as f: f.write(env.get_template("outreach/index.html").render(**ctx)) # DM 수동 보내기 탭(2026-10-30) with open(os.path.join(OUT_DIR, "outreach_dm.html"), "w", encoding="utf-8") as f: f.write(env.get_template("outreach/dm.html").render(**{**ctx, "active_tab": "dm", "dm_template": store.dm_text(t, store.NAME_TAG)})) # 설정 화면 — 저장해 둔 서식 본문(HTML)·DM 문구로 saved = store.normalize_template({ "subject": "{이름}님께 제안", "fmt": "html", "dm_body": "안녕하세요 {이름}님, DM 입니다", "body": '

안녕하세요, {이름}님.


큰 파란 글씨

' '

가운데 굵게

'}) sctx = {**ctx, "page_title": "설정", "template": {**saved, "updated_by": "me@miras.co.kr", "updated_at": "2026-10-27T10:00:00", "is_default": False}, "default": store.normalize_template(None), "max_images": 10, "dm_max": store.DM_MAX} with open(os.path.join(OUT_DIR, "outreach_settings.html"), "w", encoding="utf-8") as f: f.write(env.get_template("outreach/settings.html").render(**sctx)) if __name__ == "__main__": main()