""" 用户角色表单验证模块 ============================================================= 提供用户角色相关的表单验证功能,包括: - 用户角色分配表单验证 """ from wtforms import IntegerField from wtforms.fields.choices import SelectMultipleField from wtforms.validators import DataRequired, NumberRange, Optional from application.forms.base_form import BaseForm # ============================================================ # 用户角色表单验证 # ============================================================ class UserRoleForm(BaseForm): """ 用户角色表单验证类 用于用户分配角色权限时的数据验证。 Attributes: userId: 用户ID(必填,必须大于0) roleIds: 角色ID列表(可选,多个角色ID) """ # 用户ID userId = IntegerField( label='用户ID', validators=[ DataRequired(message='用户ID不能为空'), NumberRange(min=1, message='用户ID必须大于0') ], description='要分配角色的用户ID' ) # 角色ID列表 roleIds = SelectMultipleField( label='角色ID列表', validators=[ Optional(), ], coerce=int, choices=[], validate_choice=False, description='分配的角色ID列表' )