Accept exported option text in tryout snapshots

This commit is contained in:
dwindown
2026-04-03 22:27:51 +07:00
parent d7f110d8d0
commit c6f958879d

View File

@@ -72,7 +72,11 @@ def _extract_tryout_previews(payload: dict[str, Any]) -> list[tuple[str, dict[st
def _normalize_question(question: dict[str, Any]) -> dict[str, Any]: def _normalize_question(question: dict[str, Any]) -> dict[str, Any]:
raw_options = question.get("options") or [] raw_options = question.get("options") or []
has_option_labels = any(bool((opt or {}).get("label")) for opt in raw_options if isinstance(opt, dict)) has_option_labels = any(
bool(((opt or {}).get("text") or (opt or {}).get("label") or "").strip())
for opt in raw_options
if isinstance(opt, dict)
)
normalized = { normalized = {
"source_question_id": str(question.get("id", "")), "source_question_id": str(question.get("id", "")),
"title": str(question.get("title") or "").strip(), "title": str(question.get("title") or "").strip(),
@@ -158,7 +162,7 @@ async def preview_tryout_json_import(payload: dict[str, Any], website_id: int, d
warnings: list[str] = [] warnings: list[str] = []
if missing_option_labels: if missing_option_labels:
warnings.append( warnings.append(
f"{missing_option_labels} question(s) have no visible option labels in the export; import will store raw reference data only." f"{missing_option_labels} question(s) have no exported option text in the JSON; import will store raw reference data only."
) )
summary = QuestionDiffSummary( summary = QuestionDiffSummary(