090e508bf3
Apply project_db migration 019 to enable vertical cell merges. Other cell editing remains available before migration.
158 lines
9.0 KiB
Python
158 lines
9.0 KiB
Python
"""연간 목표(goals.html)·주간 회의록(goal_meeting.html)을 테스트용 HTML 로 렌더한다(erp_base.html 은 최소 스텁, 가상의 데이터).
|
|
|
|
python tests/js/render_goals.py # → tests/js/.out/goals_admin.html · goals_ro.html · meeting_admin.html · meeting_err.html · meeting_ro.html
|
|
|
|
칸 배치는 실제 라우터 도우미(_goal_area_layout·_goal_label_spans)로 만든다. DB·실적 모듈은 쓰지 않는다.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import copy
|
|
import io
|
|
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.project import store # noqa: E402
|
|
from app.modules.project.router import _goal_area_layout, _goal_label_spans # noqa: E402
|
|
|
|
BASE_STUB = ("{% block head_extra %}{% endblock %}<body>{% block topbar_after_logout %}{% endblock %}{% block topbar_actions %}{% endblock %}"
|
|
"<main class='erp-page'>{% block content %}{% endblock %}</main></body>")
|
|
ME = "me@test.local"
|
|
|
|
|
|
def board() -> dict:
|
|
rows_a = [{"id": 10, "label": "신제품", "cells": {0: "연간 계획", 1: "original"}, "merges": {}},
|
|
{"id": 11, "label": "리뉴얼", "cells": {}, "merges": {}}]
|
|
rows_b = [{"id": 20, "label": "쿠팡", "cells": {2: "행사"}, "merges": {}},
|
|
{"id": 21, "label": "", "cells": {}, "merges": {}}]
|
|
areas = [{"id": 1, "name": "상품", "color": "#fde2e4", "rows": rows_a},
|
|
{"id": 2, "name": "유통", "color": "", "rows": rows_b}]
|
|
for a in areas:
|
|
_goal_area_layout(a["rows"], 10)
|
|
_goal_label_spans(a["rows"])
|
|
return {
|
|
"year": 2026, "sales_unit": "만원", "halves": True, "quarters": True,
|
|
"metrics": {"sales": {"target_label": {1: "100", 2: "100"}, "actual_label": {1: "50"}},
|
|
"roas": {"target_label": {}, "actual_label": {}}},
|
|
"areas": areas,
|
|
}
|
|
|
|
|
|
def goals_ctx(admin: bool) -> dict:
|
|
return {
|
|
"user": {"email": ME, "is_super_admin": False}, "is_admin": admin, "nav_projects": [], "goal_years": [2026],
|
|
"goal_year_active": 2026, "my_open_total": 0, "mention_unread": 0, "color_palette": ["#4573d2"],
|
|
"project_icons": ["folder"], "goals_enabled": True, "goal_year": 2026, "board": board(),
|
|
"months": list(range(1, 13)),
|
|
"quarters": [(q, list(range(q * 3 - 2, q * 3 + 1)), store.GOAL_QUARTER_COL[q], f"{q}분기") for q in (1, 2, 3, 4)],
|
|
"this_month": 10, "goal_area_colors": list(store.GOAL_AREA_COLORS),
|
|
}
|
|
|
|
|
|
def meeting_view(err: bool) -> dict:
|
|
"""회의록 2026-09-28 주 — 유통 쿠팡(쇼핑몰 연결, 이번주 실적 100, 정량 목표 100), 상품1(직접 입력 결과)."""
|
|
prev_cou = {"id": 901, "week_start": "2026-09-21", "content": "지난주 행사", "target_amount": 100, "result_amount": None,
|
|
"status": "", "marketplace_code": "coupang", "period": "9/21~9/27", "not_started": False,
|
|
"market_off": False, "auto_error": err, "auto_result": None if err else 80,
|
|
"result": None if err else 80, "market_name": "쿠팡"}
|
|
prev_p1 = {"id": 902, "week_start": "2026-09-21", "content": "샘플", "target_amount": 200, "result_amount": 100,
|
|
"status": "partial", "marketplace_code": "", "period": "9/21~9/27", "not_started": False,
|
|
"market_off": False, "auto_error": False, "auto_result": None, "result": 100, "market_name": ""}
|
|
it_cou = {"id": 1, "section": "유통", "section_color": "", "label": "쿠팡", "content": "original",
|
|
"target_amount": 100, "marketplace_code": "coupang", "market_name": "쿠팡", "market_off": False,
|
|
"market_unknown": err, "week_auto": None if err else 100, "week_error": err,
|
|
"prev": prev_cou, "rate": None if err else 80.0}
|
|
it_p1 = {"id": 2, "section": "상품", "section_color": "#fde2e4", "label": "상품1", "content": "",
|
|
"target_amount": None, "marketplace_code": "", "market_name": "", "market_off": False,
|
|
"market_unknown": False, "week_auto": None, "week_error": False, "prev": prev_p1, "rate": 50.0}
|
|
it_new = {"id": 3, "section": "상품", "section_color": "#fde2e4", "label": "새 줄", "content": "",
|
|
"target_amount": None, "marketplace_code": "", "market_name": "", "market_off": False,
|
|
"market_unknown": False, "week_auto": None, "week_error": False, "prev": None, "rate": None}
|
|
meeting = {"week_start": "2026-09-28", "week_target": 1000, "attendees": "", "notes": "메모 원본", "cell_merges": True,
|
|
"items": [it_p1, it_new, it_cou],
|
|
"sections": [{"name": "상품", "color": "#fde2e4", "rows": [it_p1, it_new]},
|
|
{"name": "유통", "color": "", "rows": [it_cou]}]}
|
|
head = {"sales_unit": "원", "sales_target": 10000.0, "roas_target": None, "month_target_won": 10000,
|
|
"mtd": None if err else 0, "mtd_end": "2026-09-27", "weeks_left": 1,
|
|
"need_per_week": None if err else 10000, "prev_target": 500, "prev_exists": True,
|
|
"prev_result": None if err else 0, "week_result": None if err else 0,
|
|
"perf": True, "perf_state": "error" if err else "ok",
|
|
"unknown": ["mtd", "prev_result", "week_result"] if err else [],
|
|
"fresh_oldest": "" if err else "10/01 14:20",
|
|
"fresh_tip": "" if err else "매출 자료(실적 모듈) 쇼핑몰별 마지막 갱신 성공 — 쿠팡 10/01 14:20"}
|
|
return {"meeting": meeting, "head": head, "markets": [] if err else [{"code": "coupang", "name": "쿠팡"}]}
|
|
|
|
|
|
def meeting_ctx(admin: bool, err: bool, can_sync: bool = True) -> dict:
|
|
view = meeting_view(err)
|
|
return {
|
|
"user": {"email": ME, "is_super_admin": False}, "is_admin": admin, "nav_projects": [], "goal_years": [2026],
|
|
"goal_year_active": 2026, "my_open_total": 0, "mention_unread": 0, "color_palette": ["#4573d2"],
|
|
"project_icons": ["folder"], "goal_year": 2026, "goal_month": 9, "meetings_enabled": True,
|
|
"weeks": [{"start": "2026-09-28", "end": "2026-10-04", "n": 4, "label": "9/28~10/4", "has": True, "now": False,
|
|
"days": []}],
|
|
"cal_weeks": [], "week": "2026-09-28", "week_n": 4, "week_end": "2026-10-04",
|
|
"prev_week": "2026-09-21", "prev_week_end": "2026-09-27", "sync_from": "2026-09-21", "sync_to": "2026-10-01",
|
|
"can_sync": can_sync, "meeting_status": store.MEETING_STATUS, "meet_members": [], "month_plan": None,
|
|
"attendee_list": [], **copy.deepcopy(view),
|
|
}
|
|
|
|
|
|
def meeting_layout_ctx(admin: bool) -> dict:
|
|
ctx = meeting_ctx(admin, False, can_sync=False)
|
|
meeting = ctx["meeting"]
|
|
product = meeting["sections"][0]["rows"][0]
|
|
product["content"] = "첫 번째 줄\n두 번째 줄\n세 번째 줄"
|
|
product["prev"]["content"] = "첫 번째 줄\n두 번째 줄"
|
|
inactive = copy.deepcopy(meeting["sections"][1]["rows"][0])
|
|
inactive.update(id=4, label="네이버", section="마케팅", content="한 줄", marketplace_code="naver",
|
|
market_name="네이버 스마트스토어", market_off=True, week_auto=None)
|
|
inactive["prev"].update(id=904, content="한 줄", auto_result=None, market_off=True,
|
|
marketplace_code="naver", market_name="네이버 스마트스토어")
|
|
meeting["items"].append(inactive)
|
|
meeting["sections"].append({"name": "마케팅", "color": "", "rows": [inactive]})
|
|
return ctx
|
|
|
|
|
|
def meeting_merged_ctx() -> dict:
|
|
ctx = meeting_ctx(True, False, can_sync=False)
|
|
a, b = ctx["meeting"]["sections"][0]["rows"]
|
|
a.update(content_span=2, content_hidden=False,
|
|
content_html=store.goal_text_html(store.GOAL_RICH_PREFIX + '[{"text":"병합한 계획\\n두 번째 줄","bold":true,"size":24}]'))
|
|
b["content_hidden"] = True
|
|
return ctx
|
|
|
|
|
|
def main() -> None:
|
|
env = jinja2.Environment(loader=jinja2.ChoiceLoader([
|
|
jinja2.DictLoader({"erp_base.html": BASE_STUB}),
|
|
jinja2.FileSystemLoader(os.path.join(ROOT, "app", "modules", "project", "templates")),
|
|
]))
|
|
env.globals["pj_kr_holidays"] = {}
|
|
os.makedirs(OUT_DIR, exist_ok=True)
|
|
pages = {
|
|
"goals_admin.html": ("project/goals.html", goals_ctx(True)),
|
|
"goals_ro.html": ("project/goals.html", goals_ctx(False)),
|
|
"meeting_admin.html": ("project/goal_meeting.html", meeting_ctx(True, False)),
|
|
"meeting_err.html": ("project/goal_meeting.html", meeting_ctx(True, True)),
|
|
"meeting_ro.html": ("project/goal_meeting.html", meeting_ctx(False, False, can_sync=False)),
|
|
"meeting_layout_admin.html": ("project/goal_meeting.html", meeting_layout_ctx(True)),
|
|
"meeting_layout_ro.html": ("project/goal_meeting.html", meeting_layout_ctx(False)),
|
|
"meeting_merged.html": ("project/goal_meeting.html", meeting_merged_ctx()),
|
|
}
|
|
for name, (tpl, ctx) in pages.items():
|
|
html = env.get_template(tpl).render(**ctx)
|
|
path = os.path.join(OUT_DIR, name)
|
|
io.open(path, "w", encoding="utf-8", newline="\n").write(html)
|
|
print("rendered:", path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|