여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""업종·템플릿 정의."""
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from common.enums import PlaceCategory
|
|
|
|
CATALOG_PATH = Path(__file__).resolve().parents[2] / "shared" / "src" / "data" / "templates.json"
|
|
|
|
_CATALOG = json.loads(CATALOG_PATH.read_text(encoding="utf-8"))
|
|
|
|
TEMPLATES: dict = _CATALOG["templates"]
|
|
INDUSTRIES: dict = _CATALOG["industries"]
|
|
|
|
_INDUSTRY_BY_CATEGORY = {
|
|
PlaceCategory.LODGING.value: "stay",
|
|
PlaceCategory.CAFE.value: "cafe",
|
|
PlaceCategory.RESTAURANT.value: "restaurant",
|
|
PlaceCategory.CLINIC.value: "clinic",
|
|
}
|
|
|
|
|
|
class UnknownTemplate(ValueError):
|
|
pass
|
|
|
|
|
|
def industry_of(category: int) -> dict:
|
|
key = _INDUSTRY_BY_CATEGORY.get(category)
|
|
if key is None:
|
|
raise ValueError(f"업종 코드에 맞는 정의가 없다: {category}")
|
|
return INDUSTRIES[key]
|
|
|
|
|
|
def is_allowed(category: int, template_id: str) -> bool:
|
|
return template_id in industry_of(category)["templates"]
|
|
|
|
|
|
def resolve_template_id(category: int, stored: str | None) -> str:
|
|
template_id = (stored or "").strip() or industry_of(category)["defaultTemplate"]
|
|
if not is_allowed(category, template_id):
|
|
raise UnknownTemplate(f"업종 {category}에서 쓸 수 없는 템플릿: {template_id}")
|
|
return template_id
|