MCPcopy Create free account
hub / github.com/ZyphrZero/z.ai2api_python / build_form_updates

Function build_form_updates

app/admin/config_manager.py:557–590  ·  view source on GitHub ↗
(form_data: Mapping[str, Any])

Source from the content-addressed store, hash-verified

555
556
557def build_form_updates(form_data: Mapping[str, Any]) -> dict[str, object]:
558 updates: dict[str, object] = {}
559
560 for key in MANAGED_ENV_KEYS:
561 field = CONFIG_FIELD_SPECS[key]
562
563 if field.value_type == "bool":
564 updates[key] = key in form_data
565 continue
566
567 raw_value = str(form_data.get(key, "") or "").strip()
568 if field.required and raw_value == "":
569 raise ValueError(f"{field.label} 不能为空。")
570
571 if field.value_type == "int":
572 try:
573 parsed = int(raw_value)
574 except ValueError as exc:
575 raise ValueError(f"{field.label} 必须是整数。") from exc
576
577 if field.min_value is not None and parsed < field.min_value:
578 raise ValueError(
579 f"{field.label} 不能小于 {field.min_value}。"
580 )
581 if field.max_value is not None and parsed > field.max_value:
582 raise ValueError(
583 f"{field.label} 不能大于 {field.max_value}。"
584 )
585 updates[key] = parsed
586 continue
587
588 updates[key] = raw_value
589
590 return updates
591
592
593async def _apply_env_change(

Callers 1

save_form_configFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected