feat: admin 주제 편집 — JSON 직접 편집 + 검증

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
th-kim0823
2026-04-27 20:15:25 +09:00
parent f9cc5be2f0
commit c3bbb4e959

36
app.py
View File

@@ -710,9 +710,41 @@ def render_admin():
update_topics(new_cats)
st.success("저장됨. 큰 화면 다음 갱신 시 반영.")
st.rerun()
# JSON 모드는 T14에서 추가 (else branch는 placeholder)
else: # JSON 직접 편집
current_json = json.dumps(
{"categories": cur_topics}, ensure_ascii=False, indent=2
)
edited = st.text_area(
"topics JSON",
value=current_json,
height=400,
key="topics_json_editor",
)
jc1, jc2 = st.columns(2)
with jc1:
if st.button("JSON 검증"):
try:
parsed = json.loads(edited)
cats = parsed.get("categories", [])
if not isinstance(cats, list):
st.error("'categories'는 list 여야 합니다.")
else:
st.info("Task 14에서 JSON 직접 편집 모드 추가됨.")
st.success(f"OK — {len(cats)}개 카테고리")
except json.JSONDecodeError as e:
st.error(f"JSON 파싱 실패: {e}")
with jc2:
if st.button("JSON 저장", type="primary"):
try:
parsed = json.loads(edited)
cats = parsed.get("categories", [])
if not isinstance(cats, list):
st.error("'categories'는 list 여야 합니다.")
else:
update_topics(cats)
st.success("저장됨.")
st.rerun()
except json.JSONDecodeError as e:
st.error(f"저장 실패 — JSON 파싱 에러: {e}")
st.divider()