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

Function build_config_page_data

app/admin/config_manager.py:473–554  ·  view source on GitHub ↗
(
    *,
    settings_obj: Any = settings,
    env_path: str | Path = ENV_PATH,
    env_example_path: str | Path = ENV_EXAMPLE_PATH,
)

Source from the content-addressed store, hash-verified

471
472
473def build_config_page_data(
474 *,
475 settings_obj: Any = settings,
476 env_path: str | Path = ENV_PATH,
477 env_example_path: str | Path = ENV_EXAMPLE_PATH,
478) -> dict[str, Any]:
479 env_file = Path(env_path)
480 env_content = read_env_content(env_file)
481 env_values = dotenv_values(env_file) if env_file.exists() else {}
482 sections: list[dict[str, Any]] = []
483 total_fields = 0
484 overridden_fields = 0
485 sensitive_fields = 0
486 restart_required_fields = 0
487
488 for section in CONFIG_SECTIONS:
489 rendered_fields: list[dict[str, Any]] = []
490 for field in section.fields:
491 total_fields += 1
492 if field.sensitive:
493 sensitive_fields += 1
494 if field.restart_required:
495 restart_required_fields += 1
496
497 is_overridden = field.key in env_values
498 if is_overridden:
499 overridden_fields += 1
500
501 value = getattr(settings_obj, field.key, field.default_value)
502 if value is None:
503 value = ""
504
505 rendered_fields.append(
506 {
507 "key": field.key,
508 "label": field.label,
509 "description": field.description,
510 "value_type": field.value_type,
511 "value": value,
512 "input_type": field.input_type,
513 "placeholder": field.placeholder,
514 "required": field.required,
515 "wide": field.wide,
516 "sensitive": field.sensitive,
517 "restart_required": field.restart_required,
518 "min_value": field.min_value,
519 "max_value": field.max_value,
520 "source_label": ".env" if is_overridden else "默认值",
521 "source_badge_class": (
522 "bg-emerald-50 text-emerald-700 ring-emerald-200"
523 if is_overridden
524 else "bg-slate-100 text-slate-600 ring-slate-200"
525 ),
526 }
527 )
528
529 sections.append(
530 {

Calls 1

read_env_contentFunction · 0.85