(
data: dict,
key: str,
default: int,
label: str,
min_value: int = 0,
max_value: int | None = None,
)
| 108 | |
| 109 | |
| 110 | def parse_int_field( |
| 111 | data: dict, |
| 112 | key: str, |
| 113 | default: int, |
| 114 | label: str, |
| 115 | min_value: int = 0, |
| 116 | max_value: int | None = None, |
| 117 | ) -> int: |
| 118 | raw_value = get_form_value(data, key, str(default)).strip() |
| 119 | try: |
| 120 | value = int(raw_value) |
| 121 | except ValueError: |
| 122 | raise ValueError(f"{label} 必须是整数") |
| 123 | if value < min_value: |
| 124 | raise ValueError(f"{label} 不能小于 {min_value}") |
| 125 | if max_value is not None and value > max_value: |
| 126 | raise ValueError(f"{label} 不能大于 {max_value}") |
| 127 | return value |
| 128 | |
| 129 | |
| 130 | def parse_allowed_file_types(value: str) -> list[str]: |
no test coverage detected