23 lines
751 B
Python
23 lines
751 B
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# @Time : 2025/3/15 21:14
|
|
# @Author : AngesZhu
|
|
# @File : if_must_rules.py
|
|
# @Desc :
|
|
from typing import Any
|
|
from utils.validation_error_utils import handle_validation_errors, RequiredFieldError
|
|
|
|
|
|
def validate_required(value: Any, field: str) -> bool:
|
|
"""
|
|
校验字段是否为必填内容
|
|
:param value: 字段值
|
|
:param field: 字段名称
|
|
:return: 是否通过校验
|
|
:raises RequiredFieldError: 如果字段为空且为必填
|
|
"""
|
|
with handle_validation_errors(field, {"value": value}):
|
|
if value is None or (isinstance(value, str) and not value.strip()):
|
|
raise RequiredFieldError(f"字段 '{field}' 是必填内容", field)
|
|
return True
|